Loads of changes.

This commit is contained in:
Olof Larsson 2012-09-21 00:50:43 +02:00
parent 3c9a0a4640
commit 682e6513a4
98 changed files with 3149 additions and 107 deletions

View File

@ -2,3 +2,55 @@ name: mcore4
version: 1.0.0
main: com.massivecraft.mcore4.MCore
load: startup
permissions:
# -------------------------------------------- #
# THE REAL NODES
# -------------------------------------------- #
mcore.usys: {description: manage the universe system, default: op}
mcore.usys.multiverse: {description: manage multiverses, default: op}
mcore.usys.multiverse.list: {description: list multiverses, default: op}
mcore.usys.multiverse.show: {description: show multiverse, default: op}
mcore.usys.multiverse.new: {description: create new multiverse, default: op}
mcore.usys.multiverse.del: {description: delete multiverse, default: op}
mcore.usys.universe: {description: manage universes, default: op}
mcore.usys.universe.new: {description: create new universe in multiverse, default: op}
mcore.usys.universe.del: {description: delete universe in multiverse, default: op}
mcore.usys.universe.clear: {description: clear universe in multiverse, default: op}
mcore.usys.world: {description: set a worlds universe in a multiverse, default: op}
mcore.usys.aspect: {description: manage aspects, default: op}
mcore.usys.aspect.list: {description: list aspects, default: op}
mcore.usys.aspect.show: {description: show aspect, default: op}
mcore.usys.aspect.use: {description: set multiverse for aspect, default: op}
# -------------------------------------------- #
# STAR NOTATION
# -------------------------------------------- #
mcore.usys.multiverse.*:
default: op
children:
mcore.usys.multiverse.list: true
mcore.usys.multiverse.show: true
mcore.usys.multiverse.new: true
mcore.usys.multiverse.del: true
mcore.usys.universe.*:
default: op
children:
mcore.usys.universe.new: true
mcore.usys.universe.del: true
mcore.usys.universe.clear: true
mcore.usys.world.*:
default: op
children:
mcore.usys.world: true
mcore.usys.aspect.*:
default: op
children:
mcore.usys.aspect.list: true
mcore.usys.aspect.show: true
mcore.usys.aspect.use: true
mcore.usys.*:
default: op
children:
mcore.usys.multiverse.*: true
mcore.usys.universe.*: true
mcore.usys.world.*: true
mcore.usys.aspect.*: true

View File

@ -1,17 +1,27 @@
package com.massivecraft.mcore4;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import com.massivecraft.mcore4.event.MCoreAfterPlayerRespawnEvent;
import com.massivecraft.mcore4.event.MCoreAfterPlayerTeleportEvent;
import com.massivecraft.mcore4.event.MCorePlayerLeaveEvent;
import com.massivecraft.mcore4.persist.IClassManager;
import com.massivecraft.mcore4.persist.Persist;
import com.massivecraft.mcore4.store.Coll;
import com.massivecraft.mcore4.store.ModificationState;
import com.massivecraft.mcore4.store.PlayerColl;
import com.massivecraft.mcore4.util.MUtil;
public class InternalListener implements Listener
{
@ -23,9 +33,8 @@ public class InternalListener implements Listener
Bukkit.getServer().getPluginManager().registerEvents(this, this.p);
}
// TODO: Does this even trigger? If not we have an issue.
@EventHandler(priority = EventPriority.LOW)
public void onPlayerPreLogin(PlayerLoginEvent event)
public void onPlayerLogin(PlayerLoginEvent event)
{
String id = event.getPlayer().getName();
@ -40,21 +49,100 @@ public class InternalListener implements Listener
}
}
/**
* We sync the player in all player collections at PlayerLoginEvent LOW. LOWEST is left for anti flood and bans.
* The syncs are not to heavy to do and other events can rest assure the data is up to date.
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void syncPlayerEntities(PlayerLoginEvent event)
// -------------------------------------------- //
// AFTER EVENTS
// -------------------------------------------- //
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void after(PlayerTeleportEvent event)
{
String playerName = event.getPlayer().getName();
Bukkit.getScheduler().scheduleSyncDelayedTask(p, new MCoreAfterPlayerTeleportEvent(event), 0);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void after(PlayerRespawnEvent event)
{
Bukkit.getScheduler().scheduleSyncDelayedTask(p, new MCoreAfterPlayerRespawnEvent(event, event.getPlayer().getLocation()), 0);
}
// -------------------------------------------- //
// EVENT TOOL: causedByKick
// -------------------------------------------- //
public static Map<String,String> kickedPlayerReasons = new HashMap<String,String>();
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void causedByKick(PlayerKickEvent event)
{
final String name = event.getPlayer().getName();
kickedPlayerReasons.put(name, event.getReason());
}
@EventHandler(priority = EventPriority.MONITOR)
public void causedByKick(PlayerQuitEvent event)
{
// We do the schedule in order for the set to be correct through out the whole MONITOR priority state.
final String name = event.getPlayer().getName();
Bukkit.getScheduler().scheduleSyncDelayedTask(MCore.p, new Runnable()
{
@Override
public void run()
{
kickedPlayerReasons.remove(name);
}
});
}
// -------------------------------------------- //
// STORE SYSTEM: SYNC IN AND SYNC OUT
// -------------------------------------------- //
// There are some forced syncs of players in all collections so developers can rest assure the data is up to date.
// PlayerLoginEvent LOW. LOWEST is left for anti flood and bans.
// PlayerKickEvent MONITOR.
// PlayerQuitEvent MONITOR.
// Why do we sync at both PlayerKickEvent and PlayerQuitEvent you may wonder?
// PlayerQuitEvent do not always fire, for example due to a spoutcraft bug
// and it also fires AFTER the player left the server. In kick cases we can sync
// directly before the player leaves the server. That is great.
public void syncAllForPlayer(Player player)
{
String playerName = player.getName();
for (Coll<?, ?> coll : Coll.instances)
{
if (!(coll instanceof PlayerColl)) continue;
PlayerColl<?> pcoll = (PlayerColl<?>)coll;
ModificationState mstate = pcoll.syncId(playerName);
p.log("syncPlayerEntities", coll.name(), playerName, mstate);
pcoll.syncId(playerName);
//ModificationState mstate = pcoll.syncId(playerName);
//p.log("syncAllForPlayer", coll.name(), playerName, pcoll.syncId(playerName), pcoll.syncId(playerName));
}
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void syncAllForPlayer(PlayerLoginEvent event)
{
//p.log("syncAllForPlayer PlayerLoginEvent LOW", event.getPlayer().getName());
this.syncAllForPlayer(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void syncAllForPlayer(PlayerKickEvent event)
{
//p.log("syncAllForPlayer PlayerKickEvent MONITOR", event.getPlayer().getName());
new MCorePlayerLeaveEvent(event.getPlayer(), true, event.getReason()).run();
this.syncAllForPlayer(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void syncAllForPlayer(PlayerQuitEvent event)
{
//p.log("syncAllForPlayer PlayerQuitEvent MONITOR", event.getPlayer().getName());
if (!MUtil.causedByKick(event))
{
new MCorePlayerLeaveEvent(event.getPlayer(), false, null).run();
}
this.syncAllForPlayer(event.getPlayer());
}
}

View File

@ -15,6 +15,9 @@ import com.massivecraft.mcore4.store.Coll;
import com.massivecraft.mcore4.store.Db;
import com.massivecraft.mcore4.store.MStore;
import com.massivecraft.mcore4.store.USelColl;
import com.massivecraft.mcore4.usys.AspectColl;
import com.massivecraft.mcore4.usys.MultiverseColl;
import com.massivecraft.mcore4.usys.cmd.CmdUsys;
import com.massivecraft.mcore4.util.PlayerUtil;
import com.massivecraft.mcore4.xlib.gson.Gson;
import com.massivecraft.mcore4.xlib.gson.GsonBuilder;
@ -70,6 +73,7 @@ public class MCore extends MPlugin
};
public InternalListener internalListener;
public CmdUsys cmdUsys;
@Override
public void onEnable()
@ -96,7 +100,13 @@ public class MCore extends MPlugin
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this.collTickTask, 1, 1);
// Init internal collections
USelColl.i.init();
USelColl.i.init(); // TODO: Remove and deprecate!? possibly yes... how soon?
MultiverseColl.i.init();
AspectColl.i.init();
// Register commands
this.cmdUsys = new CmdUsys();
this.cmdUsys.register(true);
this.postEnable();
}

View File

@ -8,6 +8,8 @@ import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import com.massivecraft.mcore4.cmd.Cmd;
import com.massivecraft.mcore4.integration.Integration;
import com.massivecraft.mcore4.integration.IntegrationFeatures;
import com.massivecraft.mcore4.persist.One;
import com.massivecraft.mcore4.persist.Persist;
import com.massivecraft.mcore4.store.Coll;
@ -96,6 +98,14 @@ public abstract class MPlugin extends JavaPlugin implements Listener
Bukkit.getPluginManager().disablePlugin(this);
}
public void integrate(IntegrationFeatures... features)
{
for (IntegrationFeatures f : features)
{
new Integration(this, f);
}
}
// -------------------------------------------- //
// LOGGING
// -------------------------------------------- //

View File

@ -157,8 +157,14 @@ public class PS implements Cloneable
protected Float pitch;
public PS pitch(Float val)
{
if (val == null) this.pitch = null;
this.pitch = (val + 360F) % 360F;
if (val == null)
{
this.pitch = null;
}
else
{
this.pitch = (val + 360F) % 360F;
}
return this;
}
public Float pitch() { return this.pitch; }
@ -421,11 +427,7 @@ public class PS implements Cloneable
public synchronized void write(Player player)
{
Location location = this.locationCalc();
if (location != null) player.teleport(location);
Vector velocity = this.velocity();
if (velocity != null) player.setVelocity(velocity);
teleporter.teleport(player, this);
}
//----------------------------------------------//
@ -487,6 +489,12 @@ public class PS implements Cloneable
return new PS(this);
}
// -------------------------------------------- //
// TELEPORTER
// -------------------------------------------- //
public static transient PSTeleporter teleporter = PSTeleporterDefault.get();
//----------------------------------------------//
// COMPARISON
//----------------------------------------------//

View File

@ -0,0 +1,8 @@
package com.massivecraft.mcore4;
import org.bukkit.entity.Entity;
public interface PSTeleporter
{
public void teleport(Entity entity, PS ps);
}

View File

@ -0,0 +1,28 @@
package com.massivecraft.mcore4;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.util.Vector;
public class PSTeleporterDefault implements PSTeleporter
{
@Override
public void teleport(Entity entity, PS ps)
{
Location location = ps.locationCalc();
if (location != null) entity.teleport(location);
Vector velocity = ps.velocity();
if (velocity != null) entity.setVelocity(velocity);
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
protected static PSTeleporterDefault instance = new PSTeleporterDefault();
public static PSTeleporterDefault get()
{
return instance;
}
}

View File

@ -0,0 +1,42 @@
package com.massivecraft.mcore4;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore4.util.Perm;
public enum Permission
{
USYS("usys"),
USYS_MULTIVERSE("usys.multiverse"),
USYS_MULTIVERSE_LIST("usys.multiverse.list"),
USYS_MULTIVERSE_SHOW("usys.multiverse.show"),
USYS_MULTIVERSE_NEW("usys.multiverse.new"),
USYS_MULTIVERSE_DEL("usys.multiverse.del"),
USYS_UNIVERSE("usys.universe"),
USYS_UNIVERSE_NEW("usys.universe.new"),
USYS_UNIVERSE_DEL("usys.universe.del"),
USYS_UNIVERSE_CLEAR("usys.universe.clear"),
USYS_WORLD("usys.world"),
USYS_ASPECT("usys.aspect"),
USYS_ASPECT_LIST("usys.aspect.list"),
USYS_ASPECT_SHOW("usys.aspect.show"),
USYS_ASPECT_USE("usys.aspect.use"),
;
public final String node;
Permission(final String permissionNode)
{
this.node = "mcore."+permissionNode;
}
public boolean has(CommandSender sender, boolean informSenderIfNot)
{
return Perm.has(sender, this.node, informSenderIfNot);
}
public boolean has(CommandSender sender)
{
return has(sender, false);
}
}

View File

@ -8,21 +8,29 @@ import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldType;
import org.bukkit.command.Command;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Player;
import com.massivecraft.mcore4.cmd.arg.AHBoolean;
import com.massivecraft.mcore4.cmd.arg.AHByte;
import com.massivecraft.mcore4.cmd.arg.AHDate;
import com.massivecraft.mcore4.cmd.arg.AHDouble;
import com.massivecraft.mcore4.cmd.arg.AHFloat;
import com.massivecraft.mcore4.cmd.arg.AHInteger;
import com.massivecraft.mcore4.cmd.arg.AHMaterial;
import com.massivecraft.mcore4.cmd.arg.AHPlayer;
import com.massivecraft.mcore4.cmd.arg.AHWorld;
import com.massivecraft.mcore4.cmd.arg.IArgHandler;
import com.massivecraft.mcore4.cmd.arg.old.AHAspect;
import com.massivecraft.mcore4.cmd.arg.old.AHBoolean;
import com.massivecraft.mcore4.cmd.arg.old.AHByte;
import com.massivecraft.mcore4.cmd.arg.old.AHDate;
import com.massivecraft.mcore4.cmd.arg.old.AHDouble;
import com.massivecraft.mcore4.cmd.arg.old.AHEnvironment;
import com.massivecraft.mcore4.cmd.arg.old.AHFloat;
import com.massivecraft.mcore4.cmd.arg.old.AHInteger;
import com.massivecraft.mcore4.cmd.arg.old.AHMaterial;
import com.massivecraft.mcore4.cmd.arg.old.AHMultiverse;
import com.massivecraft.mcore4.cmd.arg.old.AHPlayer;
import com.massivecraft.mcore4.cmd.arg.old.AHWorld;
import com.massivecraft.mcore4.cmd.arg.old.AHWorldType;
import com.massivecraft.mcore4.cmd.arg.old.IArgHandler;
import com.massivecraft.mcore4.usys.Aspect;
import com.massivecraft.mcore4.usys.Multiverse;
public class Cmd
{
@ -43,15 +51,19 @@ public class Cmd
public Cmd()
{
this.setArgHandler(Aspect.class, new AHAspect());
this.setArgHandler(Boolean.class, new AHBoolean());
this.setArgHandler(Byte.class, new AHByte());
this.setArgHandler(Double.class, new AHDouble());
this.setArgHandler(Date.class, new AHDate());
this.setArgHandler(Double.class, new AHDouble());
this.setArgHandler(Environment.class, new AHEnvironment());
this.setArgHandler(Float.class, new AHFloat());
this.setArgHandler(Integer.class, new AHInteger());
this.setArgHandler(Material.class, new AHMaterial());
this.setArgHandler(Multiverse.class, new AHMultiverse());
this.setArgHandler(Player.class, new AHPlayer());
this.setArgHandler(World.class, new AHWorld());
this.setArgHandler(WorldType.class, new AHWorldType());
}
public static SimpleCommandMap getBukkitCommandMap()

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import com.massivecraft.mcore4.MPlugin;
import com.massivecraft.mcore4.cmd.MCommand;
import com.massivecraft.mcore4.cmd.arg.ARInteger;
import com.massivecraft.mcore4.util.Txt;
public class HelpCommand extends MCommand
@ -37,7 +38,7 @@ public class HelpCommand extends MCommand
}
}
Integer pagenumber = this.argAs(0, Integer.class, 1);
Integer pagenumber = this.arg(0, ARInteger.get(), 1);
if (pagenumber == null) return;
sendMessage(Txt.getPage(lines, pagenumber, "Help for command \""+parentCommand.getAliases().get(0)+"\""));
}

View File

@ -11,7 +11,9 @@ import org.bukkit.entity.Player;
import com.massivecraft.mcore4.Lang;
import com.massivecraft.mcore4.MPlugin;
import com.massivecraft.mcore4.cmd.arg.IArgHandler;
import com.massivecraft.mcore4.cmd.arg.ArgReader;
import com.massivecraft.mcore4.cmd.arg.ArgResult;
import com.massivecraft.mcore4.cmd.arg.old.IArgHandler;
import com.massivecraft.mcore4.cmd.req.IReq;
import com.massivecraft.mcore4.cmd.req.ReqHasPerm;
import com.massivecraft.mcore4.util.Perm;
@ -435,10 +437,13 @@ public abstract class MCommand
// Argument Readers
// -------------------------------------------- //
public String arg(int idx)
public String argConcatFrom(int idx)
{
if ( ! this.argIsSet(idx)) return null;
return this.args.get(idx);
int from = idx;
int to = args.size();
if (to <= from) return "";
return Txt.implode(this.args.subList(from, to), " ");
}
public boolean argIsSet(int idx)
@ -450,6 +455,31 @@ public abstract class MCommand
return true;
}
public String arg(int idx)
{
if ( ! this.argIsSet(idx)) return null;
return this.args.get(idx);
}
public <T> T arg(int idx, ArgReader<T> ar)
{
return this.arg(idx, ar, null);
}
public <T> T arg(int idx, ArgReader<T> argReader, T defaultNotSet)
{
String str = this.arg(idx);
if (str == null) return defaultNotSet;
ArgResult<T> result = argReader.read(str, this);
if (result.hasErrors()) this.msg(result.getErrors());
return result.getResult();
}
// -------------------------------------------- //
// Argument Readers DEPRACATED TODO
// -------------------------------------------- //
@Deprecated
public synchronized <T> T argAs(int idx, Class<T> clazz, String style, T defaultNotSet, T defaultNotFound)
{
if ( ! this.argIsSet(idx))
@ -472,37 +502,35 @@ public abstract class MCommand
return ret;
}
@Deprecated
public <T> T argAs(int idx, Class<T> clazz, T defaultNotSet, T defaultNotFound)
{
return this.argAs(idx, clazz, null, defaultNotSet, defaultNotFound);
}
@Deprecated
public <T> T argAs(int idx, Class<T> clazz, String style, T defaultNotSet)
{
return this.argAs(idx, clazz, style, defaultNotSet, null);
}
@Deprecated
public <T> T argAs(int idx, Class<T> clazz, T defaultNotSet)
{
return this.argAs(idx, clazz, null, defaultNotSet, null);
}
@Deprecated
public <T> T argAs(int idx, Class<T> clazz, String style)
{
return this.argAs(idx, clazz, style, null, null);
}
@Deprecated
public <T> T argAs(int idx, Class<T> clazz)
{
return this.argAs(idx, clazz, (T)null, null);
}
public String argConcatFrom(int idx)
{
if ( ! this.argIsSet(idx)) return null;
int from = idx;
int to = args.size();
if (to <= from) return "";
return Txt.implode(args.subList(from, to), " ");
}
}

View File

@ -0,0 +1,26 @@
package com.massivecraft.mcore4.cmd.arg;
import com.massivecraft.mcore4.cmd.MCommand;
public abstract class ARAbstractPrimitive<T> implements ArgReader<T>
{
public abstract String typename();
public abstract T convert(String str) throws Exception;
@Override
public ArgResult<T> read(String str, MCommand mcommand)
{
ArgResult<T> result = new ArgResult<T>();
try
{
result.setResult(this.convert(str));
}
catch (Exception e)
{
result.getErrors().add("<b>Invalid "+this.typename()+" \"<h>"+str+"\"<b>.");
}
return result;
}
}

View File

@ -0,0 +1,39 @@
package com.massivecraft.mcore4.cmd.arg;
import java.util.Collection;
import com.massivecraft.mcore4.cmd.MCommand;
import com.massivecraft.mcore4.util.Txt;
public abstract class ARAbstractSelect<T> implements ArgReader<T>
{
public abstract String typename();
public abstract T select(String str, MCommand mcommand);
public abstract Collection<String> altNames(MCommand mcommand);
public boolean canList(MCommand mcommand) { return true; }
@Override
public ArgResult<T> read(String str, MCommand mcommand)
{
ArgResult<T> result = new ArgResult<T>(this.select(str, mcommand));
if (!result.hasResult())
{
result.getErrors().add("<b>No "+this.typename()+" matches \"<h>"+str+"<b>\".");
if (this.canList(mcommand))
{
Collection<String> names = this.altNames(mcommand);
if (names.size() == 0)
{
result.getErrors().add("<i>Note: There is no "+this.typename()+" available.");
}
else
{
result.getErrors().add("<i>Use "+Txt.implodeCommaAndDot(names, "<h>%s", "<i>, ", " <i>or ", "<i>."));
}
}
}
return result;
}
}

View File

@ -0,0 +1,77 @@
package com.massivecraft.mcore4.cmd.arg;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import com.massivecraft.mcore4.cmd.MCommand;
import com.massivecraft.mcore4.util.Txt;
public abstract class ARAbstractStringMatch implements ArgReader<String>
{
// -------------------------------------------- //
// IMPLEMENTATION
// -------------------------------------------- //
@Override
public ArgResult<String> read(String str, MCommand mcommand)
{
ArgResult<String> result = new ArgResult<String>();
// Find all matches
Set<String> matches = new HashSet<String>();
for (Collection<String> altColl : this.altColls())
{
for (String alt : altColl)
{
if (this.matches(str, alt))
{
matches.add(alt);
}
}
}
// Set result and errors
if (matches.size() == 1)
{
result.setResult(matches.iterator().next());
}
else if (matches.size() > 1)
{
result.getErrors().add("<b>"+Txt.upperCaseFirst(this.typename())+" matching \"<h>"+str+"<b>\" is ambigious.");
result.getErrors().add("<b>Did you mean "+Txt.implodeCommaAndDot(matches, "<h>%s", "<b>, ", " <b>or ", "<b>?"));
}
else if (matches.size() == 0)
{
result.getErrors().add("<b>No "+this.typename()+" matching \"<h>"+str+"<b>\".");
}
return result;
}
// -------------------------------------------- //
// ABSTRACT
// -------------------------------------------- //
public abstract boolean matches(String arg, String alt);
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected String typename;
public String typename() { return this.typename; }
protected Collection<Collection<String>> altColls;
public Collection<Collection<String>> altColls() { return this.altColls; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public ARAbstractStringMatch(String typename, Collection<Collection<String>> altColls)
{
this.typename = typename;
this.altColls = altColls;
}
}

View File

@ -0,0 +1,43 @@
package com.massivecraft.mcore4.cmd.arg;
import java.util.Collection;
import com.massivecraft.mcore4.Permission;
import com.massivecraft.mcore4.cmd.MCommand;
import com.massivecraft.mcore4.usys.Aspect;
import com.massivecraft.mcore4.usys.AspectColl;
public class ARAspect extends ARAbstractSelect<Aspect>
{
@Override
public String typename()
{
return "aspect";
}
@Override
public Aspect select(String str, MCommand mcommand)
{
return AspectColl.i.get(str);
}
@Override
public boolean canList(MCommand mcommand)
{
return Permission.USYS_ASPECT_LIST.has(mcommand.sender, false);
}
@Override
public Collection<String> altNames(MCommand mcommand)
{
return AspectColl.i.ids();
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static ARAspect i = new ARAspect();
public static ARAspect get() { return i; }
}

View File

@ -0,0 +1,29 @@
package com.massivecraft.mcore4.cmd.arg;
public class ARBoolean extends ARAbstractPrimitive<Boolean>
{
@Override
public String typename()
{
return "boolean";
}
@Override
public Boolean convert(String str) throws Exception
{
str = str.toLowerCase();
if (str.startsWith("y") || str.startsWith("t") || str.startsWith("on") || str.startsWith("+") || str.startsWith("1"))
{
return true;
}
return false;
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static ARBoolean i = new ARBoolean();
public static ARBoolean get() { return i; }
}

View File

@ -0,0 +1,24 @@
package com.massivecraft.mcore4.cmd.arg;
public class ARByte extends ARAbstractPrimitive<Byte>
{
@Override
public String typename()
{
return "byte";
}
@Override
public Byte convert(String str) throws Exception
{
return Byte.parseByte(str);
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static ARByte i = new ARByte();
public static ARByte get() { return i; }
}

View File

@ -0,0 +1,30 @@
package com.massivecraft.mcore4.cmd.arg;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ARDate extends ARAbstractPrimitive<Date>
{
protected static DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
@Override
public String typename()
{
return "YYYY-MM-DD date";
}
@Override
public Date convert(String str) throws Exception
{
return df.parse(str);
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static ARDate i = new ARDate();
public static ARDate get() { return i; }
}

View File

@ -0,0 +1,24 @@
package com.massivecraft.mcore4.cmd.arg;
public class ARDouble extends ARAbstractPrimitive<Double>
{
@Override
public String typename()
{
return "double";
}
@Override
public Double convert(String str) throws Exception
{
return Double.parseDouble(str);
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static ARDouble i = new ARDouble();
public static ARDouble get() { return i; }
}

View File

@ -0,0 +1,60 @@
package com.massivecraft.mcore4.cmd.arg;
import java.util.Collection;
import org.bukkit.World.Environment;
import com.massivecraft.mcore4.cmd.MCommand;
import com.massivecraft.mcore4.util.MUtil;
public class AREnvironment extends ARAbstractSelect<Environment>
{
@Override
public String typename()
{
return "environment";
}
@Override
public Environment select(String str, MCommand mcommand)
{
Environment ret = null;
// "THE_END" --> "end"
str = str.toLowerCase();
str = str.replace("_", "");
str = str.replace("the", "");
if (str.startsWith("no") || str.startsWith("d"))
{
// "normal" or "default"
ret = Environment.NORMAL;
}
else if (str.startsWith("ne"))
{
// "nether"
ret = Environment.NETHER;
}
else if (str.startsWith("e"))
{
// "end"
ret = Environment.THE_END;
}
return ret;
}
@Override
public Collection<String> altNames(MCommand mcommand)
{
return MUtil.list("normal", "end", "nether");
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static AREnvironment i = new AREnvironment();
public static AREnvironment get() { return i; }
}

View File

@ -0,0 +1,24 @@
package com.massivecraft.mcore4.cmd.arg;
public class ARFloat extends ARAbstractPrimitive<Float>
{
@Override
public String typename()
{
return "integer";
}
@Override
public Float convert(String str) throws Exception
{
return Float.parseFloat(str);
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static ARFloat i = new ARFloat();
public static ARFloat get() { return i; }
}

View File

@ -0,0 +1,24 @@
package com.massivecraft.mcore4.cmd.arg;
public class ARInteger extends ARAbstractPrimitive<Integer>
{
@Override
public String typename()
{
return "integer";
}
@Override
public Integer convert(String str) throws Exception
{
return Integer.parseInt(str);
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static ARInteger i = new ARInteger();
public static ARInteger get() { return i; }
}

View File

@ -0,0 +1,24 @@
package com.massivecraft.mcore4.cmd.arg;
public class ARLong extends ARAbstractPrimitive<Long>
{
@Override
public String typename()
{
return "long";
}
@Override
public Long convert(String str) throws Exception
{
return Long.parseLong(str);
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static ARLong i = new ARLong();
public static ARLong get() { return i; }
}

View File

@ -0,0 +1,28 @@
package com.massivecraft.mcore4.cmd.arg;
import org.bukkit.Material;
import com.massivecraft.mcore4.cmd.MCommand;
public class ARMaterial implements ArgReader<Material>
{
@Override
public ArgResult<Material> read(String str, MCommand mcommand)
{
ArgResult<Material> result = new ArgResult<Material>(Material.matchMaterial(str));
if (!result.hasResult())
{
result.getErrors().add("<b>No material matches <h>"+str+"<b>.");
result.getErrors().add("<i>Suggestion: <aqua>http://www.minecraftwiki.net/wiki/Data_values");
}
return result;
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static ARMaterial i = new ARMaterial();
public static ARMaterial get() { return i; }
}

View File

@ -0,0 +1,43 @@
package com.massivecraft.mcore4.cmd.arg;
import java.util.Collection;
import com.massivecraft.mcore4.Permission;
import com.massivecraft.mcore4.cmd.MCommand;
import com.massivecraft.mcore4.usys.Multiverse;
import com.massivecraft.mcore4.usys.MultiverseColl;
public class ARMultiverse extends ARAbstractSelect<Multiverse>
{
@Override
public String typename()
{
return "multiverse";
}
@Override
public Multiverse select(String str, MCommand mcommand)
{
return MultiverseColl.i.get(str);
}
@Override
public boolean canList(MCommand mcommand)
{
return Permission.USYS_MULTIVERSE_LIST.has(mcommand.sender, false);
}
@Override
public Collection<String> altNames(MCommand mcommand)
{
return MultiverseColl.i.ids();
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static ARMultiverse i = new ARMultiverse();
public static ARMultiverse get() { return i; }
}

View File

@ -0,0 +1,32 @@
package com.massivecraft.mcore4.cmd.arg;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.massivecraft.mcore4.cmd.MCommand;
public class AROnlinePlayerExact implements ArgReader<Player>
{
@Override
public ArgResult<Player> read(String str, MCommand mcommand)
{
ArgResult<Player> result = new ArgResult<Player>();
Player player = Bukkit.getServer().getPlayerExact(str);
result.setResult(player);
if (!result.hasResult())
{
result.getErrors().add("<b>No online player with exact name \"<h>"+str+"<b\">.");
}
return result;
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static AROnlinePlayerExact i = new AROnlinePlayerExact();
public static AROnlinePlayerExact get() { return i; }
}

View File

@ -0,0 +1,49 @@
package com.massivecraft.mcore4.cmd.arg;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.massivecraft.mcore4.cmd.MCommand;
import com.massivecraft.mcore4.util.Txt;
public class AROnlinePlayerMatch implements ArgReader<Player>
{
@Override
public ArgResult<Player> read(String str, MCommand mcommand)
{
ArgResult<Player> result = new ArgResult<Player>();
List<Player> players = Bukkit.getServer().matchPlayer(str);
if (players.size() == 1)
{
result.setResult(players.get(0));
}
else if (players.size() > 1)
{
List<String> names = new ArrayList<String>();
for (Player player : players)
{
names.add(player.getName());
}
result.getErrors().add("<b>Online player matching \"<h>"+str+"<b>\" is ambigious.");
result.getErrors().add("<b>Did you mean "+Txt.implodeCommaAndDot(names, "<h>%s", "<b>, ", " <b>or ", "<b>?"));
}
else if (players.size() == 0)
{
result.getErrors().add("<b>No online player matching \"<h>"+str+"<b\">.");
}
return result;
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static AROnlinePlayerMatch i = new AROnlinePlayerMatch();
public static AROnlinePlayerMatch get() { return i; }
}

View File

@ -0,0 +1,53 @@
package com.massivecraft.mcore4.cmd.arg;
import com.massivecraft.mcore4.cmd.MCommand;
import com.massivecraft.mcore4.store.PlayerColl;
import com.massivecraft.mcore4.store.PlayerEntity;
public class ARPlayerEntity<T extends PlayerEntity<T>> implements ArgReader<T>
{
// -------------------------------------------- //
// IMPLEMENTATION
// -------------------------------------------- //
@Override
public ArgResult<T> read(String str, MCommand mcommand)
{
ArgResult<T> result = new ArgResult<T>();
ArgResult<String> innerResult = this.stringReader().read(str, mcommand);
if (innerResult.hasResult())
{
String playerName = innerResult.getResult();
T entity = this.playerColl().get(playerName);
result.setResult(entity);
}
else
{
result.setErrors(innerResult.getErrors());
}
return result;
}
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected ArgReader<String> stringReader;
public ArgReader<String> stringReader() { return this.stringReader; }
protected PlayerColl<T> playerColl;
public PlayerColl<T> playerColl() { return this.playerColl; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public ARPlayerEntity(ArgReader<String> stringReader, PlayerColl<T> playerColl)
{
this.stringReader = stringReader;
this.playerColl = playerColl;
}
}

View File

@ -0,0 +1,24 @@
package com.massivecraft.mcore4.cmd.arg;
public class ARString extends ARAbstractPrimitive<String>
{
@Override
public String typename()
{
return "string";
}
@Override
public String convert(String str) throws Exception
{
return str;
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static ARString i = new ARString();
public static ARString get() { return i; }
}

View File

@ -0,0 +1,25 @@
package com.massivecraft.mcore4.cmd.arg;
import java.util.Collection;
public class ARStringMatchFullCI extends ARAbstractStringMatch
{
// -------------------------------------------- //
// IMPLEMENTATION
// -------------------------------------------- //
@Override
public boolean matches(String arg, String alt)
{
return alt.equalsIgnoreCase(arg);
}
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public ARStringMatchFullCI(String typename, Collection<Collection<String>> altColls)
{
super(typename, altColls);
}
}

View File

@ -0,0 +1,25 @@
package com.massivecraft.mcore4.cmd.arg;
import java.util.Collection;
public class ARStringMatchFullCS extends ARAbstractStringMatch
{
// -------------------------------------------- //
// IMPLEMENTATION
// -------------------------------------------- //
@Override
public boolean matches(String arg, String alt)
{
return alt.equals(arg);
}
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public ARStringMatchFullCS(String typename, Collection<Collection<String>> altColls)
{
super(typename, altColls);
}
}

View File

@ -0,0 +1,27 @@
package com.massivecraft.mcore4.cmd.arg;
import java.util.Collection;
public class ARStringMatchStartCI extends ARAbstractStringMatch
{
// -------------------------------------------- //
// IMPLEMENTATION
// -------------------------------------------- //
@Override
public boolean matches(String arg, String alt)
{
arg = arg.toLowerCase();
alt = alt.toLowerCase();
return alt.startsWith(arg);
}
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public ARStringMatchStartCI(String typename, Collection<Collection<String>> altColls)
{
super(typename, altColls);
}
}

View File

@ -0,0 +1,25 @@
package com.massivecraft.mcore4.cmd.arg;
import java.util.Collection;
public class ARStringMatchStartCS extends ARAbstractStringMatch
{
// -------------------------------------------- //
// IMPLEMENTATION
// -------------------------------------------- //
@Override
public boolean matches(String arg, String alt)
{
return alt.startsWith(arg);
}
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public ARStringMatchStartCS(String typename, Collection<Collection<String>> altColls)
{
super(typename, altColls);
}
}

View File

@ -0,0 +1,52 @@
package com.massivecraft.mcore4.cmd.arg;
import java.util.ArrayList;
import java.util.Collection;
import com.massivecraft.mcore4.cmd.MCommand;
import com.massivecraft.mcore4.usys.Multiverse;
import com.massivecraft.mcore4.util.Txt;
public class ARUniverse implements ArgReader<String>
{
// -------------------------------------------- //
// IMPLEMENTATION
// -------------------------------------------- //
@Override
public ArgResult<String> read(String str, MCommand mcommand)
{
ArgResult<String> result = new ArgResult<String>();
if (multiverse.containsUniverse(str))
{
result.setResult(str);
}
else
{
result.getErrors().add("<b>No universe \"<h>"+str+"<b>\" exists in multiverse <h>"+this.multiverse.getId()+"<b>.");
Collection<String> names = new ArrayList<String>(multiverse.getUniverses());
names.add(Multiverse.DEFAULT);
result.getErrors().add("<i>Use "+Txt.implodeCommaAndDot(names, "<h>%s", "<i>, ", " <i>or ", "<i>."));
}
return result;
}
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected Multiverse multiverse;
public Multiverse multiverse() { return this.multiverse; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public ARUniverse(Multiverse multiverse)
{
this.multiverse = multiverse;
}
}

View File

@ -0,0 +1,42 @@
package com.massivecraft.mcore4.cmd.arg;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.World;
import com.massivecraft.mcore4.cmd.MCommand;
public class ARWorld extends ARAbstractSelect<World>
{
@Override
public String typename()
{
return "world";
}
@Override
public World select(String str, MCommand mcommand)
{
return Bukkit.getWorld(str);
}
@Override
public List<String> altNames(MCommand mcommand)
{
List<String> ret = new ArrayList<String>();
for (World world : Bukkit.getWorlds())
{
ret.add(world.getName());
}
return ret;
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static ARWorld i = new ARWorld();
public static ARWorld get() { return i; }
}

View File

@ -0,0 +1,70 @@
package com.massivecraft.mcore4.cmd.arg;
import java.util.Collection;
import org.bukkit.WorldType;
import com.massivecraft.mcore4.cmd.MCommand;
import com.massivecraft.mcore4.util.MUtil;
public class ARWorldType extends ARAbstractSelect<WorldType>
{
@Override
public String typename()
{
return "world type";
}
@Override
public WorldType select(String str, MCommand mcommand)
{
WorldType ret = null;
// "DEFAULT_1_1" --> "11"
// "LARGE_BIOMES" --> "large"
// "Default" --> ""
str = str.toLowerCase();
str = str.replace("_", "");
str = str.replace(".", "");
str = str.replace("normal", "");
str = str.replace("default", "");
str = str.replace("large", "");
if (str.equals(""))
{
// "normal" or "default"
ret = WorldType.NORMAL;
}
else if (str.startsWith("flat"))
{
// "flat"
ret = WorldType.FLAT;
}
else if (str.contains("11"))
{
// "VERSION_1_1"
ret = WorldType.VERSION_1_1;
}
else if (str.contains("large"))
{
// "LARGE_BIOMES"
ret = WorldType.LARGE_BIOMES;
}
return ret;
}
@Override
public Collection<String> altNames(MCommand mcommand)
{
return MUtil.list("normal", "flat", "1.1", "largebiomes");
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static ARWorldType i = new ARWorldType();
public static ARWorldType get() { return i; }
}

View File

@ -0,0 +1,8 @@
package com.massivecraft.mcore4.cmd.arg;
import com.massivecraft.mcore4.cmd.MCommand;
public interface ArgReader<T>
{
public ArgResult<T> read(String str, MCommand mcommand);
}

View File

@ -0,0 +1,88 @@
package com.massivecraft.mcore4.cmd.arg;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ArgResult<T>
{
// -------------------------------------------- //
// FIELD: RESULT
// -------------------------------------------- //
protected T result = null;
public T getResult()
{
return this.result;
}
public void setResult(T val)
{
this.result = val;
}
public boolean hasResult()
{
return this.getResult() != null;
}
// -------------------------------------------- //
// FIELD: ERRORS
// -------------------------------------------- //
protected List<String> errors = new ArrayList<String>();
public List<String> getErrors()
{
return this.errors;
}
public void setErrors(List<String> val)
{
if (val == null)
{
this.errors = new ArrayList<String>();
}
else
{
this.errors = val;
}
}
public void setErrors(String... val)
{
this.setErrors(Arrays.asList(val));
}
public boolean hasErrors()
{
return this.errors.size() > 0;
}
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public ArgResult()
{
}
public ArgResult(T result)
{
this.setResult(result);
}
public ArgResult(T result, List<String> errors)
{
this.setResult(result);
this.setErrors(errors);
}
public ArgResult(T result, String... errors)
{
this.setResult(result);
this.setErrors(errors);
}
}

View File

@ -0,0 +1,31 @@
package com.massivecraft.mcore4.cmd.arg.old;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore4.MPlugin;
import com.massivecraft.mcore4.Permission;
import com.massivecraft.mcore4.usys.Aspect;
import com.massivecraft.mcore4.usys.AspectColl;
import com.massivecraft.mcore4.util.Txt;
public class AHAspect extends AHBase<Aspect>
{
@Override
public Aspect parse(String str, String style, CommandSender sender, MPlugin p)
{
this.error.clear();
Aspect ret = AspectColl.i.get(str);
if (ret == null)
{
this.error.add("<b>No aspect called \"<p>"+str+"<b>\".");
if (Permission.USYS_ASPECT_LIST.has(sender, false))
{
this.error.add("<i>Use "+Txt.implodeCommaAndDot(AspectColl.i.ids(), "<h>%s", "<i>, ", " <i>or ", "<i>."));
}
}
return ret;
}
}

View File

@ -1,4 +1,4 @@
package com.massivecraft.mcore4.cmd.arg;
package com.massivecraft.mcore4.cmd.arg.old;
import java.util.ArrayList;
import java.util.Collection;
@ -9,7 +9,7 @@ import com.massivecraft.mcore4.MPlugin;
public abstract class AHBase<T> implements IArgHandler<T>
{
protected Collection<String> error = new ArrayList<String>();
public Collection<String> error = new ArrayList<String>();
@Override
public abstract T parse(String str, String style, CommandSender sender, MPlugin p);

View File

@ -1,4 +1,5 @@
package com.massivecraft.mcore4.cmd.arg;
package com.massivecraft.mcore4.cmd.arg.old;
public class AHBoolean extends AHPrimitive<Boolean>
{

View File

@ -1,4 +1,5 @@
package com.massivecraft.mcore4.cmd.arg;
package com.massivecraft.mcore4.cmd.arg.old;
public class AHByte extends AHPrimitive<Byte>
{

View File

@ -1,9 +1,10 @@
package com.massivecraft.mcore4.cmd.arg;
package com.massivecraft.mcore4.cmd.arg.old;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class AHDate extends AHPrimitive<Date>
{
protected static DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

View File

@ -1,4 +1,5 @@
package com.massivecraft.mcore4.cmd.arg;
package com.massivecraft.mcore4.cmd.arg.old;
public class AHDouble extends AHPrimitive<Double>
{

View File

@ -0,0 +1,46 @@
package com.massivecraft.mcore4.cmd.arg.old;
import org.bukkit.World.Environment;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore4.MPlugin;
public class AHEnvironment extends AHBase<Environment>
{
@Override
public Environment parse(String str, String style, CommandSender sender, MPlugin p)
{
this.error.clear();
Environment ret = null;
// "THE_END" --> "end"
str = str.toLowerCase();
str = str.replace("_", "");
str = str.replace("the", "");
if (str.startsWith("no") || str.startsWith("d"))
{
// "normal" or "default"
ret = Environment.NORMAL;
}
else if (str.startsWith("ne"))
{
// "nether"
ret = Environment.NETHER;
}
else if (str.startsWith("e"))
{
// "end"
ret = Environment.THE_END;
}
if (ret == null)
{
this.error.add("<b>No environment matching \"<p>"+str+"<b>\".");
this.error.add("<i>Use <h>normal<i>, <h>end<i> or <h>nether<i>.");
}
return ret;
}
}

View File

@ -1,4 +1,5 @@
package com.massivecraft.mcore4.cmd.arg;
package com.massivecraft.mcore4.cmd.arg.old;
public class AHFloat extends AHPrimitive<Float>
{

View File

@ -1,4 +1,5 @@
package com.massivecraft.mcore4.cmd.arg;
package com.massivecraft.mcore4.cmd.arg.old;
public class AHInteger extends AHPrimitive<Integer>
{

View File

@ -1,4 +1,4 @@
package com.massivecraft.mcore4.cmd.arg;
package com.massivecraft.mcore4.cmd.arg.old;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;

View File

@ -0,0 +1,32 @@
package com.massivecraft.mcore4.cmd.arg.old;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore4.MPlugin;
import com.massivecraft.mcore4.Permission;
import com.massivecraft.mcore4.usys.Multiverse;
import com.massivecraft.mcore4.usys.MultiverseColl;
import com.massivecraft.mcore4.util.Txt;
public class AHMultiverse extends AHBase<Multiverse>
{
@Override
public Multiverse parse(String str, String style, CommandSender sender, MPlugin p)
{
this.error.clear();
Multiverse ret = MultiverseColl.i.get(str);
if (ret == null)
{
this.error.add("<b>No multiverse called \"<p>"+str+"<b>\".");
if (Permission.USYS_MULTIVERSE_LIST.has(sender, false))
{
this.error.add("<i>Use "+Txt.implodeCommaAndDot(MultiverseColl.i.ids(), "<h>%s", "<i>, ", " <i>or ", "<i>."));
}
}
return ret;
}
}

View File

@ -1,4 +1,4 @@
package com.massivecraft.mcore4.cmd.arg;
package com.massivecraft.mcore4.cmd.arg.old;
import java.util.List;

View File

@ -1,4 +1,4 @@
package com.massivecraft.mcore4.cmd.arg;
package com.massivecraft.mcore4.cmd.arg.old;
import org.bukkit.command.CommandSender;

View File

@ -1,4 +1,4 @@
package com.massivecraft.mcore4.cmd.arg;
package com.massivecraft.mcore4.cmd.arg.old;
import java.util.Collection;

View File

@ -1,4 +1,4 @@
package com.massivecraft.mcore4.cmd.arg;
package com.massivecraft.mcore4.cmd.arg.old;
import org.bukkit.command.CommandSender;

View File

@ -1,4 +1,4 @@
package com.massivecraft.mcore4.cmd.arg;
package com.massivecraft.mcore4.cmd.arg.old;
import org.bukkit.command.CommandSender;

View File

@ -1,4 +1,4 @@
package com.massivecraft.mcore4.cmd.arg;
package com.massivecraft.mcore4.cmd.arg.old;
import org.bukkit.Bukkit;
import org.bukkit.World;

View File

@ -0,0 +1,57 @@
package com.massivecraft.mcore4.cmd.arg.old;
import org.bukkit.WorldType;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore4.MPlugin;
public class AHWorldType extends AHBase<WorldType>
{
@Override
public WorldType parse(String str, String style, CommandSender sender, MPlugin p)
{
this.error.clear();
WorldType ret = null;
// "DEFAULT_1_1" --> "11"
// "LARGE_BIOMES" --> "large"
// "Default" --> ""
str = str.toLowerCase();
str = str.replace("_", "");
str = str.replace(".", "");
str = str.replace("normal", "");
str = str.replace("default", "");
str = str.replace("large", "");
if (str.equals(""))
{
// "normal" or "default"
ret = WorldType.NORMAL;
}
else if (str.startsWith("flat"))
{
// "flat"
ret = WorldType.FLAT;
}
else if (str.contains("11"))
{
// "VERSION_1_1"
ret = WorldType.VERSION_1_1;
}
else if (str.contains("large"))
{
// "LARGE_BIOMES"
ret = WorldType.LARGE_BIOMES;
}
if (ret == null)
{
this.error.add("<b>No world type matching \"<p>"+str+"<b>\".");
this.error.add("<i>Use <h>normal<i>, <h>flat<i>, <h>1.1<i> or <h>largebiomes<i>.");
}
return ret;
}
}

View File

@ -1,4 +1,4 @@
package com.massivecraft.mcore4.cmd.arg;
package com.massivecraft.mcore4.cmd.arg.old;
import java.util.Collection;

View File

@ -0,0 +1,52 @@
package com.massivecraft.mcore4.event;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerRespawnEvent;
public class MCoreAfterPlayerRespawnEvent extends Event implements Runnable
{
// -------------------------------------------- //
// REQUIRED EVENT CODE
// -------------------------------------------- //
private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; }
// -------------------------------------------- //
// FIELD
// -------------------------------------------- //
protected Location deathLocation;
public Location getDeathLocation() { return this.deathLocation; }
protected PlayerRespawnEvent bukkitEvent;
public PlayerRespawnEvent getBukkitEvent() { return this.bukkitEvent; }
public Location getRespawnLocation() { return this.bukkitEvent.getRespawnLocation(); }
public Player getPlayer() { return this.bukkitEvent.getPlayer(); }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public MCoreAfterPlayerRespawnEvent(PlayerRespawnEvent bukkitEvent, Location deathLocation)
{
this.bukkitEvent = bukkitEvent;
this.deathLocation = deathLocation;
}
// -------------------------------------------- //
// HANDY RUN SHORTCUT
// -------------------------------------------- //
@Override
public void run()
{
Bukkit.getPluginManager().callEvent(this);
}
}

View File

@ -0,0 +1,50 @@
package com.massivecraft.mcore4.event;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
public class MCoreAfterPlayerTeleportEvent extends Event implements Runnable
{
// -------------------------------------------- //
// REQUIRED EVENT CODE
// -------------------------------------------- //
private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; }
// -------------------------------------------- //
// FIELD
// -------------------------------------------- //
protected PlayerTeleportEvent bukkitEvent;
public PlayerTeleportEvent getBukkitEvent() { return this.bukkitEvent; }
public Location getFrom() { return this.bukkitEvent.getFrom(); }
public Location getTo() { return this.bukkitEvent.getTo(); }
public Player getPlayer() { return this.bukkitEvent.getPlayer(); }
public TeleportCause getCause() { return this.bukkitEvent.getCause(); }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public MCoreAfterPlayerTeleportEvent(PlayerTeleportEvent bukkitEvent)
{
this.bukkitEvent = bukkitEvent;
}
// -------------------------------------------- //
// HANDY RUN SHORTCUT
// -------------------------------------------- //
@Override
public void run()
{
Bukkit.getPluginManager().callEvent(this);
}
}

View File

@ -0,0 +1,63 @@
package com.massivecraft.mcore4.event;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* The MCorePlayerLeaveEvent is a non-cancellable event.
* It is run at the MONITOR of either PlayerKickEvent or PlayerQuitEvent.
* It is also guaranteed to run before the MCore "store" module syncs
* all entities related to the player that is leaving the server.
*
* Use this even if you want to update a player entity as
* that player leaves. Automatic syncing will be guaranteed and the
* event will run the moment BEFORE the player leaves the server if possible
* due to the internal usage if the PlayerKickedEvent.
*/
public class MCorePlayerLeaveEvent extends Event implements Runnable
{
// -------------------------------------------- //
// REQUIRED EVENT CODE
// -------------------------------------------- //
private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; }
// -------------------------------------------- //
// FIELD
// -------------------------------------------- //
protected Player player;
public Player getPlayer() { return this.player; }
protected boolean kick;
public boolean isKick() { return this.kick; }
public boolean isQuit() { return !this.kick; }
protected String kickReason;
public String getKickReason() { return this.kickReason; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public MCorePlayerLeaveEvent(Player player, boolean kick, String kickReason)
{
this.player = player;
this.kick = kick;
this.kickReason = kickReason;
}
// -------------------------------------------- //
// HANDY RUN SHORTCUT
// -------------------------------------------- //
@Override
public void run()
{
Bukkit.getPluginManager().callEvent(this);
}
}

View File

@ -0,0 +1,106 @@
package com.massivecraft.mcore4.integration;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.plugin.Plugin;
import com.massivecraft.mcore4.MPlugin;
public class Integration implements Listener
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected MPlugin ourPlugin;
protected IntegrationFeatures features;
protected boolean active = false;
public boolean active() { return this.active; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public Integration(MPlugin ourPlugin, IntegrationFeatures features)
{
this.ourPlugin = ourPlugin;
this.features = features;
Bukkit.getServer().getPluginManager().registerEvents(this, this.ourPlugin);
this.tick();
}
// -------------------------------------------- //
// LOGIC
// -------------------------------------------- //
public void tick()
{
if (pluginEnabled(this.features.getTargetPluginName()))
{
if (!this.active)
{
try
{
this.features.activate();
this.active = true;
this.ourPlugin.log("Activated integration with "+this.features.getTargetPluginName()+".");
}
catch (Exception e)
{
this.ourPlugin.log("Failed to activate integration with "+this.features.getTargetPluginName()+".");
e.printStackTrace();
}
}
}
else
{
if (this.active)
{
try
{
this.active = false;
this.features.deactivate();
this.ourPlugin.log("Deactivated integration with "+this.features.getTargetPluginName()+".");
}
catch (Exception e)
{
this.ourPlugin.log("Failed to deactivate integration with "+this.features.getTargetPluginName()+".");
e.printStackTrace();
}
}
}
}
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //
public static boolean pluginEnabled(String pluginName)
{
Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName);
if (plugin == null) return false;
return plugin.isEnabled();
}
// -------------------------------------------- //
// EVENT LISTENERS
// -------------------------------------------- //
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginDisable(PluginDisableEvent event)
{
this.tick();
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginEnable(PluginEnableEvent event)
{
this.tick();
}
}

View File

@ -0,0 +1,8 @@
package com.massivecraft.mcore4.integration;
public interface IntegrationFeatures
{
public String getTargetPluginName();
public void activate();
public void deactivate();
}

View File

@ -0,0 +1,25 @@
package com.massivecraft.mcore4.integration;
public abstract class IntegrationFeaturesAbstract implements IntegrationFeatures
{
@Override
public String getTargetPluginName()
{
// "SpoutFeatures" --> "Spout"
String ret = this.getClass().getSimpleName();
ret = ret.substring(0, ret.length()-8);
return ret;
}
@Override
public void activate()
{
}
@Override
public void deactivate()
{
}
}

View File

@ -2,18 +2,18 @@ package com.massivecraft.mcore4.persist;
import java.util.Collection;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import com.massivecraft.mcore4.util.PlayerUtil;
import com.massivecraft.mcore4.util.Txt;
public abstract class PlayerEntity<T extends PlayerEntity<T>> extends Entity<T>
{
public Player getPlayer()
{
return PlayerUtil.getPlayerExact(this.getId());
// There is no case sensitivity.
return Bukkit.getPlayerExact(this.getId());
}
public boolean isOnline()

View File

@ -33,11 +33,11 @@ public class Coll<E, L> implements CollInterface<E, L>
protected final String name;
@Override public String name() { return this.name; }
protected final String nameContext;
@Override public String nameContext() { return this.nameContext; }
protected final String basename;
@Override public String basename() { return this.basename; }
protected final String nameUniverse;
@Override public String nameUniverse() { return this.nameUniverse; }
protected final String universe;
@Override public String universe() { return this.universe; }
protected final Class<E> entityClass;
@Override public Class<E> entityClass() { return this.entityClass; }
@ -536,14 +536,14 @@ public class Coll<E, L> implements CollInterface<E, L>
// Setup the name and the parsed parts
this.name = name;
String[] nameParts = this.name.split("\\@");
this.nameContext = nameParts[0];
this.basename = nameParts[0];
if (nameParts.length > 1)
{
this.nameUniverse = nameParts[1];
this.universe = nameParts[1];
}
else
{
this.nameUniverse = null;
this.universe = null;
}
this.entityClass = entityClass;

View File

@ -15,8 +15,8 @@ public interface CollInterface<E, L>
// WHAT DO WE HANDLE?
// -------------------------------------------- //
public String name();
public String nameContext();
public String nameUniverse();
public String basename();
public String universe();
public Class<E> entityClass();
public Class<L> idClass();

View File

@ -3,15 +3,18 @@ package com.massivecraft.mcore4.store;
import java.util.HashMap;
import java.util.Map;
import com.massivecraft.mcore4.usys.Aspect;
import com.massivecraft.mcore4.util.MUtil;
public abstract class Colls<C extends Coll<E, L>, E, L>
{
protected Map<String, C> name2coll = new HashMap<String, C>();
public Map<String, C> name2coll() { return this.name2coll; }
public abstract C createColl(String name);
public abstract String getContext();
public abstract Aspect aspect();
public abstract String basename();
public abstract Db<?> getDb();
@ -21,7 +24,7 @@ public abstract class Colls<C extends Coll<E, L>, E, L>
public void init()
{
String start = this.collnameStart();
String start = this.collnameForUniverse("");
for (String collname : this.getDb().collnames())
{
if ( ! collname.startsWith(start)) continue;
@ -33,15 +36,16 @@ public abstract class Colls<C extends Coll<E, L>, E, L>
// UTIL
// -------------------------------------------- //
public String collnameStart()
public String collnameForUniverse(String universe)
{
return this.getContext() + "@";
return this.basename() + "@" + universe;
}
public String universeFromWorldName(String worldName)
{
USel selector = USelColl.i.get(this.getContext());
return selector.select(worldName);
if (worldName == null) throw new IllegalArgumentException("worldName may not be null.");
return this.aspect().multiverse().getUniverseForWorldName(worldName);
}
// -------------------------------------------- //
@ -50,12 +54,15 @@ public abstract class Colls<C extends Coll<E, L>, E, L>
public C getForWorld(String worldName)
{
if (worldName == null) throw new IllegalArgumentException("worldName may not be null.");
return this.getForUniverse(this.universeFromWorldName(worldName));
}
public C getForUniverse(String universe)
{
String collname = this.collnameStart() + universe;
if (universe == null) throw new IllegalArgumentException("universe may not be null.");
String collname = this.collnameForUniverse(universe);
return this.getForCollname(collname);
}

View File

@ -28,7 +28,7 @@ public abstract class Entity<E extends Entity<E, L>, L>
Coll<E, L> coll = this.getColl();
if (coll == null) return null;
return coll.nameUniverse();
return coll.universe();
}
public L attach(Coll<E, L> coll)

View File

@ -17,9 +17,7 @@ public class JsonFileFilter implements FileFilter
// INSTANCE
// -------------------------------------------- //
protected static JsonFileFilter instance = new JsonFileFilter();
public static JsonFileFilter get()
{
return instance;
}
private static JsonFileFilter instance = new JsonFileFilter();
public static JsonFileFilter get() { return instance; }
}

View File

@ -6,11 +6,16 @@ import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerEvent;
import com.massivecraft.mcore4.MCore;
import com.massivecraft.mcore4.MPlugin;
import com.massivecraft.mcore4.Predictate;
import com.massivecraft.mcore4.cmd.arg.ARPlayerEntity;
import com.massivecraft.mcore4.cmd.arg.ARStringMatchFullCI;
import com.massivecraft.mcore4.cmd.arg.ARStringMatchStartCI;
import com.massivecraft.mcore4.cmd.arg.ArgReader;
import com.massivecraft.mcore4.util.MUtil;
import com.massivecraft.mcore4.util.PlayerUtil;
public class PlayerColl<E extends PlayerEntity<E>> extends Coll<E, String>
{
@ -24,14 +29,15 @@ public class PlayerColl<E extends PlayerEntity<E>> extends Coll<E, String>
super(MCore.getDb(), mplugin, "ai", name, entityClass, String.class, true);
}
// -------------------------------------------- //
// EXTRAS
// -------------------------------------------- //
@Override
public String idFix(Object oid)
{
if (oid == null) return null;
if (oid instanceof String) return (String) oid;
if (oid instanceof Player) return ((Player)oid).getName();
if (oid instanceof PlayerEvent) return ((PlayerEvent)oid).getPlayer().getName();
return null;
return MUtil.extract(String.class, "playerName", oid);
}
public Collection<E> getAllOnline()
@ -57,4 +63,36 @@ public class PlayerColl<E extends PlayerEntity<E>> extends Coll<E, String>
});
}
// -------------------------------------------- //
// ARGUMENT READERS
// -------------------------------------------- //
protected Collection<Collection<String>> forgeAltColls()
{
Collection<Collection<String>> ret = new ArrayList<Collection<String>>();
ret.add(this.ids());
if (this.creative()) ret.add(PlayerUtil.getAllVisitorNames());
return ret;
}
public ArgReader<String> argReaderPlayerNameFull()
{
return new ARStringMatchFullCI("player", this.forgeAltColls());
}
public ArgReader<String> argReaderPlayerNameStart()
{
return new ARStringMatchStartCI("player", this.forgeAltColls());
}
public ArgReader<E> argReaderPlayerFull()
{
return new ARPlayerEntity<E>(this.argReaderPlayerNameFull(), this);
}
public ArgReader<E> argReaderPlayerStart()
{
return new ARPlayerEntity<E>(this.argReaderPlayerNameStart(), this);
}
}

View File

@ -26,13 +26,22 @@ public abstract class PlayerEntity<E extends PlayerEntity<E>> extends Entity<E,
return ! isOnline();
}
public String getCurrentUniverse()
/*public String getCurrentUniverse()
{
Player player = this.getPlayer();
if (player == null) return null;
String context = this.getColl().nameContext();
return USelColl.i.get(context).select(player.getWorld().getName());
String aspectId = this.getColl().nameAspect();
Aspect aspect = Aspect.get(aspectId);
aspect.
return USelColl.i.get(aspect).select(player.getWorld().getName());
vi ska returna ett universeId
}
public boolean isInThisUniverse()
@ -44,7 +53,7 @@ public abstract class PlayerEntity<E extends PlayerEntity<E>> extends Entity<E,
if (currentUniverse == null) return false;
return universe.equals(currentUniverse);
}
}*/
// -------------------------------------------- //
// CHECKER UTILS

View File

@ -0,0 +1,63 @@
package com.massivecraft.mcore4.usys;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import com.massivecraft.mcore4.store.Entity;
public class Aspect extends Entity<Aspect, String>
{
// -------------------------------------------- //
// META
// -------------------------------------------- //
@Override protected Aspect getThis() { return this; }
private final static transient Aspect defaultInstance = new Aspect();
@Override public Aspect getDefaultInstance(){ return defaultInstance; }
@Override protected Class<Aspect> getClazz() { return Aspect.class; }
public static Aspect get(Object oid)
{
return AspectColl.i.get(oid);
}
// -------------------------------------------- //
// TRANSIENT FIELDS
// -------------------------------------------- //
protected transient boolean registered = false;
public boolean registered() { return this.registered; }
public void register() { this.registered = true; }
protected transient Collection<String> desc = new ArrayList<String>();
public Collection<String> desc() { return this.desc; }
public void desc(Collection<String> val) { this.desc = val; }
public void desc(String... val) { this.desc = Arrays.asList(val); }
// -------------------------------------------- //
// STORED FIELDS
// -------------------------------------------- //
protected String multiverseId;
public String multiverseId() { return this.multiverseId; }
public void multiverseId(String val) { this.multiverseId = val; }
public Multiverse multiverse()
{
Multiverse ret = MultiverseColl.i.get(this.multiverseId);
if (ret == null) ret = MultiverseColl.i.get(Multiverse.DEFAULT);
return ret;
}
public void multiverse(Multiverse val) { this.multiverseId = val.getId(); }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public Aspect()
{
}
}

View File

@ -0,0 +1,48 @@
package com.massivecraft.mcore4.usys;
import java.util.ArrayList;
import java.util.List;
import com.massivecraft.mcore4.MCore;
import com.massivecraft.mcore4.store.Coll;
public class AspectColl extends Coll<Aspect, String>
{
// -------------------------------------------- //
// META
// -------------------------------------------- //
public static AspectColl i = new AspectColl();
private AspectColl()
{
super(MCore.p, "ai", "usys_aspect", Aspect.class, String.class, false);
}
// -------------------------------------------- //
// EXTRAS
// -------------------------------------------- //
public List<Aspect> getAllRegistered()
{
List<Aspect> ret = new ArrayList<Aspect>();
for (Aspect aspect : this.getAll())
{
if(aspect.registered() == false) continue;
ret.add(aspect);
}
return ret;
}
public List<Aspect> getAllRegisteredForMultiverse(Multiverse multiverse, boolean normal)
{
List<Aspect> ret = new ArrayList<Aspect>();
for (Aspect aspect : this.getAll())
{
if(aspect.registered() == false) continue;
if((aspect.multiverse() != multiverse) == normal) continue;
ret.add(aspect);
}
return ret;
}
}

View File

@ -0,0 +1,175 @@
package com.massivecraft.mcore4.usys;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import com.massivecraft.mcore4.cmd.arg.ARUniverse;
import com.massivecraft.mcore4.store.Entity;
import com.massivecraft.mcore4.util.MUtil;
public class Multiverse extends Entity<Multiverse, String>
{
// -------------------------------------------- //
// META
// -------------------------------------------- //
@Override protected Multiverse getThis() { return this; }
private final static transient Multiverse defaultInstance = new Multiverse();
@Override public Multiverse getDefaultInstance(){ return defaultInstance; }
@Override protected Class<Multiverse> getClazz() { return Multiverse.class; }
public static Multiverse get(Object oid)
{
return MultiverseColl.i.get(oid);
}
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
public static final transient String DEFAULT = "default";
protected Map<String, Set<String>> uw = new HashMap<String, Set<String>>();
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public Multiverse()
{
}
// -------------------------------------------- //
// ASPECTS
// -------------------------------------------- //
public List<Aspect> myAspects()
{
return AspectColl.i.getAllRegisteredForMultiverse(this, true);
}
public List<Aspect> otherAspects()
{
return AspectColl.i.getAllRegisteredForMultiverse(this, false);
}
// -------------------------------------------- //
// UNIVERSE
// -------------------------------------------- //
public boolean containsUniverse(String worldName)
{
return worldName.equals(Multiverse.DEFAULT) || this.uw.containsKey(worldName);
}
public Set<String> newUniverse(String universe)
{
Set<String> ret = this.uw.get(universe);
if (ret == null)
{
ret = new HashSet<String>();
this.uw.put(universe, ret);
}
return ret;
}
public Set<String> delUniverse(String universe)
{
return this.uw.remove(universe);
}
public Set<String> getUniverses()
{
return this.uw.keySet();
}
public String getUniverseForWorldName(String worldName)
{
for (Entry<String, Set<String>> entry : this.uw.entrySet())
{
String universe = entry.getKey();
Set<String> worlds = entry.getValue();
if (worlds.contains(worldName)) return universe;
}
return Multiverse.DEFAULT;
}
public String getUniverse(Object worldNameExtractable)
{
String worldName = MUtil.extract(String.class, "worldName", worldNameExtractable);
return this.getUniverseForWorldName(worldName);
}
// -------------------------------------------- //
// UNIVERSE AND WORLD
// -------------------------------------------- //
public boolean clearUniverse(String universe)
{
Set<String> worlds = this.uw.get(universe);
if (worlds == null) return false;
worlds.clear();
return true;
}
public boolean setWorldUniverse(String worldName, String universe)
{
if (this.getUniverseForWorldName(worldName).equals(universe)) return false;
this.removeWorld(worldName);
if (!universe.equals(Multiverse.DEFAULT))
{
this.newUniverse(universe).add(worldName);
}
return true;
}
// -------------------------------------------- //
// WORLD
// -------------------------------------------- //
public boolean containsWorld(String worldName)
{
return this.getWorlds().contains(worldName);
}
public Set<String> getWorlds()
{
Set<String>ret = new HashSet<String>();
for (Set<String> uworlds : this.uw.values())
{
ret.addAll(uworlds);
}
return ret;
}
public Set<String> getWorlds(String universe)
{
return this.uw.get(universe);
}
public boolean removeWorld(String worldName)
{
for (Set<String> worldNames : this.uw.values())
{
if(worldNames.remove(worldName)) return true;
}
return false;
}
// -------------------------------------------- //
// ARG READERS
// -------------------------------------------- //
public ARUniverse argReaderUniverse()
{
return new ARUniverse(this);
}
}

View File

@ -0,0 +1,27 @@
package com.massivecraft.mcore4.usys;
import com.massivecraft.mcore4.MCore;
import com.massivecraft.mcore4.store.Coll;
public class MultiverseColl extends Coll<Multiverse, String>
{
// -------------------------------------------- //
// META
// -------------------------------------------- //
public static MultiverseColl i = new MultiverseColl();
private MultiverseColl()
{
super(MCore.p, "ai", "usys_multiverse", Multiverse.class, String.class, false);
}
@Override
public void init()
{
super.init();
// Ensure the default multiverse exits
this.get(Multiverse.DEFAULT, true);
}
}

View File

@ -0,0 +1,35 @@
package com.massivecraft.mcore4.usys.cmd;
import com.massivecraft.mcore4.Permission;
import com.massivecraft.mcore4.cmd.HelpCommand;
import com.massivecraft.mcore4.cmd.req.ReqHasPerm;
public class CmdUsys extends UsysCommand
{
public CmdUsysMultiverse cmdUsysMultiverse = new CmdUsysMultiverse();
public CmdUsysUniverse cmdUsysUniverse = new CmdUsysUniverse();
public CmdUsysWorld cmdUsysWorld = new CmdUsysWorld();
public CmdUsysAspect cmdUsysAspect = new CmdUsysAspect();
public CmdUsys()
{
super();
// TODO: Make configurable
this.addAliases("usys");
this.addSubCommand(this.cmdUsysMultiverse);
this.addSubCommand(this.cmdUsysUniverse);
this.addSubCommand(this.cmdUsysWorld);
this.addSubCommand(this.cmdUsysAspect);
this.addRequirements(ReqHasPerm.get(Permission.USYS.node));
}
@Override
public void perform()
{
this.getCommandChain().add(this);
HelpCommand.getInstance().execute(this.sender, this.args, this.commandChain);
}
}

View File

@ -0,0 +1,31 @@
package com.massivecraft.mcore4.usys.cmd;
import com.massivecraft.mcore4.Permission;
import com.massivecraft.mcore4.cmd.HelpCommand;
import com.massivecraft.mcore4.cmd.req.ReqHasPerm;
public class CmdUsysAspect extends UsysCommand
{
public CmdUsysAspectList cmdUsysAspectList = new CmdUsysAspectList();
public CmdUsysAspectShow cmdUsysAspectShow = new CmdUsysAspectShow();
public CmdUsysAspectUse cmdUsysAspectUse = new CmdUsysAspectUse();
public CmdUsysAspect()
{
super();
this.addAliases("a", "aspect");
this.addSubCommand(this.cmdUsysAspectList);
this.addSubCommand(this.cmdUsysAspectShow);
this.addSubCommand(this.cmdUsysAspectUse);
this.addRequirements(ReqHasPerm.get(Permission.USYS_ASPECT.node));
}
@Override
public void perform()
{
this.getCommandChain().add(this);
HelpCommand.getInstance().execute(this.sender, this.args, this.commandChain);
}
}

View File

@ -0,0 +1,41 @@
package com.massivecraft.mcore4.usys.cmd;
import java.util.ArrayList;
import java.util.List;
import com.massivecraft.mcore4.Permission;
import com.massivecraft.mcore4.cmd.arg.ARInteger;
import com.massivecraft.mcore4.cmd.req.ReqHasPerm;
import com.massivecraft.mcore4.usys.Aspect;
import com.massivecraft.mcore4.usys.AspectColl;
import com.massivecraft.mcore4.util.Txt;
public class CmdUsysAspectList extends UsysCommand
{
public CmdUsysAspectList()
{
this.addAliases("l", "list");
this.addOptionalArg("page", "1");
this.addRequirements(ReqHasPerm.get(Permission.USYS_ASPECT_LIST.node));
}
@Override
public void perform()
{
Integer pageHumanBased = this.arg(0, ARInteger.get(), 1);
if (pageHumanBased == null) return;
// Create Messages
List<String> lines = new ArrayList<String>();
for (Aspect aspect : AspectColl.i.getAllRegistered())
{
lines.add("<h>"+aspect.getId()+" <white>--> <h>"+aspect.multiverse().getId());
}
// Send them
lines = Txt.parseWrap(lines);
this.sendMessage(Txt.getPage(lines, pageHumanBased, "Aspect List"));
}
}

View File

@ -0,0 +1,33 @@
package com.massivecraft.mcore4.usys.cmd;
import com.massivecraft.mcore4.Permission;
import com.massivecraft.mcore4.cmd.arg.ARAspect;
import com.massivecraft.mcore4.cmd.req.ReqHasPerm;
import com.massivecraft.mcore4.usys.Aspect;
import com.massivecraft.mcore4.util.Txt;
public class CmdUsysAspectShow extends UsysCommand
{
public CmdUsysAspectShow()
{
this.addAliases("s", "show");
this.addRequiredArg("aspect");
this.addRequirements(ReqHasPerm.get(Permission.USYS_ASPECT_SHOW.node));
}
@Override
public void perform()
{
Aspect aspect = this.arg(0, ARAspect.get());
if (aspect == null) return;
msg(Txt.titleize("Aspect: "+aspect.getId()));
msg("<k>using multiverse: <v>%s",aspect.multiverse().getId());
for (String descLine : aspect.desc())
{
msg(descLine);
}
}
}

View File

@ -0,0 +1,34 @@
package com.massivecraft.mcore4.usys.cmd;
import com.massivecraft.mcore4.Permission;
import com.massivecraft.mcore4.cmd.arg.ARAspect;
import com.massivecraft.mcore4.cmd.arg.ARMultiverse;
import com.massivecraft.mcore4.cmd.req.ReqHasPerm;
import com.massivecraft.mcore4.usys.Aspect;
import com.massivecraft.mcore4.usys.Multiverse;
public class CmdUsysAspectUse extends UsysCommand
{
public CmdUsysAspectUse()
{
this.addAliases("u", "use");
this.addRequiredArg("aspect");
this.addRequiredArg("multiverse");
this.addRequirements(ReqHasPerm.get(Permission.USYS_ASPECT_USE.node));
}
@Override
public void perform()
{
Aspect aspect = this.arg(0, ARAspect.get());
if (aspect == null) return;
Multiverse multiverse = this.arg(1, ARMultiverse.get());
if (multiverse == null) return;
aspect.multiverse(multiverse);
msg("<g>The aspect <h>%s<g> now use multiverse <h>%s<g>.", aspect.getId(), multiverse.getId());
}
}

View File

@ -0,0 +1,33 @@
package com.massivecraft.mcore4.usys.cmd;
import com.massivecraft.mcore4.Permission;
import com.massivecraft.mcore4.cmd.HelpCommand;
import com.massivecraft.mcore4.cmd.req.ReqHasPerm;
public class CmdUsysMultiverse extends UsysCommand
{
public CmdUsysMultiverseList cmdUsysMultiverseList = new CmdUsysMultiverseList();
public CmdUsysMultiverseShow cmdUsysMultiverseShow = new CmdUsysMultiverseShow();
public CmdUsysMultiverseNew cmdUsysMultiverseNew = new CmdUsysMultiverseNew();
public CmdUsysMultiverseDel cmdUsysMultiverseDel = new CmdUsysMultiverseDel();
public CmdUsysMultiverse()
{
super();
this.addAliases("m", "multiverse");
this.addSubCommand(this.cmdUsysMultiverseList);
this.addSubCommand(this.cmdUsysMultiverseShow);
this.addSubCommand(this.cmdUsysMultiverseNew);
this.addSubCommand(this.cmdUsysMultiverseDel);
this.addRequirements(ReqHasPerm.get(Permission.USYS_MULTIVERSE.node));
}
@Override
public void perform()
{
this.getCommandChain().add(this);
HelpCommand.getInstance().execute(this.sender, this.args, this.commandChain);
}
}

View File

@ -0,0 +1,36 @@
package com.massivecraft.mcore4.usys.cmd;
import com.massivecraft.mcore4.Permission;
import com.massivecraft.mcore4.cmd.arg.ARMultiverse;
import com.massivecraft.mcore4.cmd.req.ReqHasPerm;
import com.massivecraft.mcore4.usys.Multiverse;
public class CmdUsysMultiverseDel extends UsysCommand
{
public CmdUsysMultiverseDel()
{
this.addAliases("d", "del");
this.addRequiredArg("multiverse");
this.addRequirements(ReqHasPerm.get(Permission.USYS_MULTIVERSE_DEL.node));
}
@Override
public void perform()
{
Multiverse multiverse = this.arg(0, ARMultiverse.get());
if (multiverse == null) return;
String id = multiverse.getId();
if (id.equals(Multiverse.DEFAULT))
{
msg("<b>You can't delete the default multiverse.");
return;
}
multiverse.detach();
msg("<g>Deleted multiverse <h>%s<g>.", id);
}
}

View File

@ -0,0 +1,48 @@
package com.massivecraft.mcore4.usys.cmd;
import java.util.ArrayList;
import java.util.List;
import com.massivecraft.mcore4.Permission;
import com.massivecraft.mcore4.cmd.arg.ARInteger;
import com.massivecraft.mcore4.cmd.req.ReqHasPerm;
import com.massivecraft.mcore4.usys.Multiverse;
import com.massivecraft.mcore4.usys.MultiverseColl;
import com.massivecraft.mcore4.util.Txt;
public class CmdUsysMultiverseList extends UsysCommand
{
public CmdUsysMultiverseList()
{
this.addAliases("l", "list");
this.addOptionalArg("page", "1");
this.addRequirements(ReqHasPerm.get(Permission.USYS_MULTIVERSE_LIST.node));
}
@Override
public void perform()
{
Integer pageHumanBased = this.arg(0, ARInteger.get(), 1);
if (pageHumanBased == null) return;
// Create Messages
List<String> lines = new ArrayList<String>();
for (Multiverse multiverse : MultiverseColl.i.getAll())
{
if (multiverse.getUniverses().size() > 0)
{
lines.add("<h>"+multiverse.getId()+" <i>has "+Txt.implodeCommaAndDot(multiverse.getUniverses(), "<aqua>%s", "<i>, ", " <i>and ", "<i>."));
}
else
{
lines.add("<h>"+multiverse.getId()+" <i>has no universes.");
}
}
// Send them
lines = Txt.parseWrap(lines);
this.sendMessage(Txt.getPage(lines, pageHumanBased, "Multiverse List"));
}
}

View File

@ -0,0 +1,32 @@
package com.massivecraft.mcore4.usys.cmd;
import com.massivecraft.mcore4.Permission;
import com.massivecraft.mcore4.cmd.req.ReqHasPerm;
import com.massivecraft.mcore4.usys.MultiverseColl;
public class CmdUsysMultiverseNew extends UsysCommand
{
public CmdUsysMultiverseNew()
{
this.addAliases("n", "new");
this.addRequiredArg("multiverse");
this.addRequirements(ReqHasPerm.get(Permission.USYS_MULTIVERSE_NEW.node));
}
@Override
public void perform()
{
String id = this.arg(0);
if (MultiverseColl.i.ids().contains(id))
{
msg("<b>The multiverse <h>%s<b> alread exists.", id);
return;
}
MultiverseColl.i.create(id);
msg("<g>Created multiverse <h>%s<g>.", id);
}
}

View File

@ -0,0 +1,64 @@
package com.massivecraft.mcore4.usys.cmd;
import java.util.ArrayList;
import java.util.List;
import com.massivecraft.mcore4.Permission;
import com.massivecraft.mcore4.cmd.arg.ARMultiverse;
import com.massivecraft.mcore4.cmd.req.ReqHasPerm;
import com.massivecraft.mcore4.usys.Aspect;
import com.massivecraft.mcore4.usys.Multiverse;
import com.massivecraft.mcore4.util.Txt;
public class CmdUsysMultiverseShow extends UsysCommand
{
public CmdUsysMultiverseShow()
{
this.addAliases("s", "show");
this.addRequiredArg("multiverse");
this.addRequirements(ReqHasPerm.get(Permission.USYS_MULTIVERSE_SHOW.node));
}
@Override
public void perform()
{
Multiverse multiverse = this.arg(0, ARMultiverse.get());
if (multiverse == null) return;
msg(Txt.titleize("Multiverse: "+multiverse.getId()));
for (String universe : multiverse.getUniverses())
{
msg("<aqua>"+universe+"<i>: "+Txt.implodeCommaAndDot(multiverse.getWorlds(universe), "<h>%s", "<i>, ", " <i>and ", "<i>."));
}
msg("<aqua>default<i>: for all other worlds.");
msg("");
msg("<i>Aspects using this multiverse:");
this.msgAspects(multiverse.myAspects());
msg("");
msg("<i>Aspects NOT using this multiverse:");
this.msgAspects(multiverse.otherAspects());
}
public void msgAspects(List<Aspect> aspects)
{
List<String> ids = new ArrayList<String>();
for (Aspect aspect : aspects)
{
ids.add(aspect.getId());
}
if (ids.size() == 0)
{
msg("<i>*none*");
}
else
{
msg(Txt.implodeCommaAndDot(ids, "<h>%s", "<i>, ", " <i>and ", "<i>."));
}
}
}

View File

@ -0,0 +1,31 @@
package com.massivecraft.mcore4.usys.cmd;
import com.massivecraft.mcore4.Permission;
import com.massivecraft.mcore4.cmd.HelpCommand;
import com.massivecraft.mcore4.cmd.req.ReqHasPerm;
public class CmdUsysUniverse extends UsysCommand
{
public CmdUsysUniverseNew cmdUsysUniverseNew = new CmdUsysUniverseNew();
public CmdUsysUniverseDel cmdUsysUniverseDel = new CmdUsysUniverseDel();
public CmdUsysUniverseClear cmdUsysUniverseClear = new CmdUsysUniverseClear();
public CmdUsysUniverse()
{
super();
this.addAliases("u", "universe");
this.addSubCommand(this.cmdUsysUniverseNew);
this.addSubCommand(this.cmdUsysUniverseDel);
this.addSubCommand(this.cmdUsysUniverseClear);
this.addRequirements(ReqHasPerm.get(Permission.USYS_UNIVERSE.node));
}
@Override
public void perform()
{
this.getCommandChain().add(this);
HelpCommand.getInstance().execute(this.sender, this.args, this.commandChain);
}
}

View File

@ -0,0 +1,43 @@
package com.massivecraft.mcore4.usys.cmd;
import com.massivecraft.mcore4.Permission;
import com.massivecraft.mcore4.cmd.arg.ARMultiverse;
import com.massivecraft.mcore4.cmd.req.ReqHasPerm;
import com.massivecraft.mcore4.usys.Multiverse;
public class CmdUsysUniverseClear extends UsysCommand
{
public CmdUsysUniverseClear()
{
this.addAliases("c", "clear");
this.addRequiredArg("universe");
this.addRequiredArg("multiverse");
this.addRequirements(ReqHasPerm.get(Permission.USYS_UNIVERSE_CLEAR.node));
}
@Override
public void perform()
{
Multiverse multiverse = this.arg(1, ARMultiverse.get());
if (multiverse == null) return;
String universe = this.arg(0);
if (universe.equals(Multiverse.DEFAULT))
{
msg("<b>You can't clear the default universe.");
msg("<b>It contains the worlds that aren't assigned to a universe.");
return;
}
if (multiverse.clearUniverse(universe))
{
msg("<g>Cleared universe <h>%s<g> in multiverse <h>%s<g>.", universe, multiverse.getId());
}
else
{
msg("<b>No universe <h>%s<b> exists in multiverse <h>%s<b>.", universe, multiverse.getId());
}
}
}

View File

@ -0,0 +1,44 @@
package com.massivecraft.mcore4.usys.cmd;
import com.massivecraft.mcore4.Permission;
import com.massivecraft.mcore4.cmd.arg.ARMultiverse;
import com.massivecraft.mcore4.cmd.req.ReqHasPerm;
import com.massivecraft.mcore4.usys.Multiverse;
public class CmdUsysUniverseDel extends UsysCommand
{
public CmdUsysUniverseDel()
{
this.addAliases("d", "del");
this.addRequiredArg("universe");
this.addRequiredArg("multiverse");
this.addRequirements(ReqHasPerm.get(Permission.USYS_MULTIVERSE_DEL.node));
}
@Override
public void perform()
{
Multiverse multiverse = this.arg(1, ARMultiverse.get());
if (multiverse == null) return;
String universe = this.arg(0);
if (universe.equals(Multiverse.DEFAULT))
{
msg("<b>You can't remove the default universe.");
msg("<b>Each multiverse contains a default universe.");
return;
}
if (!multiverse.containsUniverse(universe))
{
msg("<b>No universe <h>%s<b> exists in multiverse <h>%s<b>.", universe, multiverse.getId());
return;
}
multiverse.delUniverse(universe);
msg("<g>Deleted universe <h>%s<g> in multiverse <h>%s<g>.", universe, multiverse.getId());
}
}

View File

@ -0,0 +1,37 @@
package com.massivecraft.mcore4.usys.cmd;
import com.massivecraft.mcore4.Permission;
import com.massivecraft.mcore4.cmd.arg.ARMultiverse;
import com.massivecraft.mcore4.cmd.req.ReqHasPerm;
import com.massivecraft.mcore4.usys.Multiverse;
public class CmdUsysUniverseNew extends UsysCommand
{
public CmdUsysUniverseNew()
{
this.addAliases("n", "new");
this.addRequiredArg("universe");
this.addRequiredArg("multiverse");
this.addRequirements(ReqHasPerm.get(Permission.USYS_UNIVERSE_NEW.node));
}
@Override
public void perform()
{
Multiverse multiverse = this.arg(1, ARMultiverse.get());
if (multiverse == null) return;
String universe = this.arg(0);
if (multiverse.containsUniverse(universe) || universe.equals(Multiverse.DEFAULT))
{
msg("<b>The universe <h>%s<b> already exists in multiverse <h>%s<b>.", universe, multiverse.getId());
return;
}
multiverse.newUniverse(universe);
msg("<g>Created universe <h>%s<g> in multiverse <h>%s<g>.", universe, multiverse.getId());
}
}

View File

@ -0,0 +1,46 @@
package com.massivecraft.mcore4.usys.cmd;
import com.massivecraft.mcore4.Permission;
import com.massivecraft.mcore4.cmd.arg.ARMultiverse;
import com.massivecraft.mcore4.cmd.req.ReqHasPerm;
import com.massivecraft.mcore4.usys.Multiverse;
public class CmdUsysWorld extends UsysCommand
{
public CmdUsysWorld()
{
this.addAliases("w", "world");
this.addRequiredArg("world");
this.addRequiredArg("universe");
this.addRequiredArg("multiverse");
this.addRequirements(ReqHasPerm.get(Permission.USYS_WORLD.node));
}
@Override
public void perform()
{
Multiverse multiverse = this.arg(2, ARMultiverse.get());
if (multiverse == null) return;
String universe = this.arg(1);
String worldName = this.arg(0);
if (!multiverse.containsUniverse(universe))
{
msg("<b>No universe <h>%s<b> exists in multiverse <h>%s<b>.", universe, multiverse.getId());
return;
}
String universeOld = multiverse.getUniverseForWorldName(worldName);
if (multiverse.setWorldUniverse(worldName, universe))
{
msg("<g>World <h>%s <g>moved from <h>%s <g>to <h>%s <g>universe in multiverse <h>%s<g>.", worldName, universeOld, universe, multiverse.getId());
}
else
{
msg("<i>World <h>%s <i>is already in universe <h>%s <i>in multiverse <h>%s<i>.", worldName, universe, multiverse.getId());
}
}
}

View File

@ -0,0 +1,20 @@
package com.massivecraft.mcore4.usys.cmd;
import com.massivecraft.mcore4.MCore;
import com.massivecraft.mcore4.cmd.MCommand;
public abstract class UsysCommand extends MCommand
{
public MCore p;
public UsysCommand()
{
super();
this.p = MCore.p;
}
@Override
public MCore p()
{
return MCore.p;
}
}

View File

@ -0,0 +1,119 @@
package com.massivecraft.mcore4.util;
import java.lang.reflect.Field;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.plugin.AuthorNagException;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredListener;
public class EventUtil
{
public static Field fieldRegisteredListenerDotPriority;
public static Field fieldRegisteredListenerDotListener;
static
{
try
{
fieldRegisteredListenerDotPriority = RegisteredListener.class.getDeclaredField("priority");
fieldRegisteredListenerDotPriority.setAccessible(true);
fieldRegisteredListenerDotListener = RegisteredListener.class.getDeclaredField("listener");
fieldRegisteredListenerDotListener.setAccessible(true);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void callEventAt(Event event, EventPriority priority)
{
HandlerList handlers = event.getHandlers();
RegisteredListener[] listeners = handlers.getRegisteredListeners().clone();
for (RegisteredListener registration : listeners)
{
try
{
EventPriority thisPriority = (EventPriority) fieldRegisteredListenerDotPriority.get(registration);
if (thisPriority != priority) continue;
}
catch (Exception e)
{
e.printStackTrace();
continue;
}
fireEventRegistration(event, registration);
}
}
public static void callEventAfter(Event event, Listener listener, EventPriority priority)
{
HandlerList handlers = event.getHandlers();
RegisteredListener[] listeners = handlers.getRegisteredListeners().clone();
boolean run = false;
for (RegisteredListener registration : listeners)
{
if (run)
{
fireEventRegistration(event, registration);
}
else
{
try
{
EventPriority thisPriority = (EventPriority) fieldRegisteredListenerDotPriority.get(registration);
Listener thisListener = (Listener) fieldRegisteredListenerDotListener.get(registration);
if (thisListener == listener && thisPriority == priority) run = true;
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
/**
* This is the for-loop part of SimplePluginManager#fireEvent
*/
public static void fireEventRegistration(Event event, RegisteredListener registration)
{
if (!registration.getPlugin().isEnabled()) return;
try
{
registration.callEvent(event);
}
catch (AuthorNagException ex)
{
Plugin plugin = registration.getPlugin();
if (plugin.isNaggable())
{
plugin.setNaggable(false);
String author = "<NoAuthorGiven>";
if (plugin.getDescription().getAuthors().size() > 0)
{
author = plugin.getDescription().getAuthors().get(0);
}
Bukkit.getServer().getLogger().log(Level.SEVERE, String.format("Nag author: '%s' of '%s' about the following: %s", author, plugin.getDescription().getName(), ex.getMessage()));
}
}
catch (Throwable ex)
{
Bukkit.getServer().getLogger().log(Level.SEVERE, "Could not pass event " + event.getEventName() + " to " + registration.getPlugin().getDescription().getName(), ex);
}
}
}

View File

@ -15,16 +15,23 @@ import java.util.SortedSet;
import java.util.TreeSet;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import com.massivecraft.mcore4.InternalListener;
import com.massivecraft.mcore4.MCore;
import com.massivecraft.mcore4.util.extractor.Extractor;
import com.massivecraft.mcore4.util.extractor.ExtractorPlayer;
import com.massivecraft.mcore4.util.extractor.ExtractorPlayerName;
import com.massivecraft.mcore4.util.extractor.ExtractorWorld;
import com.massivecraft.mcore4.util.extractor.ExtractorWorldName;
public class MUtil
@ -99,6 +106,16 @@ public class MUtil
return ret;
}
public static String kickReason(PlayerQuitEvent event)
{
return InternalListener.kickedPlayerReasons.get(event.getPlayer().getName());
}
public static boolean causedByKick(PlayerQuitEvent event)
{
return kickReason(event) != null;
}
// -------------------------------------------- //
// SIMPLE CONSTRUCTORS
// -------------------------------------------- //
@ -226,6 +243,9 @@ public class MUtil
static
{
registerExtractor(World.class, "world", new ExtractorWorld());
registerExtractor(String.class, "worldName", new ExtractorWorldName());
registerExtractor(Player.class, "player", new ExtractorPlayer());
registerExtractor(String.class, "playerName", new ExtractorPlayerName());
}
}

View File

@ -0,0 +1,134 @@
package com.massivecraft.mcore4.util.extractor;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
import org.bukkit.event.entity.EntityEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.painting.PaintingBreakByEntityEvent;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.event.vehicle.VehicleEnterEvent;
import org.bukkit.event.vehicle.VehicleEvent;
import org.bukkit.event.vehicle.VehicleExitEvent;
import com.massivecraft.mcore4.PS;
import com.massivecraft.mcore4.store.PlayerEntity;
public class ExtractorLogic
{
// -------------------------------------------- //
// PLAYER
// -------------------------------------------- //
public static Player player(String o) { return Bukkit.getPlayerExact(o); }
public static Player player(PlayerEvent o) { return o.getPlayer(); }
public static Player player(BlockBreakEvent o) { return o.getPlayer(); }
public static Player player(BlockDamageEvent o) { return o.getPlayer(); }
public static Player player(BlockIgniteEvent o) { return o.getPlayer(); }
public static Player player(BlockPlaceEvent o) { return o.getPlayer(); }
public static Player player(SignChangeEvent o) { return o.getPlayer(); }
public static Player player(EnchantItemEvent o) { return o.getEnchanter(); }
public static Player player(PrepareItemEnchantEvent o) { return o.getEnchanter(); }
public static Player player(Entity o) { if (o instanceof Player) return (Player)o; return null; }
public static Player player(EntityEvent o) { return player(o.getEntity()); }
public static Player player(InventoryClickEvent o) { return player(o.getWhoClicked()); }
public static Player player(InventoryCloseEvent o) { return player(o.getPlayer()); }
public static Player player(InventoryOpenEvent o) { return player(o.getPlayer()); }
public static Player player(PaintingBreakByEntityEvent o) { return player(o.getRemover()); }
public static Player player(VehicleDamageEvent o) { return player(o.getAttacker()); }
public static Player player(VehicleDestroyEvent o) { return player(o.getAttacker()); }
public static Player player(VehicleEnterEvent o) { return player(o.getEntered()); }
public static Player player(VehicleExitEvent o) { return player(o.getExited()); }
public static Player player(VehicleEvent o) { return player(o.getVehicle().getPassenger()); }
public static Player playerFromObject(Object o)
{
if (o instanceof Player) return (Player)o;
if (o instanceof String) return player((String)o);
if (o instanceof PlayerEvent) return player((PlayerEvent)o);
if (o instanceof BlockBreakEvent) return player((BlockBreakEvent)o);
if (o instanceof BlockDamageEvent) return player((BlockDamageEvent)o);
if (o instanceof BlockIgniteEvent) return player((BlockIgniteEvent)o);
if (o instanceof BlockPlaceEvent) return player((BlockPlaceEvent)o);
if (o instanceof SignChangeEvent) return player((SignChangeEvent)o);
if (o instanceof EnchantItemEvent) return player((EnchantItemEvent)o);
if (o instanceof PrepareItemEnchantEvent) return player((PrepareItemEnchantEvent)o);
if (o instanceof Entity) return player((Entity)o);
if (o instanceof EntityEvent) return player((EntityEvent)o);
if (o instanceof InventoryClickEvent) return player((InventoryClickEvent)o);
if (o instanceof InventoryCloseEvent) return player((InventoryCloseEvent)o);
if (o instanceof InventoryOpenEvent) return player((InventoryOpenEvent)o);
if (o instanceof PaintingBreakByEntityEvent) return player((PaintingBreakByEntityEvent)o);
if (o instanceof VehicleDamageEvent) return player((VehicleDamageEvent)o);
if (o instanceof VehicleDestroyEvent) return player((VehicleDestroyEvent)o);
if (o instanceof VehicleEnterEvent) return player((VehicleEnterEvent)o);
if (o instanceof VehicleExitEvent) return player((VehicleExitEvent)o);
if (o instanceof VehicleEvent) return player((VehicleEvent)o);
return null;
}
// -------------------------------------------- //
// PLAYER NAME
// -------------------------------------------- //
public static String playerNameFromObject(Object o)
{
if (o instanceof String) return (String)o;
if (o instanceof PlayerEntity) return ((PlayerEntity<?>)o).getId();
Player player = playerFromObject(o);
if (player == null) return null;
return player.getName();
}
// -------------------------------------------- //
// WORLD
// -------------------------------------------- //
public static World world(Block o) { return o.getWorld(); }
public static World world(Location o) { return o.getWorld(); }
public static World world(Entity o) { return o.getWorld(); }
public static World world(PlayerEvent o) { return world(o.getPlayer()); }
public static World world(PS o) { return o.world(); }
public static World worldFromObject(Object o)
{
if (o instanceof World) return (World)o;
if (o instanceof Block) return world((Block)o);
if (o instanceof Location) return world((Location)o);
if (o instanceof Entity) return world((Entity)o);
if (o instanceof PlayerEvent) return world((PlayerEvent)o);
if (o instanceof PS) return world((PS)o);
return null;
}
// -------------------------------------------- //
// WORLD NAME
// -------------------------------------------- //
public static String worldNameFromObject(Object o)
{
if (o instanceof String) return (String)o;
if (o instanceof PS) return ((PS)o).worldName();
World world = worldFromObject(o);
if (world == null) return null;
return world.getName();
}
}

View File

@ -0,0 +1,10 @@
package com.massivecraft.mcore4.util.extractor;
public class ExtractorPlayer implements Extractor
{
@Override
public Object extract(Object o)
{
return ExtractorLogic.playerFromObject(o);
}
}

View File

@ -0,0 +1,10 @@
package com.massivecraft.mcore4.util.extractor;
public class ExtractorPlayerName implements Extractor
{
@Override
public Object extract(Object o)
{
return ExtractorLogic.playerNameFromObject(o);
}
}

View File

@ -0,0 +1,10 @@
package com.massivecraft.mcore4.util.extractor;
public class ExtractorWorld implements Extractor
{
@Override
public Object extract(Object o)
{
return ExtractorLogic.worldFromObject(o);
}
}

View File

@ -1,22 +1,10 @@
package com.massivecraft.mcore4.util.extractor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.event.player.PlayerEvent;
public class ExtractorWorldName implements Extractor
{
@Override
public Object extract(Object o)
{
if (o instanceof String) return o;
if (o instanceof World) return ((World)o).getName();
if (o instanceof Block) return ((Block)o).getWorld().getName();
if (o instanceof Location) return ((Location)o).getWorld().getName();
if (o instanceof Entity) return ((Entity)o).getWorld().getName();
if (o instanceof PlayerEvent) return ((PlayerEvent)o).getPlayer().getWorld().getName();
return null;
return ExtractorLogic.worldNameFromObject(o);
}
}