diff --git a/src/com/massivecraft/massivecore/MassiveCore.java b/src/com/massivecraft/massivecore/MassiveCore.java index 10d04275..a5f748f5 100644 --- a/src/com/massivecraft/massivecore/MassiveCore.java +++ b/src/com/massivecraft/massivecore/MassiveCore.java @@ -60,6 +60,22 @@ import com.massivecraft.massivecore.engine.EngineMassiveCoreTeleportMixinCause; import com.massivecraft.massivecore.engine.EngineMassiveCoreVariable; import com.massivecraft.massivecore.engine.EngineMassiveCoreWorldNameSet; import com.massivecraft.massivecore.integration.vault.IntegrationVault; +import com.massivecraft.massivecore.mixin.MixinActionbar; +import com.massivecraft.massivecore.mixin.MixinActual; +import com.massivecraft.massivecore.mixin.MixinCommand; +import com.massivecraft.massivecore.mixin.MixinDisplayName; +import com.massivecraft.massivecore.mixin.MixinEvent; +import com.massivecraft.massivecore.mixin.MixinGamemode; +import com.massivecraft.massivecore.mixin.MixinInventory; +import com.massivecraft.massivecore.mixin.MixinKick; +import com.massivecraft.massivecore.mixin.MixinMessage; +import com.massivecraft.massivecore.mixin.MixinModification; +import com.massivecraft.massivecore.mixin.MixinPlayed; +import com.massivecraft.massivecore.mixin.MixinSenderPs; +import com.massivecraft.massivecore.mixin.MixinTeleport; +import com.massivecraft.massivecore.mixin.MixinTitle; +import com.massivecraft.massivecore.mixin.MixinVisibility; +import com.massivecraft.massivecore.mixin.MixinWorld; import com.massivecraft.massivecore.mson.Mson; import com.massivecraft.massivecore.mson.MsonEvent; import com.massivecraft.massivecore.ps.PS; @@ -220,7 +236,25 @@ public class MassiveCore extends MassivePlugin CmdMassiveCoreStore.get(), CmdMassiveCoreBuffer.get(), CmdMassiveCoreCmdurl.get(), - CmdMassiveCoreClick.get() + CmdMassiveCoreClick.get(), + + // Mixin + MixinEvent.get(), // NOTE: Should be first + MixinActionbar.get(), + MixinActual.get(), + MixinCommand.get(), + MixinDisplayName.get(), + MixinGamemode.get(), + MixinInventory.get(), + MixinKick.get(), + MixinMessage.get(), + MixinModification.get(), + MixinPlayed.get(), + MixinSenderPs.get(), + MixinTeleport.get(), + MixinTitle.get(), + MixinVisibility.get(), + MixinWorld.get() ); // Start the examine threads diff --git a/src/com/massivecraft/massivecore/mixin/ActionbarMixin.java b/src/com/massivecraft/massivecore/mixin/ActionbarMixin.java deleted file mode 100644 index 6a827f9c..00000000 --- a/src/com/massivecraft/massivecore/mixin/ActionbarMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -import com.massivecraft.massivecore.mson.Mson; - -public interface ActionbarMixin -{ - // Abstract - public boolean sendActionbarMessage(Object watcherObject, String message); - - // Parsed - public boolean sendActionbarMsg(Object watcherObject, String message); - - // Mson - public boolean sendActionbarMson(Object watcherObject, Mson mson); - - // Available - public boolean isActionbarAvailable(); - -} diff --git a/src/com/massivecraft/massivecore/mixin/ActionbarMixinAbstract.java b/src/com/massivecraft/massivecore/mixin/ActionbarMixinAbstract.java deleted file mode 100644 index fda51d05..00000000 --- a/src/com/massivecraft/massivecore/mixin/ActionbarMixinAbstract.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -import com.massivecraft.massivecore.util.Txt; - -public abstract class ActionbarMixinAbstract implements ActionbarMixin -{ - // Parsed - @Override - public boolean sendActionbarMsg(Object watcherObject, String message) - { - return this.sendActionbarMessage(watcherObject, Txt.parse(message)); - } -} diff --git a/src/com/massivecraft/massivecore/mixin/ActualMixin.java b/src/com/massivecraft/massivecore/mixin/ActualMixin.java deleted file mode 100644 index f451f1f7..00000000 --- a/src/com/massivecraft/massivecore/mixin/ActualMixin.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -import org.bukkit.event.player.PlayerJoinEvent; - -import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave; - -public interface ActualMixin -{ - public boolean isActualJoin(PlayerJoinEvent event); - public boolean isActualLeave(EventMassiveCorePlayerLeave event); -} diff --git a/src/com/massivecraft/massivecore/mixin/ActualMixinAbstract.java b/src/com/massivecraft/massivecore/mixin/ActualMixinAbstract.java deleted file mode 100644 index 7b638e4d..00000000 --- a/src/com/massivecraft/massivecore/mixin/ActualMixinAbstract.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -public abstract class ActualMixinAbstract implements ActualMixin -{ - -} diff --git a/src/com/massivecraft/massivecore/mixin/CommandMixin.java b/src/com/massivecraft/massivecore/mixin/CommandMixin.java deleted file mode 100644 index 1018d0f7..00000000 --- a/src/com/massivecraft/massivecore/mixin/CommandMixin.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -public interface CommandMixin -{ - public boolean dispatchCommand(Object senderObject, String commandLine); - public boolean dispatchCommand(Object presentObject, Object senderObject, String commandLine); // This one is non-abstract - -} diff --git a/src/com/massivecraft/massivecore/mixin/CommandMixinAbstract.java b/src/com/massivecraft/massivecore/mixin/CommandMixinAbstract.java deleted file mode 100644 index e63dca3e..00000000 --- a/src/com/massivecraft/massivecore/mixin/CommandMixinAbstract.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -public abstract class CommandMixinAbstract implements CommandMixin -{ - @Override - public boolean dispatchCommand(Object senderObject, String commandLine) - { - return this.dispatchCommand(senderObject, senderObject, commandLine); - } -} diff --git a/src/com/massivecraft/massivecore/mixin/DisplayNameMixin.java b/src/com/massivecraft/massivecore/mixin/DisplayNameMixin.java deleted file mode 100644 index 21c6f7aa..00000000 --- a/src/com/massivecraft/massivecore/mixin/DisplayNameMixin.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -import com.massivecraft.massivecore.mson.Mson; - -public interface DisplayNameMixin -{ - public Mson getDisplayNameMson(Object senderObject, Object watcherObject); - public String getDisplayName(Object senderObject, Object watcherObject); -} diff --git a/src/com/massivecraft/massivecore/mixin/DisplayNameMixinAbstract.java b/src/com/massivecraft/massivecore/mixin/DisplayNameMixinAbstract.java deleted file mode 100644 index 3cb702d3..00000000 --- a/src/com/massivecraft/massivecore/mixin/DisplayNameMixinAbstract.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -import com.massivecraft.massivecore.mson.Mson; - -public abstract class DisplayNameMixinAbstract implements DisplayNameMixin -{ - public Mson getDisplayNameMson(Object senderObject, Object watcherObject) - { - String displayName = this.getDisplayName(senderObject, watcherObject); - if (displayName == null) return null; - return Mson.fromParsedMessage(displayName); - } -} diff --git a/src/com/massivecraft/massivecore/mixin/GamemodeMixin.java b/src/com/massivecraft/massivecore/mixin/GamemodeMixin.java deleted file mode 100644 index f0179ce9..00000000 --- a/src/com/massivecraft/massivecore/mixin/GamemodeMixin.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -import org.bukkit.GameMode; - -public interface GamemodeMixin -{ - public GameMode getGamemode(Object playerObject); - public void setGamemode(Object playerObject, GameMode gm); -} diff --git a/src/com/massivecraft/massivecore/mixin/GamemodeMixinAbstract.java b/src/com/massivecraft/massivecore/mixin/GamemodeMixinAbstract.java deleted file mode 100644 index cebc016e..00000000 --- a/src/com/massivecraft/massivecore/mixin/GamemodeMixinAbstract.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -public abstract class GamemodeMixinAbstract implements GamemodeMixin -{ - -} diff --git a/src/com/massivecraft/massivecore/mixin/InventoryMixin.java b/src/com/massivecraft/massivecore/mixin/InventoryMixin.java deleted file mode 100644 index dcc5e2ea..00000000 --- a/src/com/massivecraft/massivecore/mixin/InventoryMixin.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.PlayerInventory; - -public interface InventoryMixin -{ - // Create a Player Inventory without a Player - public PlayerInventory createPlayerInventory(); - - // Create an arbitrary size standard chest-like inventory - public Inventory createInventory(InventoryHolder holder, int size, String title); -} diff --git a/src/com/massivecraft/massivecore/mixin/InventoryMixinAbstract.java b/src/com/massivecraft/massivecore/mixin/InventoryMixinAbstract.java deleted file mode 100644 index ed824da0..00000000 --- a/src/com/massivecraft/massivecore/mixin/InventoryMixinAbstract.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -public abstract class InventoryMixinAbstract implements InventoryMixin -{ - -} diff --git a/src/com/massivecraft/massivecore/mixin/KickMixin.java b/src/com/massivecraft/massivecore/mixin/KickMixin.java deleted file mode 100644 index 0c69f6b2..00000000 --- a/src/com/massivecraft/massivecore/mixin/KickMixin.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -public interface KickMixin -{ - public boolean kick(Object senderObject); - public boolean kick(Object senderObject, String message); -} diff --git a/src/com/massivecraft/massivecore/mixin/KickMixinAbstract.java b/src/com/massivecraft/massivecore/mixin/KickMixinAbstract.java deleted file mode 100644 index 5680054f..00000000 --- a/src/com/massivecraft/massivecore/mixin/KickMixinAbstract.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -public abstract class KickMixinAbstract implements KickMixin -{ - @Override - public boolean kick(Object senderObject) - { - return this.kick(senderObject, null); - } -} diff --git a/src/com/massivecraft/massivecore/mixin/MessageMixin.java b/src/com/massivecraft/massivecore/mixin/MessageMixin.java deleted file mode 100644 index 4012cb75..00000000 --- a/src/com/massivecraft/massivecore/mixin/MessageMixin.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -import java.util.Collection; - -import org.bukkit.command.CommandSender; - -import com.massivecraft.massivecore.predicate.Predicate; - -public interface MessageMixin -{ - // -------------------------------------------- // - // MSG - // -------------------------------------------- // - // All implemented in abstract! - - // All - public boolean msgAll(String msg); - public boolean msgAll(String msg, Object... args); - public boolean msgAll(Collection msgs); - - // Predicate - public boolean msgPredicate(Predicate predicate, String msg); - public boolean msgPredicate(Predicate predicate, String msg, Object... args); - public boolean msgPredicate(Predicate predicate, Collection msgs); - - // One - public boolean msgOne(Object sendeeObject, String msg); - public boolean msgOne(Object sendeeObject, String msg, Object... args); - public boolean msgOne(Object sendeeObject, Collection msgs); - - // -------------------------------------------- // - // MESSAGE - // -------------------------------------------- // - - // All - public boolean messageAll(Object message); - public boolean messageAll(Object... messages); - public boolean messageAll(Collection messages); - - // Predicate - public boolean messagePredicate(Predicate predicate, Object message); - public boolean messagePredicate(Predicate predicate, Object... messages); - public boolean messagePredicate(Predicate predicate, Collection messages); - - // One - public boolean messageOne(Object sendeeObject, Object message); - public boolean messageOne(Object sendeeObject, Object... messages); - public boolean messageOne(Object sendeeObject, Collection messages); - -} diff --git a/src/com/massivecraft/massivecore/mixin/MessageMixinAbstract.java b/src/com/massivecraft/massivecore/mixin/MessageMixinAbstract.java deleted file mode 100644 index 3b5b4613..00000000 --- a/src/com/massivecraft/massivecore/mixin/MessageMixinAbstract.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - -import org.bukkit.command.CommandSender; - -import com.massivecraft.massivecore.predicate.Predicate; -import com.massivecraft.massivecore.util.Txt; - -public abstract class MessageMixinAbstract implements MessageMixin -{ - // -------------------------------------------- // - // MSG STRING - // -------------------------------------------- // - // All implemented in abstract! - - // All - @Override - public boolean msgAll(String msg) - { - return this.messageAll(Txt.parse(msg)); - } - - @Override - public boolean msgAll(String msg, Object... args) - { - return this.messageAll(Txt.parse(msg, args)); - } - - @Override - public boolean msgAll(Collection msgs) - { - return this.messageAll(Txt.parse(msgs)); - } - - // Predicate - @Override - public boolean msgPredicate(Predicate predicate, String msg) - { - return this.messagePredicate(predicate, Txt.parse(msg)); - } - - @Override - public boolean msgPredicate(Predicate predicate, String msg, Object... args) - { - return this.messagePredicate(predicate, Txt.parse(msg, args)); - } - - @Override - public boolean msgPredicate(Predicate predicate, Collection msgs) - { - return this.messagePredicate(predicate, Txt.parse(msgs)); - } - - // One - @Override - public boolean msgOne(Object sendeeObject, String msg) - { - return this.messageOne(sendeeObject, Txt.parse(msg)); - } - - @Override - public boolean msgOne(Object sendeeObject, String msg, Object... args) - { - return this.messageOne(sendeeObject, Txt.parse(msg, args)); - } - - @Override - public boolean msgOne(Object sendeeObject, Collection msgs) - { - return this.messageOne(sendeeObject, Txt.parse(msgs)); - } - - // -------------------------------------------- // - // MESSAGE - // -------------------------------------------- // - - // All - @Override - public boolean messageAll(Object message) - { - return this.messageAll(asCollection(message)); - } - - @Override - public boolean messageAll(Object... messages) - { - return this.messageAll(asCollection(messages)); - } - - // Predicate - @Override - public boolean messagePredicate(Predicate predicate, Object message) - { - return this.messagePredicate(predicate, asCollection(message)); - } - - @Override - public boolean messagePredicate(Predicate predicate, Object... messages) - { - return this.messagePredicate(predicate, asCollection(messages)); - } - - // One - @Override - public boolean messageOne(Object sendeeObject, Object message) - { - return this.messageOne(sendeeObject, asCollection(message)); - } - - @Override - public boolean messageOne(Object sendeeObject, Object... messages) - { - return this.messageOne(sendeeObject, asCollection(messages)); - } - - // -------------------------------------------- // - // UTIL - // -------------------------------------------- // - - public Collection asCollection(Object message) - { - if (message instanceof Collection) return (Collection) message; - if (message instanceof Object[]) return Arrays.asList((Object[]) message); - return Collections.singleton(message); - } - -} diff --git a/src/com/massivecraft/massivecore/mixin/MessageMixinDefault.java b/src/com/massivecraft/massivecore/mixin/MessageMixinDefault.java deleted file mode 100644 index 6c7c37b2..00000000 --- a/src/com/massivecraft/massivecore/mixin/MessageMixinDefault.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -import java.util.Collection; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import com.massivecraft.massivecore.mson.Mson; -import com.massivecraft.massivecore.nms.NmsPacket; -import com.massivecraft.massivecore.predicate.Predicate; -import com.massivecraft.massivecore.util.IdUtil; - -public class MessageMixinDefault extends MessageMixinAbstract -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static MessageMixinDefault i = new MessageMixinDefault(); - public static MessageMixinDefault get() { return i; } - - // -------------------------------------------- // - // MESSAGE - // -------------------------------------------- // - - // All - // NOTE: Targets messageOne - @Override - public boolean messageAll(Collection messages) - { - // Check Messages - if (messages == null) return false; - if (messages.isEmpty()) return false; - - // Here - for (CommandSender sender : IdUtil.getLocalSenders()) - { - this.messageOne(sender, messages); - } - - // Return - return true; - } - - // Predicate - // NOTE: Targets messageOne - @Override - public boolean messagePredicate(Predicate predicate, Collection messages) - { - // Check Predicate - if (predicate == null) return false; - - // Check Messages - if (messages == null) return false; - if (messages.isEmpty()) return false; - - // Here - for (CommandSender sender : IdUtil.getLocalSenders()) - { - if (!predicate.apply(sender)) continue; - this.messageOne(sender, messages); - } - - // Return - return true; - } - - // One - // NOTE: The core implementation - @Override - public boolean messageOne(Object sendeeObject, Collection messages) - { - // Check Sendee - CommandSender sendee = IdUtil.getSender(sendeeObject); - if (sendee == null) return false; - - // Check Messages - if (messages == null) return false; - if (messages.isEmpty()) return false; - - // For each Message - for (Object message : messages) - { - if (message instanceof String) - { - String string = (String)message; - sendee.sendMessage(string); - } - else if (message instanceof Mson) - { - Mson mson = (Mson)message; - if (sendee instanceof Player && NmsPacket.get().isAvailable()) - { - Player player = (Player) sendee; - NmsPacket.sendRaw(player, mson.toRaw()); - } - else - { - sendee.sendMessage(mson.toPlain(true)); - } - } - else - { - String desc = (message == null ? "null" : message.getClass().getSimpleName()); - throw new IllegalArgumentException(desc + " is neither String nor Mson."); - } - } - return true; - } - -} diff --git a/src/com/massivecraft/massivecore/mixin/Mixin.java b/src/com/massivecraft/massivecore/mixin/Mixin.java index 16d66d78..b00cc945 100644 --- a/src/com/massivecraft/massivecore/mixin/Mixin.java +++ b/src/com/massivecraft/massivecore/mixin/Mixin.java @@ -23,122 +23,58 @@ import com.massivecraft.massivecore.teleport.Destination; public class Mixin { - // -------------------------------------------- // - // GET/SET MIXINS - // -------------------------------------------- // - - private static WorldMixin worldMixin = WorldMixinDefault.get(); - public static WorldMixin getWorldMixin() { return worldMixin; } - public static void setWorldMixin(WorldMixin val) { worldMixin = val; } - - private static DisplayNameMixin displayNameMixin = DisplayNameMixinDefault.get(); - public static DisplayNameMixin getDisplayNameMixin() { return displayNameMixin; } - public static void setDisplayNameMixin(DisplayNameMixin val) { displayNameMixin = val; } - - private static InventoryMixin inventoryMixin = InventoryMixinDefault.get(); - public static InventoryMixin getInventoryMixin() { return inventoryMixin; } - public static void setInventoryMixin(InventoryMixin val) { inventoryMixin = val; } - - private static SenderPsMixin senderPsMixin = SenderPsMixinDefault.get(); - public static SenderPsMixin getSenderPsMixin() { return senderPsMixin; } - public static void setSenderPsMixin(SenderPsMixin val) { senderPsMixin = val; } - - private static GamemodeMixin gamemodeMixin = GamemodeMixinDefault.get(); - public static GamemodeMixin getGamemodeMixin() { return gamemodeMixin; } - public static void setGamemodeMixin(GamemodeMixin val) { gamemodeMixin = val; } - - private static PlayedMixin playedMixin = PlayedMixinDefault.get(); - public static PlayedMixin getPlayedMixin() { return playedMixin; } - public static void setPlayedMixin(PlayedMixin val) { playedMixin = val; } - - private static VisibilityMixin visibilityMixin = VisibilityMixinDefault.get(); - public static VisibilityMixin getVisibilityMixin() { return visibilityMixin; } - public static void setVisibilityMixin(VisibilityMixin val) { visibilityMixin = val; } - - private static TeleportMixin teleportMixin = TeleportMixinDefault.get(); - public static TeleportMixin getTeleportMixin() { return teleportMixin; } - public static void setTeleportMixin(TeleportMixin val) { teleportMixin = val; } - - private static MessageMixin messageMixin = MessageMixinDefault.get(); - public static MessageMixin getMessageMixin() { return messageMixin; } - public static void setMessageMixin(MessageMixin val) { messageMixin = val; } - - private static ActionbarMixin actionbarMixin = ActionbarMixinDefault.get(); - public static ActionbarMixin getActionbarMixin() { return actionbarMixin; } - public static void setActionbarMixin(ActionbarMixin val) { actionbarMixin = val; } - - private static TitleMixin titleMixin = TitleMixinDefault.get(); - public static TitleMixin getTitleMixin() { return titleMixin; } - public static void setTitleMixin(TitleMixin val) { titleMixin = val; } - - private static KickMixin kickMixin = KickMixinDefault.get(); - public static KickMixin getKickMixin() { return kickMixin; } - public static void setKickMixin(KickMixin val) { kickMixin = val; } - - private static ActualMixin actualMixin = ActualMixinDefault.get(); - public static ActualMixin getActualMixin() { return actualMixin; } - public static void setActualMixin(ActualMixin val) { actualMixin = val; } - - private static CommandMixin commandMixin = CommandMixinDefault.get(); - public static CommandMixin getCommandMixin() { return commandMixin; } - public static void setCommandMixin(CommandMixin val) { commandMixin = val; } - - private static ModificationMixin modificationMixin = ModificationMixinDefault.get(); - public static ModificationMixin getModificationMixin() { return modificationMixin; } - public static void setModificationMixin(ModificationMixin val) { modificationMixin = val; } - // -------------------------------------------- // // STATIC EXPOSE: WORLD // -------------------------------------------- // public static boolean canSeeWorld(Permissible permissible, String worldId) { - return getWorldMixin().canSeeWorld(permissible, worldId); + return MixinWorld.get().canSeeWorld(permissible, worldId); } public static List getWorldIds() { - return getWorldMixin().getWorldIds(); + return MixinWorld.get().getWorldIds(); } public static List getVisibleWorldIds(Permissible permissible) { - return getWorldMixin().getVisibleWorldIds(permissible); + return MixinWorld.get().getVisibleWorldIds(permissible); } public static ChatColor getWorldColor(String worldId) { - return getWorldMixin().getWorldColor(worldId); + return MixinWorld.get().getWorldColor(worldId); } public static List getWorldAliases(String worldId) { - return getWorldMixin().getWorldAliases(worldId); + return MixinWorld.get().getWorldAliases(worldId); } public static String getWorldAliasOrId(String worldId) { - return getWorldMixin().getWorldAliasOrId(worldId); + return MixinWorld.get().getWorldAliasOrId(worldId); } public static String getWorldDisplayName(String worldId) { - return getWorldMixin().getWorldDisplayName(worldId); + return MixinWorld.get().getWorldDisplayName(worldId); } public static PS getWorldSpawnPs(String worldId) { - return getWorldMixin().getWorldSpawnPs(worldId); + return MixinWorld.get().getWorldSpawnPs(worldId); } public static void setWorldSpawnPs(String worldId, PS spawnPs) { - getWorldMixin().setWorldSpawnPs(worldId, spawnPs); + MixinWorld.get().setWorldSpawnPs(worldId, spawnPs); } public static boolean trySetWorldSpawnWp(CommandSender sender, String worldId, PS spawnPs, boolean verbooseChange, boolean verbooseSame) { - return getWorldMixin().trySetWorldSpawnWp(sender, worldId, spawnPs, verbooseChange, verbooseSame); + return MixinWorld.get().trySetWorldSpawnWp(sender, worldId, spawnPs, verbooseChange, verbooseSame); } // -------------------------------------------- // @@ -148,17 +84,17 @@ public class Mixin @Deprecated public static String getDisplayName(Object senderObject) { - return getDisplayNameMixin().getDisplayName(senderObject, null); + return MixinDisplayName.get().getDisplayName(senderObject, null); } public static String getDisplayName(Object senderObject, Object watcherObject) { - return getDisplayNameMixin().getDisplayName(senderObject, watcherObject); + return MixinDisplayName.get().getDisplayName(senderObject, watcherObject); } public static Mson getDisplayNameMson(Object senderObject, Object watcherObject) { - return getDisplayNameMixin().getDisplayNameMson(senderObject, watcherObject); + return MixinDisplayName.get().getDisplayNameMson(senderObject, watcherObject); } // -------------------------------------------- // @@ -167,12 +103,12 @@ public class Mixin public static PlayerInventory createPlayerInventory() { - return getInventoryMixin().createPlayerInventory(); + return MixinInventory.get().createPlayerInventory(); } public static Inventory createInventory(InventoryHolder holder, int size, String title) { - return getInventoryMixin().createInventory(holder, size, title); + return MixinInventory.get().createInventory(holder, size, title); } // -------------------------------------------- // @@ -181,12 +117,12 @@ public class Mixin public static PS getSenderPs(Object senderObject) { - return getSenderPsMixin().getSenderPs(senderObject); + return MixinSenderPs.get().getSenderPs(senderObject); } public static void setSenderPs(Object senderObject, PS ps) { - getSenderPsMixin().setSenderPs(senderObject, ps); + MixinSenderPs.get().setSenderPs(senderObject, ps); } // -------------------------------------------- // @@ -195,12 +131,12 @@ public class Mixin public static GameMode getGamemode(Object playerObject) { - return getGamemodeMixin().getGamemode(playerObject); + return MixinGamemode.get().getGamemode(playerObject); } - public static void setGamemode(Object playerObject, GameMode gm) + public static void setGamemode(Object playerObject, GameMode gameMode) { - getGamemodeMixin().setGamemode(playerObject, gm); + MixinGamemode.get().setGamemode(playerObject, gameMode); } // -------------------------------------------- // @@ -209,27 +145,27 @@ public class Mixin public static boolean isOnline(Object senderObject) { - return getPlayedMixin().isOnline(senderObject); + return MixinPlayed.get().isOnline(senderObject); } public static boolean isOffline(Object senderObject) { - return getPlayedMixin().isOffline(senderObject); + return MixinPlayed.get().isOffline(senderObject); } public static Long getLastPlayed(Object senderObject) { - return getPlayedMixin().getLastPlayed(senderObject); + return MixinPlayed.get().getLastPlayed(senderObject); } public static Long getFirstPlayed(Object senderObject) { - return getPlayedMixin().getFirstPlayed(senderObject); + return MixinPlayed.get().getFirstPlayed(senderObject); } public static boolean hasPlayedBefore(Object senderObject) { - return getPlayedMixin().hasPlayedBefore(senderObject); + return MixinPlayed.get().hasPlayedBefore(senderObject); } public static String getIp(Object senderObject) { - return getPlayedMixin().getIp(senderObject); + return MixinPlayed.get().getIp(senderObject); } // -------------------------------------------- // @@ -238,11 +174,11 @@ public class Mixin public static boolean isVisible(Object watcheeObject) { - return getVisibilityMixin().isVisible(watcheeObject); + return MixinVisibility.get().isVisible(watcheeObject); } public static boolean isVisible(Object watcheeObject, Object watcherObject) { - return getVisibilityMixin().isVisible(watcheeObject, watcherObject); + return MixinVisibility.get().isVisible(watcheeObject, watcherObject); } // -------------------------------------------- // @@ -251,20 +187,20 @@ public class Mixin public static boolean isCausedByMixin(PlayerTeleportEvent event) { - return getTeleportMixin().isCausedByMixin(event); + return MixinTeleport.get().isCausedByMixin(event); } public static void teleport(Object teleporteeObject, Destination destination) throws TeleporterException { - getTeleportMixin().teleport(teleporteeObject, destination); + MixinTeleport.get().teleport(teleporteeObject, destination); } public static void teleport(Object teleporteeObject, Destination destination, Permissible delayPermissible) throws TeleporterException { - getTeleportMixin().teleport(teleporteeObject, destination, delayPermissible); + MixinTeleport.get().teleport(teleporteeObject, destination, delayPermissible); } public static void teleport(Object teleporteeObject, Destination destination, int delaySeconds) throws TeleporterException { - getTeleportMixin().teleport(teleporteeObject, destination, delaySeconds); + MixinTeleport.get().teleport(teleporteeObject, destination, delaySeconds); } // -------------------------------------------- // @@ -274,147 +210,140 @@ public class Mixin // MSG: All public static boolean msgAll(String msg) { - return getMessageMixin().msgAll(msg); + return MixinMessage.get().msgAll(msg); } public static boolean msgAll(String msg, Object... args) { - return getMessageMixin().msgAll(msg, args); + return MixinMessage.get().msgAll(msg, args); } public static boolean msgAll(Collection msgs) { - return getMessageMixin().msgAll(msgs); + return MixinMessage.get().msgAll(msgs); } // MSG: Predicate public static boolean msgPredicate(Predicate predicate, String msg) { - return getMessageMixin().msgPredicate(predicate, msg); + return MixinMessage.get().msgPredicate(predicate, msg); } public static boolean msgPredicate(Predicate predicate, String msg, Object... args) { - return getMessageMixin().msgPredicate(predicate, msg, args); + return MixinMessage.get().msgPredicate(predicate, msg, args); } public static boolean msgPredicate(Predicate predicate, Collection msgs) { - return getMessageMixin().msgPredicate(predicate, msgs); + return MixinMessage.get().msgPredicate(predicate, msgs); } // MSG: One public static boolean msgOne(Object sendeeObject, String msg) { - return getMessageMixin().msgOne(sendeeObject, msg); + return MixinMessage.get().msgOne(sendeeObject, msg); } public static boolean msgOne(Object sendeeObject, String msg, Object... args) { - return getMessageMixin().msgOne(sendeeObject, msg, args); + return MixinMessage.get().msgOne(sendeeObject, msg, args); } public static boolean msgOne(Object sendeeObject, Collection msgs) { - return getMessageMixin().msgOne(sendeeObject, msgs); + return MixinMessage.get().msgOne(sendeeObject, msgs); } // MESSAGE: All public static boolean messageAll(Object message) { - return getMessageMixin().messageAll(message); + return MixinMessage.get().messageAll(message); } public static boolean messageAll(Object... messages) { - return getMessageMixin().messageAll(messages); + return MixinMessage.get().messageAll(messages); } public static boolean messageAll(Collection messages) { - return getMessageMixin().messageAll(messages); + return MixinMessage.get().messageAll(messages); } // MESSAGE: Predicate public static boolean messagePredicate(Predicate predicate, Object message) { - return getMessageMixin().messagePredicate(predicate, message); + return MixinMessage.get().messagePredicate(predicate, message); } public static boolean messagePredicate(Predicate predicate, Object... messages) { - return getMessageMixin().messagePredicate(predicate, messages); + return MixinMessage.get().messagePredicate(predicate, messages); } public static boolean messagePredicate(Predicate predicate, Collection messages) { - return getMessageMixin().messagePredicate(predicate, messages); + return MixinMessage.get().messagePredicate(predicate, messages); } // MESSAGE: One public static boolean messageOne(Object sendeeObject, Object message) { - return getMessageMixin().messageOne(sendeeObject, message); + return MixinMessage.get().messageOne(sendeeObject, message); } public static boolean messageOne(Object sendeeObject, Object... messages) { - return getMessageMixin().messageOne(sendeeObject, messages); + return MixinMessage.get().messageOne(sendeeObject, messages); } public static boolean messageOne(Object sendeeObject, Collection messages) { - return getMessageMixin().messageOne(sendeeObject, messages); + return MixinMessage.get().messageOne(sendeeObject, messages); } // -------------------------------------------- // // STATIC EXPOSE: ACTIONBAR // -------------------------------------------- // - // Default public static boolean sendActionbarMessage(Object sendeeObject, String message) { - return getActionbarMixin().sendActionbarMessage(sendeeObject, message); + return MixinActionbar.get().sendActionbarMessage(sendeeObject, message); } - // Parsed public static boolean sendActionbarMsg(Object sendeeObject, String message) { - return getActionbarMixin().sendActionbarMsg(sendeeObject, message); + return MixinActionbar.get().sendActionbarMsg(sendeeObject, message); } - // Mson public static boolean sendActionbarMson(Object sendeeObject, Mson mson) { - return getActionbarMixin().sendActionbarMson(sendeeObject, mson); + return MixinActionbar.get().sendActionbarMson(sendeeObject, mson); } - // Available public static boolean isActionbarAvailable() { - return getActionbarMixin().isActionbarAvailable(); + return MixinActionbar.get().isActionbarAvailable(); } // -------------------------------------------- // // STATIC EXPOSE: TITLE // -------------------------------------------- // - // Default public static boolean sendTitleMessage(Object watcherObject, int ticksIn, int ticksStay, int ticksOut, String titleMain, String titleSub) { - return getTitleMixin().sendTitleMessage(watcherObject, ticksIn, ticksStay, ticksOut, titleMain, titleSub); + return MixinTitle.get().sendTitleMessage(watcherObject, ticksIn, ticksStay, ticksOut, titleMain, titleSub); } - // Parsed public static boolean sendTitleMsg(Object watcherObject, int ticksIn, int ticksStay, int ticksOut, String titleMain, String titleSub) { - return getTitleMixin().sendTitleMsg(watcherObject, ticksIn, ticksStay, ticksOut, titleMain, titleSub); + return MixinTitle.get().sendTitleMsg(watcherObject, ticksIn, ticksStay, ticksOut, titleMain, titleSub); } - // Available public static boolean isTitlesAvailable() { - return getTitleMixin().isTitlesAvailable(); + return MixinTitle.get().isTitlesAvailable(); } // -------------------------------------------- // @@ -423,12 +352,12 @@ public class Mixin public static boolean kick(Object senderObject) { - return getKickMixin().kick(senderObject); + return MixinKick.get().kick(senderObject); } public static boolean kick(Object senderObject, String message) { - return getKickMixin().kick(senderObject, message); + return MixinKick.get().kick(senderObject, message); } // -------------------------------------------- // @@ -437,12 +366,12 @@ public class Mixin public static boolean isActualJoin(PlayerJoinEvent event) { - return getActualMixin().isActualJoin(event); + return MixinActual.get().isActualJoin(event); } public static boolean isActualLeave(EventMassiveCorePlayerLeave event) { - return getActualMixin().isActualLeave(event); + return MixinActual.get().isActualLeave(event); } // -------------------------------------------- // @@ -451,12 +380,12 @@ public class Mixin public static boolean dispatchCommand(Object senderObject, String commandLine) { - return getCommandMixin().dispatchCommand(senderObject, commandLine); + return MixinCommand.get().dispatchCommand(senderObject, commandLine); } public static boolean dispatchCommand(Object presentObject, Object senderObject, String commandLine) { - return getCommandMixin().dispatchCommand(presentObject, senderObject, commandLine); + return MixinCommand.get().dispatchCommand(presentObject, senderObject, commandLine); } // -------------------------------------------- // @@ -465,12 +394,12 @@ public class Mixin public static void syncModification(Entity entity) { - getModificationMixin().syncModification(entity); + MixinModification.get().syncModification(entity); } public static void syncModification(Coll coll, String id) { - getModificationMixin().syncModification(coll, id); + MixinModification.get().syncModification(coll, id); } } diff --git a/src/com/massivecraft/massivecore/mixin/MixinAbstract.java b/src/com/massivecraft/massivecore/mixin/MixinAbstract.java new file mode 100644 index 00000000..06037e0f --- /dev/null +++ b/src/com/massivecraft/massivecore/mixin/MixinAbstract.java @@ -0,0 +1,39 @@ +package com.massivecraft.massivecore.mixin; + +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.util.ReflectionUtil; + +public class MixinAbstract extends Engine +{ + // -------------------------------------------- // + // STATIC REFLECTION + // -------------------------------------------- // + + private Class clazz = ReflectionUtil.getSuperclassDeclaringField(this.getClass(), true, "d"); + public MixinAbstract getDefault() { return ReflectionUtil.getField(this.clazz, "d", null); } + public MixinAbstract getInstance() { return ReflectionUtil.getField(this.clazz, "i", null); } + public void setInstance(MixinAbstract i) { ReflectionUtil.setField(this.clazz, "i", null, i); } + + // -------------------------------------------- // + // ACTIVE + // -------------------------------------------- // + + @Override + public boolean isActive() + { + return this.getInstance() == this; + } + + @Override + public void setActive(boolean active) + { + this.setActiveMixin(active); + super.setActive(active); + } + + public void setActiveMixin(boolean active) + { + this.setInstance(active ? this : this.getDefault()); + } + +} diff --git a/src/com/massivecraft/massivecore/mixin/ActionbarMixinDefault.java b/src/com/massivecraft/massivecore/mixin/MixinActionbar.java similarity index 70% rename from src/com/massivecraft/massivecore/mixin/ActionbarMixinDefault.java rename to src/com/massivecraft/massivecore/mixin/MixinActionbar.java index d0b32168..5b19878f 100644 --- a/src/com/massivecraft/massivecore/mixin/ActionbarMixinDefault.java +++ b/src/com/massivecraft/massivecore/mixin/MixinActionbar.java @@ -1,25 +1,26 @@ package com.massivecraft.massivecore.mixin; import org.bukkit.entity.Player; - import com.massivecraft.massivecore.mson.Mson; import com.massivecraft.massivecore.nms.NmsPacket; import com.massivecraft.massivecore.util.IdUtil; +import com.massivecraft.massivecore.util.Txt; -public class ActionbarMixinDefault extends ActionbarMixinAbstract +public class MixinActionbar extends MixinAbstract { // -------------------------------------------- // // INSTANCE & CONSTRUCT // -------------------------------------------- // - - private static ActionbarMixinDefault i = new ActionbarMixinDefault(); - public static ActionbarMixinDefault get() { return i; } - + + private static MixinActionbar d = new MixinActionbar(); + private static MixinActionbar i = d; + public static MixinActionbar get() { return i; } + public static void set(MixinActionbar i) { MixinActionbar.i = i; } + // -------------------------------------------- // - // OVERRIDE + // METHODS // -------------------------------------------- // - - @Override + public boolean sendActionbarMessage(Object watcherObject, String message) { // Get the player @@ -31,7 +32,11 @@ public class ActionbarMixinDefault extends ActionbarMixinAbstract return NmsPacket.sendActionbar(player, message); } - @Override + public boolean sendActionbarMsg(Object watcherObject, String message) + { + return this.sendActionbarMessage(watcherObject, Txt.parse(message)); + } + public boolean sendActionbarMson(Object watcherObject, Mson mson) { // Get the player @@ -44,7 +49,6 @@ public class ActionbarMixinDefault extends ActionbarMixinAbstract return NmsPacket.sendActionbar(player, message); } - @Override public boolean isActionbarAvailable() { return NmsPacket.get().isAvailable(); diff --git a/src/com/massivecraft/massivecore/mixin/ActualMixinDefault.java b/src/com/massivecraft/massivecore/mixin/MixinActual.java similarity index 68% rename from src/com/massivecraft/massivecore/mixin/ActualMixinDefault.java rename to src/com/massivecraft/massivecore/mixin/MixinActual.java index 86daced8..bf777ed4 100644 --- a/src/com/massivecraft/massivecore/mixin/ActualMixinDefault.java +++ b/src/com/massivecraft/massivecore/mixin/MixinActual.java @@ -1,32 +1,32 @@ -package com.massivecraft.massivecore.mixin; - -import org.bukkit.event.player.PlayerJoinEvent; - -import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave; - -public class ActualMixinDefault extends ActualMixinAbstract -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static ActualMixinDefault i = new ActualMixinDefault(); - public static ActualMixinDefault get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean isActualJoin(PlayerJoinEvent event) - { - return true; - } - - @Override - public boolean isActualLeave(EventMassiveCorePlayerLeave event) - { - return true; - } - -} \ No newline at end of file +package com.massivecraft.massivecore.mixin; + +import org.bukkit.event.player.PlayerJoinEvent; + +import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave; + +public class MixinActual extends MixinAbstract +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MixinActual d = new MixinActual(); + private static MixinActual i = d; + public static MixinActual get() { return i; } + public static void set(MixinActual i) { MixinActual.i = i; } + + // -------------------------------------------- // + // METHODS + // -------------------------------------------- // + + public boolean isActualJoin(PlayerJoinEvent event) + { + return true; + } + + public boolean isActualLeave(EventMassiveCorePlayerLeave event) + { + return true; + } + +} diff --git a/src/com/massivecraft/massivecore/mixin/CommandMixinDefault.java b/src/com/massivecraft/massivecore/mixin/MixinCommand.java similarity index 68% rename from src/com/massivecraft/massivecore/mixin/CommandMixinDefault.java rename to src/com/massivecraft/massivecore/mixin/MixinCommand.java index 6ecdf846..d085132f 100644 --- a/src/com/massivecraft/massivecore/mixin/CommandMixinDefault.java +++ b/src/com/massivecraft/massivecore/mixin/MixinCommand.java @@ -1,37 +1,42 @@ -package com.massivecraft.massivecore.mixin; - -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; - -import com.massivecraft.massivecore.util.IdUtil; - -public class CommandMixinDefault extends CommandMixinAbstract -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static CommandMixinDefault i = new CommandMixinDefault(); - public static CommandMixinDefault get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean dispatchCommand(Object presentObject, Object senderObject, String commandLine) - { - // Additional enforced presence - CommandSender present = IdUtil.getSender(presentObject); - if (present == null) return false; - - // We must then of course have the presence of the sender - CommandSender sender = IdUtil.getSender(senderObject); - if (sender == null) return false; - - // Great! Let's do it! - Bukkit.getServer().dispatchCommand(sender, commandLine); - return true; - } - -} +package com.massivecraft.massivecore.mixin; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import com.massivecraft.massivecore.util.IdUtil; + +public class MixinCommand extends MixinAbstract +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MixinCommand d = new MixinCommand(); + private static MixinCommand i = d; + public static MixinCommand get() { return i; } + public static void set(MixinCommand i) { MixinCommand.i = i; } + + // -------------------------------------------- // + // METHODS + // -------------------------------------------- // + + public boolean dispatchCommand(Object senderObject, String commandLine) + { + return this.dispatchCommand(senderObject, senderObject, commandLine); + } + + public boolean dispatchCommand(Object presentObject, Object senderObject, String commandLine) + { + // Additional enforced presence + CommandSender present = IdUtil.getSender(presentObject); + if (present == null) return false; + + // We must then of course have the presence of the sender + CommandSender sender = IdUtil.getSender(senderObject); + if (sender == null) return false; + + // Great! Let's do it! + Bukkit.getServer().dispatchCommand(sender, commandLine); + return true; + } + +} diff --git a/src/com/massivecraft/massivecore/mixin/DisplayNameMixinDefault.java b/src/com/massivecraft/massivecore/mixin/MixinDisplayName.java similarity index 65% rename from src/com/massivecraft/massivecore/mixin/DisplayNameMixinDefault.java rename to src/com/massivecraft/massivecore/mixin/MixinDisplayName.java index 2aeeacfb..b1d6a255 100644 --- a/src/com/massivecraft/massivecore/mixin/DisplayNameMixinDefault.java +++ b/src/com/massivecraft/massivecore/mixin/MixinDisplayName.java @@ -1,63 +1,71 @@ -package com.massivecraft.massivecore.mixin; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import com.massivecraft.massivecore.util.IdUtil; - -public class DisplayNameMixinDefault extends DisplayNameMixinAbstract -{ - public final static ChatColor DEFAULT_COLOR = ChatColor.WHITE; - - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static DisplayNameMixinDefault i = new DisplayNameMixinDefault(); - public static DisplayNameMixinDefault get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getDisplayName(Object senderObject, Object watcherObject) - { - String senderId = IdUtil.getId(senderObject); - if (senderId == null) return null; - - // Ret - String ret = null; - - // Bukkit - if (ret == null) - { - Player player = IdUtil.getPlayer(senderObject); - if (player != null) - { - ret = player.getDisplayName(); - } - } - - // Fixed Name - if (ret == null) - { - ret = IdUtil.getName(senderObject); - } - - // Id Fallback - if (ret == null) - { - ret = senderId; - } - - // Ensure Colored - if (ChatColor.stripColor(ret).equals(ret)) - { - ret = DEFAULT_COLOR.toString() + ret; - } - - return ret; - } - -} +package com.massivecraft.massivecore.mixin; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import com.massivecraft.massivecore.mson.Mson; +import com.massivecraft.massivecore.util.IdUtil; + +public class MixinDisplayName extends MixinAbstract +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MixinDisplayName d = new MixinDisplayName(); + private static MixinDisplayName i = d; + public static MixinDisplayName get() { return i; } + public static void set(MixinDisplayName i) { MixinDisplayName.i = i; } + + // -------------------------------------------- // + // METHODS + // -------------------------------------------- // + + public final static ChatColor DEFAULT_COLOR = ChatColor.WHITE; + + public Mson getDisplayNameMson(Object senderObject, Object watcherObject) + { + String displayName = this.getDisplayName(senderObject, watcherObject); + if (displayName == null) return null; + return Mson.fromParsedMessage(displayName); + } + + public String getDisplayName(Object senderObject, Object watcherObject) + { + String senderId = IdUtil.getId(senderObject); + if (senderId == null) return null; + + // Ret + String ret = null; + + // Bukkit + if (ret == null) + { + Player player = IdUtil.getPlayer(senderObject); + if (player != null) + { + ret = player.getDisplayName(); + } + } + + // Fixed Name + if (ret == null) + { + ret = IdUtil.getName(senderObject); + } + + // Id Fallback + if (ret == null) + { + ret = senderId; + } + + // Ensure Colored + if (ChatColor.stripColor(ret).equals(ret)) + { + ret = DEFAULT_COLOR.toString() + ret; + } + + return ret; + } + +} diff --git a/src/com/massivecraft/massivecore/mixin/MixinEvent.java b/src/com/massivecraft/massivecore/mixin/MixinEvent.java new file mode 100644 index 00000000..f7ea1f91 --- /dev/null +++ b/src/com/massivecraft/massivecore/mixin/MixinEvent.java @@ -0,0 +1,44 @@ +package com.massivecraft.massivecore.mixin; + +import java.io.Serializable; + +import org.bukkit.Bukkit; +import org.bukkit.event.Event; + +public class MixinEvent extends MixinAbstract +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MixinEvent d = new MixinEvent(); + private static MixinEvent i = d; + public static MixinEvent get() { return i; } + public static void set(MixinEvent i) { MixinEvent.i = i; } + + // -------------------------------------------- // + // METHODS + // -------------------------------------------- // + + public void distribute(E event) + { + this.distribute(event, false); + } + + public void distribute(E event, boolean includeSelf) + { + this.distributeOthers(event); + if (includeSelf) this.distributeSelf(event); + } + + protected void distributeSelf(E event) + { + Bukkit.getPluginManager().callEvent(event); + } + + protected void distributeOthers(E event) + { + // NOTE: This is where the event would be sent to all other servers in the network. + } + +} diff --git a/src/com/massivecraft/massivecore/mixin/GamemodeMixinDefault.java b/src/com/massivecraft/massivecore/mixin/MixinGamemode.java similarity index 64% rename from src/com/massivecraft/massivecore/mixin/GamemodeMixinDefault.java rename to src/com/massivecraft/massivecore/mixin/MixinGamemode.java index 0035b494..8b1eb4b6 100644 --- a/src/com/massivecraft/massivecore/mixin/GamemodeMixinDefault.java +++ b/src/com/massivecraft/massivecore/mixin/MixinGamemode.java @@ -5,20 +5,21 @@ import org.bukkit.entity.Player; import com.massivecraft.massivecore.util.IdUtil; -public class GamemodeMixinDefault extends GamemodeMixinAbstract +public class MixinGamemode extends MixinAbstract { // -------------------------------------------- // // INSTANCE & CONSTRUCT // -------------------------------------------- // - private static GamemodeMixinDefault i = new GamemodeMixinDefault(); - public static GamemodeMixinDefault get() { return i; } - + private static MixinGamemode d = new MixinGamemode(); + private static MixinGamemode i = d; + public static MixinGamemode get() { return i; } + public static void set(MixinGamemode i) { MixinGamemode.i = i; } + // -------------------------------------------- // - // OVERRIDE + // METHODS // -------------------------------------------- // - @Override public GameMode getGamemode(Object playerObject) { Player player = IdUtil.getPlayer(playerObject); @@ -27,13 +28,12 @@ public class GamemodeMixinDefault extends GamemodeMixinAbstract return player.getGameMode(); } - @Override - public void setGamemode(Object playerObject, GameMode gm) + public void setGamemode(Object playerObject, GameMode gameMode) { Player player = IdUtil.getPlayer(playerObject); if (player == null) return; - player.setGameMode(gm); + player.setGameMode(gameMode); } } diff --git a/src/com/massivecraft/massivecore/mixin/InventoryMixinDefault.java b/src/com/massivecraft/massivecore/mixin/MixinInventory.java similarity index 72% rename from src/com/massivecraft/massivecore/mixin/InventoryMixinDefault.java rename to src/com/massivecraft/massivecore/mixin/MixinInventory.java index cac7d5ca..a8669c9e 100644 --- a/src/com/massivecraft/massivecore/mixin/InventoryMixinDefault.java +++ b/src/com/massivecraft/massivecore/mixin/MixinInventory.java @@ -1,35 +1,35 @@ -package com.massivecraft.massivecore.mixin; - -import org.bukkit.Bukkit; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.PlayerInventory; - -import com.massivecraft.massivecore.nms.NmsInventory; - -public class InventoryMixinDefault extends InventoryMixinAbstract -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static InventoryMixinDefault i = new InventoryMixinDefault(); - public static InventoryMixinDefault get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public PlayerInventory createPlayerInventory() - { - return NmsInventory.createPlayerInventory(); - } - - @Override - public Inventory createInventory(InventoryHolder holder, int size, String title) - { - return Bukkit.createInventory(holder, size, title); - } - -} +package com.massivecraft.massivecore.mixin; + +import org.bukkit.Bukkit; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.PlayerInventory; + +import com.massivecraft.massivecore.nms.NmsInventory; + +public class MixinInventory extends MixinAbstract +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MixinInventory d = new MixinInventory(); + private static MixinInventory i = d; + public static MixinInventory get() { return i; } + public static void set(MixinInventory i) { MixinInventory.i = i; } + + // -------------------------------------------- // + // METHODS + // -------------------------------------------- // + + public PlayerInventory createPlayerInventory() + { + return NmsInventory.createPlayerInventory(); + } + + public Inventory createInventory(InventoryHolder holder, int size, String title) + { + return Bukkit.createInventory(holder, size, title); + } + +} diff --git a/src/com/massivecraft/massivecore/mixin/KickMixinDefault.java b/src/com/massivecraft/massivecore/mixin/MixinKick.java similarity index 63% rename from src/com/massivecraft/massivecore/mixin/KickMixinDefault.java rename to src/com/massivecraft/massivecore/mixin/MixinKick.java index 20ad6f6a..4b1ef662 100644 --- a/src/com/massivecraft/massivecore/mixin/KickMixinDefault.java +++ b/src/com/massivecraft/massivecore/mixin/MixinKick.java @@ -1,29 +1,35 @@ -package com.massivecraft.massivecore.mixin; - -import org.bukkit.entity.Player; - -import com.massivecraft.massivecore.util.IdUtil; - -public class KickMixinDefault extends KickMixinAbstract -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static KickMixinDefault i = new KickMixinDefault(); - public static KickMixinDefault get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean kick(Object senderObject, String message) - { - Player player = IdUtil.getPlayer(senderObject); - if (player == null) return false; - player.kickPlayer(message); - return true; - } - -} +package com.massivecraft.massivecore.mixin; + +import org.bukkit.entity.Player; + +import com.massivecraft.massivecore.util.IdUtil; + +public class MixinKick extends MixinAbstract +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MixinKick d = new MixinKick(); + private static MixinKick i = d; + public static MixinKick get() { return i; } + public static void set(MixinKick i) { MixinKick.i = i; } + + // -------------------------------------------- // + // METHODS + // -------------------------------------------- // + + public boolean kick(Object senderObject) + { + return this.kick(senderObject, null); + } + + public boolean kick(Object senderObject, String message) + { + Player player = IdUtil.getPlayer(senderObject); + if (player == null) return false; + player.kickPlayer(message); + return true; + } + +} diff --git a/src/com/massivecraft/massivecore/mixin/MixinMessage.java b/src/com/massivecraft/massivecore/mixin/MixinMessage.java new file mode 100644 index 00000000..0482b4d7 --- /dev/null +++ b/src/com/massivecraft/massivecore/mixin/MixinMessage.java @@ -0,0 +1,213 @@ +package com.massivecraft.massivecore.mixin; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.massivecraft.massivecore.mson.Mson; +import com.massivecraft.massivecore.nms.NmsPacket; +import com.massivecraft.massivecore.predicate.Predicate; +import com.massivecraft.massivecore.util.IdUtil; +import com.massivecraft.massivecore.util.Txt; + +public class MixinMessage extends MixinAbstract +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MixinMessage d = new MixinMessage(); + private static MixinMessage i = d; + public static MixinMessage get() { return i; } + public static void set(MixinMessage i) { MixinMessage.i = i; } + + // -------------------------------------------- // + // MSG > ALL + // -------------------------------------------- // + + public boolean msgAll(String msg) + { + return this.messageAll(Txt.parse(msg)); + } + + public boolean msgAll(String msg, Object... args) + { + return this.messageAll(Txt.parse(msg, args)); + } + + public boolean msgAll(Collection msgs) + { + return this.messageAll(Txt.parse(msgs)); + } + + // -------------------------------------------- // + // MSG > PREDICATE + // -------------------------------------------- // + + public boolean msgPredicate(Predicate predicate, String msg) + { + return this.messagePredicate(predicate, Txt.parse(msg)); + } + + public boolean msgPredicate(Predicate predicate, String msg, Object... args) + { + return this.messagePredicate(predicate, Txt.parse(msg, args)); + } + + public boolean msgPredicate(Predicate predicate, Collection msgs) + { + return this.messagePredicate(predicate, Txt.parse(msgs)); + } + + // -------------------------------------------- // + // MSG > ONE + // -------------------------------------------- // + + public boolean msgOne(Object sendeeObject, String msg) + { + return this.messageOne(sendeeObject, Txt.parse(msg)); + } + + public boolean msgOne(Object sendeeObject, String msg, Object... args) + { + return this.messageOne(sendeeObject, Txt.parse(msg, args)); + } + + public boolean msgOne(Object sendeeObject, Collection msgs) + { + return this.messageOne(sendeeObject, Txt.parse(msgs)); + } + + // -------------------------------------------- // + // MESSAGE > ALL + // -------------------------------------------- // + + public boolean messageAll(Object message) + { + return this.messageAll(asCollection(message)); + } + + public boolean messageAll(Object... messages) + { + return this.messageAll(asCollection(messages)); + } + + public boolean messageAll(Collection messages) + { + // Check Messages + if (messages == null) return false; + if (messages.isEmpty()) return false; + + // Here + for (CommandSender sender : IdUtil.getLocalSenders()) + { + this.messageOne(sender, messages); + } + + // Return + return true; + } + + // -------------------------------------------- // + // MESSAGE > PREDICATE + // -------------------------------------------- // + + public boolean messagePredicate(Predicate predicate, Object message) + { + return this.messagePredicate(predicate, asCollection(message)); + } + + public boolean messagePredicate(Predicate predicate, Object... messages) + { + return this.messagePredicate(predicate, asCollection(messages)); + } + + public boolean messagePredicate(Predicate predicate, Collection messages) + { + // Check Predicate + if (predicate == null) return false; + + // Check Messages + if (messages == null) return false; + if (messages.isEmpty()) return false; + + // Here + for (CommandSender sender : IdUtil.getLocalSenders()) + { + if ( ! predicate.apply(sender)) continue; + this.messageOne(sender, messages); + } + + // Return + return true; + } + + // -------------------------------------------- // + // MESSAGE > ONE + // -------------------------------------------- // + + public boolean messageOne(Object sendeeObject, Object message) + { + return this.messageOne(sendeeObject, asCollection(message)); + } + + public boolean messageOne(Object sendeeObject, Object... messages) + { + return this.messageOne(sendeeObject, asCollection(messages)); + } + + public boolean messageOne(Object sendeeObject, Collection messages) + { + // Check Sendee + CommandSender sendee = IdUtil.getSender(sendeeObject); + if (sendee == null) return false; + + // Check Messages + if (messages == null) return false; + if (messages.isEmpty()) return false; + + // For each Message + for (Object message : messages) + { + if (message instanceof String) + { + String string = (String)message; + sendee.sendMessage(string); + } + else if (message instanceof Mson) + { + Mson mson = (Mson)message; + if (sendee instanceof Player && NmsPacket.get().isAvailable()) + { + Player player = (Player) sendee; + NmsPacket.sendRaw(player, mson.toRaw()); + } + else + { + sendee.sendMessage(mson.toPlain(true)); + } + } + else + { + String desc = (message == null ? "null" : message.getClass().getSimpleName()); + throw new IllegalArgumentException(desc + " is neither String nor Mson."); + } + } + return true; + } + + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + + public Collection asCollection(Object message) + { + if (message instanceof Collection) return (Collection) message; + if (message instanceof Object[]) return Arrays.asList((Object[]) message); + return Collections.singleton(message); + } + +} diff --git a/src/com/massivecraft/massivecore/mixin/MixinModification.java b/src/com/massivecraft/massivecore/mixin/MixinModification.java new file mode 100644 index 00000000..c45e4d0e --- /dev/null +++ b/src/com/massivecraft/massivecore/mixin/MixinModification.java @@ -0,0 +1,31 @@ +package com.massivecraft.massivecore.mixin; + +import com.massivecraft.massivecore.store.Coll; +import com.massivecraft.massivecore.store.Entity; + +public class MixinModification extends MixinAbstract +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MixinModification d = new MixinModification(); + private static MixinModification i = d; + public static MixinModification get() { return i; } + public static void set(MixinModification i) { MixinModification.i = i; } + + // -------------------------------------------- // + // METHODS + // -------------------------------------------- // + + public void syncModification(Entity entity) + { + this.syncModification(entity.getColl(), entity.getId()); + } + + public void syncModification(Coll coll, String id) + { + // Nothing to do here + } + +} diff --git a/src/com/massivecraft/massivecore/mixin/PlayedMixinDefault.java b/src/com/massivecraft/massivecore/mixin/MixinPlayed.java similarity index 73% rename from src/com/massivecraft/massivecore/mixin/PlayedMixinDefault.java rename to src/com/massivecraft/massivecore/mixin/MixinPlayed.java index 48f131f4..5a7baa23 100644 --- a/src/com/massivecraft/massivecore/mixin/PlayedMixinDefault.java +++ b/src/com/massivecraft/massivecore/mixin/MixinPlayed.java @@ -1,69 +1,84 @@ -package com.massivecraft.massivecore.mixin; - -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.CommandSender; - -import com.massivecraft.massivecore.util.IdUtil; -import com.massivecraft.massivecore.util.MUtil; - -public class PlayedMixinDefault extends PlayedMixinAbstract -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static PlayedMixinDefault i = new PlayedMixinDefault(); - public static PlayedMixinDefault get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Long getFirstPlayed(Object senderObject) - { - if (MUtil.isNpc(senderObject)) return null; - - UUID uuid = IdUtil.getUuid(senderObject); - if (uuid == null) return null; - OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid); - if (offlinePlayer == null) return null; - - Long ret = offlinePlayer.getFirstPlayed(); - if (ret == 0) ret = null; - - return ret; - } - - @Override - public Long getLastPlayed(Object senderObject) - { - //if (this.isOnline(senderObject)) return System.currentTimeMillis(); - // We do in fact NOT want this commented out behavior - // It's important we can check the previous played time on join! - - if (MUtil.isNpc(senderObject)) return null; - - UUID uuid = IdUtil.getUuid(senderObject); - if (uuid == null) return null; - OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid); - if (offlinePlayer == null) return null; - - Long ret = offlinePlayer.getLastPlayed(); - if (ret == 0) ret = null; - - return ret; - } - - @Override - public String getIp(Object senderObject) - { - CommandSender sender = IdUtil.getSender(senderObject); - if (MUtil.isntPlayer(senderObject)) return null; - return MUtil.getIp(sender); - } - -} +package com.massivecraft.massivecore.mixin; + +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; + +import com.massivecraft.massivecore.util.IdUtil; +import com.massivecraft.massivecore.util.MUtil; + +public class MixinPlayed extends MixinAbstract +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MixinPlayed d = new MixinPlayed(); + private static MixinPlayed i = d; + public static MixinPlayed get() { return i; } + public static void set(MixinPlayed i) { MixinPlayed.i = i; } + + // -------------------------------------------- // + // METHODS + // -------------------------------------------- // + + public boolean isOnline(Object senderObject) + { + return IdUtil.isOnline(senderObject); + } + + public boolean isOffline(Object senderObject) + { + return ! this.isOnline(senderObject); + } + + public Long getFirstPlayed(Object senderObject) + { + if (MUtil.isNpc(senderObject)) return null; + + UUID uuid = IdUtil.getUuid(senderObject); + if (uuid == null) return null; + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid); + if (offlinePlayer == null) return null; + + Long ret = offlinePlayer.getFirstPlayed(); + if (ret == 0) ret = null; + + return ret; + } + + public Long getLastPlayed(Object senderObject) + { + //if (this.isOnline(senderObject)) return System.currentTimeMillis(); + // We do in fact NOT want this commented out behavior + // It's important we can check the previous played time on join! + + if (MUtil.isNpc(senderObject)) return null; + + UUID uuid = IdUtil.getUuid(senderObject); + if (uuid == null) return null; + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid); + if (offlinePlayer == null) return null; + + Long ret = offlinePlayer.getLastPlayed(); + if (ret == 0) ret = null; + + return ret; + } + + public boolean hasPlayedBefore(Object senderObject) + { + Long firstPlayed = this.getFirstPlayed(senderObject); + return firstPlayed != null && firstPlayed != 0; + } + + public String getIp(Object senderObject) + { + CommandSender sender = IdUtil.getSender(senderObject); + if (MUtil.isntPlayer(senderObject)) return null; + return MUtil.getIp(sender); + } + +} diff --git a/src/com/massivecraft/massivecore/mixin/SenderPsMixinDefault.java b/src/com/massivecraft/massivecore/mixin/MixinSenderPs.java similarity index 73% rename from src/com/massivecraft/massivecore/mixin/SenderPsMixinDefault.java rename to src/com/massivecraft/massivecore/mixin/MixinSenderPs.java index 78d41756..bfd2ef5d 100644 --- a/src/com/massivecraft/massivecore/mixin/SenderPsMixinDefault.java +++ b/src/com/massivecraft/massivecore/mixin/MixinSenderPs.java @@ -1,34 +1,35 @@ -package com.massivecraft.massivecore.mixin; - -import org.bukkit.entity.Player; - -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.IdUtil; - -public class SenderPsMixinDefault extends SenderPsMixinAbstract -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static SenderPsMixinDefault i = new SenderPsMixinDefault(); - public static SenderPsMixinDefault get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public PS getSenderPs(Object senderObject) - { - Player player = IdUtil.getPlayer(senderObject); - if (player == null) return null; - return PS.valueOf(player.getLocation()); - } - - @Override - public void setSenderPs(Object senderObject, PS ps) - { - // Bukkit does not support setting the physical state for offline players for now. - } -} +package com.massivecraft.massivecore.mixin; + +import org.bukkit.entity.Player; + +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.IdUtil; + +public class MixinSenderPs extends MixinAbstract +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MixinSenderPs d = new MixinSenderPs(); + private static MixinSenderPs i = d; + public static MixinSenderPs get() { return i; } + public static void set(MixinSenderPs i) { MixinSenderPs.i = i; } + + // -------------------------------------------- // + // METHODS + // -------------------------------------------- // + + public PS getSenderPs(Object senderObject) + { + Player player = IdUtil.getPlayer(senderObject); + if (player == null) return null; + return PS.valueOf(player.getLocation()); + } + + public void setSenderPs(Object senderObject, PS ps) + { + // Bukkit does not support setting the physical state for offline players for now. + } + +} diff --git a/src/com/massivecraft/massivecore/mixin/TeleportMixinDefault.java b/src/com/massivecraft/massivecore/mixin/MixinTeleport.java similarity index 76% rename from src/com/massivecraft/massivecore/mixin/TeleportMixinDefault.java rename to src/com/massivecraft/massivecore/mixin/MixinTeleport.java index 2d83ec84..5004efa0 100644 --- a/src/com/massivecraft/massivecore/mixin/TeleportMixinDefault.java +++ b/src/com/massivecraft/massivecore/mixin/MixinTeleport.java @@ -1,133 +1,157 @@ -package com.massivecraft.massivecore.mixin; - -import org.bukkit.Location; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -import com.massivecraft.massivecore.engine.EngineMassiveCoreTeleportMixinCause; -import com.massivecraft.massivecore.event.EventMassiveCorePlayerPSTeleport; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.teleport.Destination; -import com.massivecraft.massivecore.teleport.ScheduledTeleport; -import com.massivecraft.massivecore.util.IdUtil; -import com.massivecraft.massivecore.util.Txt; - -public class TeleportMixinDefault extends TeleportMixinAbstract -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TeleportMixinDefault i = new TeleportMixinDefault(); - public static TeleportMixinDefault get() { return i; } - - // -------------------------------------------- // - // CORE LOGIC - // -------------------------------------------- // - - public static void teleportPlayer(Player player, PS ps) throws TeleporterException - { - // Base the PS location on the entity location - ps = ps.getEntity(true); - ps = PS.valueOf(player.getLocation()).with(ps); - - // Bukkit Location - Location location = null; - try - { - location = ps.asBukkitLocation(); - - } - catch (Exception e) - { - throw new TeleporterException(Txt.parse("Could not calculate the location: %s", e.getMessage())); - } - - // eject passengers and unmount before transport - player.eject(); - Entity vehicle = player.getVehicle(); - if (vehicle != null) vehicle.eject(); - - // Do the teleport - EngineMassiveCoreTeleportMixinCause.get().setMixinCausedTeleportIncoming(true); - player.teleport(location); - EngineMassiveCoreTeleportMixinCause.get().setMixinCausedTeleportIncoming(false); - - // Bukkit velocity - Vector velocity = null; - try - { - velocity = ps.asBukkitVelocity(); - } - catch (Exception e) - { - return; - } - player.setVelocity(velocity); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void teleport(Object teleporteeObject, Destination destination, int delaySeconds) throws TeleporterException - { - String teleporteeId = IdUtil.getId(teleporteeObject); - if (!IdUtil.isPlayerId(teleporteeId)) throw new TeleporterException(Txt.parse("%s is not a player.", Mixin.getDisplayName(teleporteeId, IdUtil.getConsole()))); - - PS ps; - try - { - ps = destination.getPs(teleporteeId); - } - catch (Exception e) - { - throw new TeleporterException(e.getMessage()); - } - - String desc = destination.getDesc(teleporteeId); - if (delaySeconds > 0) - { - // With delay - if (desc != null && ! desc.isEmpty()) - { - Mixin.msgOne(teleporteeId, "Teleporting to "+desc+" in "+delaySeconds+"s unless you move."); - } - else - { - Mixin.msgOne(teleporteeId, "Teleporting in "+delaySeconds+"s unless you move."); - } - - new ScheduledTeleport(teleporteeId, destination, delaySeconds).schedule(); - } - else - { - // Without delay AKA "now"/"at once" - - // Run event - EventMassiveCorePlayerPSTeleport event = new EventMassiveCorePlayerPSTeleport(teleporteeId, Mixin.getSenderPs(teleporteeId), destination); - event.run(); - if (event.isCancelled()) return; - destination = event.getDestination(); - desc = destination.getDesc(teleporteeId); - - if (desc != null && ! desc.isEmpty()) - { - Mixin.msgOne(teleporteeId, "Teleporting to "+desc+"."); - } - - Player teleportee = IdUtil.getPlayer(teleporteeId); - if (teleportee != null) - { - teleportPlayer(teleportee, ps); - } - else - { - Mixin.setSenderPs(teleporteeId, ps); - } - } - } - -} +package com.massivecraft.massivecore.mixin; + +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.permissions.Permissible; +import org.bukkit.util.Vector; + +import com.massivecraft.massivecore.MassiveCoreMConf; +import com.massivecraft.massivecore.engine.EngineMassiveCoreTeleportMixinCause; +import com.massivecraft.massivecore.event.EventMassiveCorePlayerPSTeleport; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.teleport.Destination; +import com.massivecraft.massivecore.teleport.ScheduledTeleport; +import com.massivecraft.massivecore.util.IdUtil; +import com.massivecraft.massivecore.util.Txt; + +public class MixinTeleport extends MixinAbstract +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MixinTeleport d = new MixinTeleport(); + private static MixinTeleport i = d; + public static MixinTeleport get() { return i; } + public static void set(MixinTeleport i) { MixinTeleport.i = i; } + + // -------------------------------------------- // + // METHODS + // -------------------------------------------- // + + public boolean isCausedByMixin(PlayerTeleportEvent event) + { + return EngineMassiveCoreTeleportMixinCause.get().isCausedByTeleportMixin(event); + } + + public void teleport(Object teleportee, Destination destination) throws TeleporterException + { + this.teleport(teleportee, destination, 0); + } + + public void teleport(Object teleportee, Destination destination, Permissible delayPermissible) throws TeleporterException + { + int delaySeconds = MassiveCoreMConf.get().getTpdelay(delayPermissible); + this.teleport(teleportee, destination, delaySeconds); + } + + // -------------------------------------------- // + // CORE LOGIC + // -------------------------------------------- // + + public static void teleportPlayer(Player player, PS ps) throws TeleporterException + { + // Base the PS location on the entity location + ps = ps.getEntity(true); + ps = PS.valueOf(player.getLocation()).with(ps); + + // Bukkit Location + Location location = null; + try + { + location = ps.asBukkitLocation(); + + } + catch (Exception e) + { + throw new TeleporterException(Txt.parse("Could not calculate the location: %s", e.getMessage())); + } + + // eject passengers and unmount before transport + player.eject(); + Entity vehicle = player.getVehicle(); + if (vehicle != null) vehicle.eject(); + + // Do the teleport + EngineMassiveCoreTeleportMixinCause.get().setMixinCausedTeleportIncoming(true); + player.teleport(location); + EngineMassiveCoreTeleportMixinCause.get().setMixinCausedTeleportIncoming(false); + + // Bukkit velocity + Vector velocity = null; + try + { + velocity = ps.asBukkitVelocity(); + } + catch (Exception e) + { + return; + } + player.setVelocity(velocity); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + public void teleport(Object teleporteeObject, Destination destination, int delaySeconds) throws TeleporterException + { + String teleporteeId = IdUtil.getId(teleporteeObject); + if (!IdUtil.isPlayerId(teleporteeId)) throw new TeleporterException(Txt.parse("%s is not a player.", Mixin.getDisplayName(teleporteeId, IdUtil.getConsole()))); + + PS ps; + try + { + ps = destination.getPs(teleporteeId); + } + catch (Exception e) + { + throw new TeleporterException(e.getMessage()); + } + + String desc = destination.getDesc(teleporteeId); + if (delaySeconds > 0) + { + // With delay + if (desc != null && ! desc.isEmpty()) + { + Mixin.msgOne(teleporteeId, "Teleporting to "+desc+" in "+delaySeconds+"s unless you move."); + } + else + { + Mixin.msgOne(teleporteeId, "Teleporting in "+delaySeconds+"s unless you move."); + } + + new ScheduledTeleport(teleporteeId, destination, delaySeconds).schedule(); + } + else + { + // Without delay AKA "now"/"at once" + + // Run event + EventMassiveCorePlayerPSTeleport event = new EventMassiveCorePlayerPSTeleport(teleporteeId, Mixin.getSenderPs(teleporteeId), destination); + event.run(); + if (event.isCancelled()) return; + destination = event.getDestination(); + desc = destination.getDesc(teleporteeId); + + if (desc != null && ! desc.isEmpty()) + { + Mixin.msgOne(teleporteeId, "Teleporting to "+desc+"."); + } + + Player teleportee = IdUtil.getPlayer(teleporteeId); + if (teleportee != null) + { + teleportPlayer(teleportee, ps); + } + else + { + Mixin.setSenderPs(teleporteeId, ps); + } + } + } + +} diff --git a/src/com/massivecraft/massivecore/mixin/TitleMixinDefault.java b/src/com/massivecraft/massivecore/mixin/MixinTitle.java similarity index 58% rename from src/com/massivecraft/massivecore/mixin/TitleMixinDefault.java rename to src/com/massivecraft/massivecore/mixin/MixinTitle.java index 1bd526de..bba5397d 100644 --- a/src/com/massivecraft/massivecore/mixin/TitleMixinDefault.java +++ b/src/com/massivecraft/massivecore/mixin/MixinTitle.java @@ -4,21 +4,23 @@ import org.bukkit.entity.Player; import com.massivecraft.massivecore.nms.NmsPacket; import com.massivecraft.massivecore.util.IdUtil; +import com.massivecraft.massivecore.util.Txt; -public class TitleMixinDefault extends TitleMixinAbstract +public class MixinTitle extends MixinAbstract { // -------------------------------------------- // // INSTANCE & CONSTRUCT // -------------------------------------------- // - private static TitleMixinDefault i = new TitleMixinDefault(); - public static TitleMixinDefault get() { return i; } + private static MixinTitle d = new MixinTitle(); + private static MixinTitle i = d; + public static MixinTitle get() { return i; } + public static void set(MixinTitle i) { MixinTitle.i = i; } // -------------------------------------------- // - // OVERRIDE + // METHODS // -------------------------------------------- // - @Override public boolean sendTitleMessage(Object watcherObject, int ticksIn, int ticksStay, int ticksOut, String titleMain, String titleSub) { // Get the player @@ -26,16 +28,22 @@ public class TitleMixinDefault extends TitleMixinAbstract if (player == null) return false; // If we don't send any message (empty is ok) we might end up displaying old messages. - if (titleSub == null) titleSub = ""; - if (titleMain == null) titleMain = ""; + if (titleSub == null) titleSub = ""; + if (titleMain == null) titleMain = ""; titleSub = NmsPacket.toJson(titleSub); titleMain = NmsPacket.toJson(titleMain); return NmsPacket.sendTitle(player, ticksIn, ticksStay, ticksOut, titleMain, titleSub); } - - @Override + + public boolean sendTitleMsg(Object watcherObject, int ticksIn, int ticksStay, int ticksOut, String titleMain, String titleSub) + { + if (titleMain != null) titleMain = Txt.parse(titleMain); + if (titleSub != null) titleSub = Txt.parse(titleSub); + return this.sendTitleMessage(watcherObject, ticksIn, ticksStay, ticksOut, titleMain, titleSub); + } + public boolean isTitlesAvailable() { return NmsPacket.get().isAvailable(); diff --git a/src/com/massivecraft/massivecore/mixin/VisibilityMixinDefault.java b/src/com/massivecraft/massivecore/mixin/MixinVisibility.java similarity index 82% rename from src/com/massivecraft/massivecore/mixin/VisibilityMixinDefault.java rename to src/com/massivecraft/massivecore/mixin/MixinVisibility.java index 9380ddd1..4ada1c65 100644 --- a/src/com/massivecraft/massivecore/mixin/VisibilityMixinDefault.java +++ b/src/com/massivecraft/massivecore/mixin/MixinVisibility.java @@ -1,55 +1,54 @@ -package com.massivecraft.massivecore.mixin; - -import org.bukkit.entity.Player; - -import com.massivecraft.massivecore.util.IdUtil; -import com.massivecraft.massivecore.util.MUtil; - -public class VisibilityMixinDefault extends VisibilityMixinAbstract -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static VisibilityMixinDefault i = new VisibilityMixinDefault(); - public static VisibilityMixinDefault get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean isVisible(Object watcheeObject) - { - // The Bukkit API is not about general visibility. - // It only handles player to player visibility. - // With this in mind we loop to do some sort of approximation. - // If there is any other player who can not see then we are not visible. - // This is for the sake of security. Rather hide than display secret information. - - Player pwatchee = IdUtil.getPlayer(watcheeObject); - if (pwatchee == null) return true; - - for (Player pwatcher : MUtil.getOnlinePlayers()) - { - if (pwatchee.equals(pwatcher)) continue; - if (pwatcher.canSee(pwatchee)) continue; - return false; - } - - return true; - } - - @Override - public boolean isVisible(Object watcheeObject, Object watcherObject) - { - Player pwatchee = IdUtil.getPlayer(watcheeObject); - Player pwatcher = IdUtil.getPlayer(watcherObject); - - if (pwatchee == null) return true; - if (pwatcher == null) return true; - - return pwatcher.canSee(pwatchee); - } - -} +package com.massivecraft.massivecore.mixin; + +import org.bukkit.entity.Player; +import com.massivecraft.massivecore.util.IdUtil; +import com.massivecraft.massivecore.util.MUtil; + +public class MixinVisibility extends MixinAbstract +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MixinVisibility d = new MixinVisibility(); + private static MixinVisibility i = d; + public static MixinVisibility get() { return i; } + public static void set(MixinVisibility i) { MixinVisibility.i = i; } + + // -------------------------------------------- // + // METHODS + // -------------------------------------------- // + + public boolean isVisible(Object watcheeObject) + { + // The Bukkit API is not about general visibility. + // It only handles player to player visibility. + // With this in mind we loop to do some sort of approximation. + // If there is any other player who can not see then we are not visible. + // This is for the sake of security. Rather hide than display secret information. + + Player pwatchee = IdUtil.getPlayer(watcheeObject); + if (pwatchee == null) return true; + + for (Player pwatcher : MUtil.getOnlinePlayers()) + { + if (pwatchee.equals(pwatcher)) continue; + if (pwatcher.canSee(pwatchee)) continue; + return false; + } + + return true; + } + + public boolean isVisible(Object watcheeObject, Object watcherObject) + { + Player pwatchee = IdUtil.getPlayer(watcheeObject); + Player pwatcher = IdUtil.getPlayer(watcherObject); + + if (pwatchee == null) return true; + if (pwatcher == null) return true; + + return pwatcher.canSee(pwatchee); + } + +} diff --git a/src/com/massivecraft/massivecore/mixin/WorldMixinDefault.java b/src/com/massivecraft/massivecore/mixin/MixinWorld.java similarity index 76% rename from src/com/massivecraft/massivecore/mixin/WorldMixinDefault.java rename to src/com/massivecraft/massivecore/mixin/MixinWorld.java index 12affc91..7218bc7f 100644 --- a/src/com/massivecraft/massivecore/mixin/WorldMixinDefault.java +++ b/src/com/massivecraft/massivecore/mixin/MixinWorld.java @@ -1,135 +1,158 @@ -package com.massivecraft.massivecore.mixin; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.Permissible; - -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.ps.PSFormatDesc; -import com.massivecraft.massivecore.util.MUtil; - -public class WorldMixinDefault extends WorldMixinAbstract -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static WorldMixinDefault i = new WorldMixinDefault(); - public static WorldMixinDefault get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean canSeeWorld(Permissible permissible, String worldId) - { - return true; - } - - @Override - public List getWorldIds() - { - // Create - List ret = new ArrayList(); - - // Fill - for (World world : Bukkit.getWorlds()) - { - ret.add(world.getName()); - } - - // Return - return ret; - } - - @Override - public ChatColor getWorldColor(String worldId) - { - return ChatColor.WHITE; - } - - @Override - public List getWorldAliases(String worldId) - { - return new ArrayList(); - } - - @Override - public PS getWorldSpawnPs(String worldId) - { - World world = Bukkit.getWorld(worldId); - if (world == null) return null; - return PS.valueOf(world.getSpawnLocation()); - } - - @Override - public void setWorldSpawnPs(String worldId, PS spawnPs) - { - World world = Bukkit.getWorld(worldId); - if (world == null) return; - - spawnPs = spawnPs.withWorld(world.getName()); - - Location location = null; - try - { - location = spawnPs.asBukkitLocation(true); - } - catch (Exception e) - { - return; - } - - world.setSpawnLocation(location.getBlockX(), location.getBlockY(), location.getBlockZ()); - } - - @Override - public boolean trySetWorldSpawnWp(CommandSender sender, String worldId, PS goal, boolean verbooseChange, boolean verbooseSame) - { - World world = Bukkit.getWorld(worldId); - if (world == null) - { - if (verbooseChange || verbooseSame) - { - Mixin.msgOne(sender, "Unknown world %s.", worldId); - } - return false; - } - - // Pre Calculations - String worldDisplayName = Mixin.getWorldDisplayName(worldId); - PS current = this.getWorldSpawnPs(worldId); - String currentFormatted = current.toString(PSFormatDesc.get()); - String goalFormatted = goal.toString(PSFormatDesc.get()); - - // No change? - if (MUtil.equals(goal, current)) - { - if (verbooseSame) - { - Mixin.msgOne(sender, "Spawn location is already %s for %s.", currentFormatted, worldDisplayName); - } - return true; - } - - // Report - if (verbooseChange) - { - Mixin.msgOne(sender, "Changing spawn location from %s to %s for %s.", currentFormatted, goalFormatted, worldDisplayName); - } - - // Set it - this.setWorldSpawnPs(worldId, goal); - - // Return - return true; - } - -} +package com.massivecraft.massivecore.mixin; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.permissions.Permissible; + +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.ps.PSFormatDesc; +import com.massivecraft.massivecore.util.MUtil; + +public class MixinWorld extends MixinAbstract +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MixinWorld d = new MixinWorld(); + private static MixinWorld i = d; + public static MixinWorld get() { return i; } + public static void set(MixinWorld i) { MixinWorld.i = i; } + + // -------------------------------------------- // + // METHODS + // -------------------------------------------- // + + public boolean canSeeWorld(Permissible permissible, String worldId) + { + return true; + } + + public List getWorldIds() + { + // Create + List ret = new ArrayList(); + + // Fill + for (World world : Bukkit.getWorlds()) + { + ret.add(world.getName()); + } + + // Return + return ret; + } + + public List getVisibleWorldIds(Permissible permissible) + { + // Create + List ret = new ArrayList(); + + // Fill + for (String worldId : this.getWorldIds()) + { + if ( ! this.canSeeWorld(permissible, worldId)) continue; + ret.add(worldId); + } + + // Return + return ret; + } + + public ChatColor getWorldColor(String worldId) + { + return ChatColor.WHITE; + } + + public List getWorldAliases(String worldId) + { + return new ArrayList(); + } + + public String getWorldAliasOrId(String worldId) + { + List aliases = this.getWorldAliases(worldId); + if (aliases.size() > 0) return aliases.get(0); + return worldId; + } + + public String getWorldDisplayName(String worldId) + { + return this.getWorldColor(worldId).toString() + this.getWorldAliasOrId(worldId); + } + + public PS getWorldSpawnPs(String worldId) + { + World world = Bukkit.getWorld(worldId); + if (world == null) return null; + return PS.valueOf(world.getSpawnLocation()); + } + + public void setWorldSpawnPs(String worldId, PS spawnPs) + { + World world = Bukkit.getWorld(worldId); + if (world == null) return; + + spawnPs = spawnPs.withWorld(world.getName()); + + Location location = null; + try + { + location = spawnPs.asBukkitLocation(true); + } + catch (Exception e) + { + return; + } + + world.setSpawnLocation(location.getBlockX(), location.getBlockY(), location.getBlockZ()); + } + + public boolean trySetWorldSpawnWp(CommandSender sender, String worldId, PS goal, boolean verbooseChange, boolean verbooseSame) + { + World world = Bukkit.getWorld(worldId); + if (world == null) + { + if (verbooseChange || verbooseSame) + { + Mixin.msgOne(sender, "Unknown world %s.", worldId); + } + return false; + } + + // Pre Calculations + String worldDisplayName = Mixin.getWorldDisplayName(worldId); + PS current = this.getWorldSpawnPs(worldId); + String currentFormatted = current.toString(PSFormatDesc.get()); + String goalFormatted = goal.toString(PSFormatDesc.get()); + + // No change? + if (MUtil.equals(goal, current)) + { + if (verbooseSame) + { + Mixin.msgOne(sender, "Spawn location is already %s for %s.", currentFormatted, worldDisplayName); + } + return true; + } + + // Report + if (verbooseChange) + { + Mixin.msgOne(sender, "Changing spawn location from %s to %s for %s.", currentFormatted, goalFormatted, worldDisplayName); + } + + // Set it + this.setWorldSpawnPs(worldId, goal); + + // Return + return true; + } + +} diff --git a/src/com/massivecraft/massivecore/mixin/ModificationMixin.java b/src/com/massivecraft/massivecore/mixin/ModificationMixin.java deleted file mode 100644 index 53a73d86..00000000 --- a/src/com/massivecraft/massivecore/mixin/ModificationMixin.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -import com.massivecraft.massivecore.store.Coll; -import com.massivecraft.massivecore.store.Entity; - -public interface ModificationMixin -{ - public void syncModification(Entity entity); - public void syncModification(Coll coll, String id); -} diff --git a/src/com/massivecraft/massivecore/mixin/ModificationMixinAbstract.java b/src/com/massivecraft/massivecore/mixin/ModificationMixinAbstract.java deleted file mode 100644 index 1222eb39..00000000 --- a/src/com/massivecraft/massivecore/mixin/ModificationMixinAbstract.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -import com.massivecraft.massivecore.store.Entity; - -public abstract class ModificationMixinAbstract implements ModificationMixin -{ - public void syncModification(Entity entity) - { - this.syncModification(entity.getColl(), entity.getId()); - } -} diff --git a/src/com/massivecraft/massivecore/mixin/ModificationMixinDefault.java b/src/com/massivecraft/massivecore/mixin/ModificationMixinDefault.java deleted file mode 100644 index 470a6463..00000000 --- a/src/com/massivecraft/massivecore/mixin/ModificationMixinDefault.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -import com.massivecraft.massivecore.store.Coll; - -public class ModificationMixinDefault extends ModificationMixinAbstract -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static ModificationMixinDefault i = new ModificationMixinDefault(); - public static ModificationMixinDefault get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - @Override - public void syncModification(Coll coll, String id) - { - // Nothing to do here - } - -} diff --git a/src/com/massivecraft/massivecore/mixin/PlayedMixin.java b/src/com/massivecraft/massivecore/mixin/PlayedMixin.java deleted file mode 100644 index 564f7d50..00000000 --- a/src/com/massivecraft/massivecore/mixin/PlayedMixin.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -public interface PlayedMixin -{ - public boolean isOnline(Object senderObject); - public boolean isOffline(Object senderObject); - public Long getFirstPlayed(Object senderObject); - public Long getLastPlayed(Object senderObject); - public boolean hasPlayedBefore(Object senderObject); - public String getIp(Object senderObject); -} diff --git a/src/com/massivecraft/massivecore/mixin/PlayedMixinAbstract.java b/src/com/massivecraft/massivecore/mixin/PlayedMixinAbstract.java deleted file mode 100644 index 408217be..00000000 --- a/src/com/massivecraft/massivecore/mixin/PlayedMixinAbstract.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -import com.massivecraft.massivecore.util.IdUtil; - -public abstract class PlayedMixinAbstract implements PlayedMixin -{ - @Override - public boolean isOnline(Object senderObject) - { - return IdUtil.isOnline(senderObject); - } - - @Override - public boolean isOffline(Object senderObject) - { - return !this.isOnline(senderObject); - } - - @Override - public boolean hasPlayedBefore(Object senderObject) - { - Long firstPlayed = this.getFirstPlayed(senderObject); - return firstPlayed != null && firstPlayed != 0; - } - -} diff --git a/src/com/massivecraft/massivecore/mixin/SenderPsMixin.java b/src/com/massivecraft/massivecore/mixin/SenderPsMixin.java deleted file mode 100644 index e3858719..00000000 --- a/src/com/massivecraft/massivecore/mixin/SenderPsMixin.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -import com.massivecraft.massivecore.ps.PS; - -public interface SenderPsMixin -{ - public PS getSenderPs(Object senderObject); - public void setSenderPs(Object senderObject, PS ps); -} diff --git a/src/com/massivecraft/massivecore/mixin/SenderPsMixinAbstract.java b/src/com/massivecraft/massivecore/mixin/SenderPsMixinAbstract.java deleted file mode 100644 index 3347afd0..00000000 --- a/src/com/massivecraft/massivecore/mixin/SenderPsMixinAbstract.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -public abstract class SenderPsMixinAbstract implements SenderPsMixin -{ - -} diff --git a/src/com/massivecraft/massivecore/mixin/TeleportMixin.java b/src/com/massivecraft/massivecore/mixin/TeleportMixin.java deleted file mode 100644 index 305a340a..00000000 --- a/src/com/massivecraft/massivecore/mixin/TeleportMixin.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.permissions.Permissible; - -import com.massivecraft.massivecore.teleport.Destination; - -public interface TeleportMixin -{ - // -------------------------------------------- // - // CHECK - // -------------------------------------------- // - - public boolean isCausedByMixin(PlayerTeleportEvent event); - - // PERMUTATION - // # to - // PS - // CommandSender - // SenderEntity - // String - // PSGetter - - // -------------------------------------------- // - // COMMAND SENDER - // -------------------------------------------- // - - public void teleport(Object teleporteeObject, Destination destination) throws TeleporterException; - public void teleport(Object teleporteeObject, Destination destination, Permissible delayPermissible) throws TeleporterException; - public void teleport(Object teleporteeObject, Destination destination, int delaySeconds) throws TeleporterException; - -} diff --git a/src/com/massivecraft/massivecore/mixin/TeleportMixinAbstract.java b/src/com/massivecraft/massivecore/mixin/TeleportMixinAbstract.java deleted file mode 100644 index ac52f15d..00000000 --- a/src/com/massivecraft/massivecore/mixin/TeleportMixinAbstract.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.permissions.Permissible; - -import com.massivecraft.massivecore.MassiveCoreMConf; -import com.massivecraft.massivecore.engine.EngineMassiveCoreTeleportMixinCause; -import com.massivecraft.massivecore.teleport.Destination; - -public abstract class TeleportMixinAbstract implements TeleportMixin -{ - // -------------------------------------------- // - // UTIL - // -------------------------------------------- // - - public static int getTpdelay(Permissible delayPermissible) - { - return MassiveCoreMConf.get().getTpdelay(delayPermissible); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean isCausedByMixin(PlayerTeleportEvent event) - { - return EngineMassiveCoreTeleportMixinCause.get().isCausedByTeleportMixin(event); - } - - @Override - public void teleport(Object teleportee, Destination destination) throws TeleporterException - { - this.teleport(teleportee, destination, 0); - } - - @Override - public void teleport(Object teleportee, Destination destination, Permissible delayPermissible) throws TeleporterException - { - this.teleport(teleportee, destination, getTpdelay(delayPermissible)); - } - - // TO OVERRIDE - /* - @Override - public void teleport(Object teleporteeObject, Destination destination, int delaySeconds) throws TeleporterException - { - // TODO Auto-generated method stub - } - */ -} diff --git a/src/com/massivecraft/massivecore/mixin/TitleMixin.java b/src/com/massivecraft/massivecore/mixin/TitleMixin.java deleted file mode 100644 index 7b01033e..00000000 --- a/src/com/massivecraft/massivecore/mixin/TitleMixin.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -public interface TitleMixin -{ - // Abstract - public boolean sendTitleMessage(Object watcherObject, int ticksIn, int ticksStay, int ticksOut, String titleMain, String titleSub); - - // Parsed - public boolean sendTitleMsg(Object watcherObject, int ticksIn, int ticksStay, int ticksOut, String titleMain, String titleSub); - - // Available - public boolean isTitlesAvailable(); -} diff --git a/src/com/massivecraft/massivecore/mixin/TitleMixinAbstract.java b/src/com/massivecraft/massivecore/mixin/TitleMixinAbstract.java deleted file mode 100644 index 76285212..00000000 --- a/src/com/massivecraft/massivecore/mixin/TitleMixinAbstract.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -import com.massivecraft.massivecore.util.Txt; - -public abstract class TitleMixinAbstract implements TitleMixin -{ - // Parsed - @Override - public boolean sendTitleMsg(Object watcherObject, int ticksIn, int ticksStay, int ticksOut, String titleMain, String titleSub) - { - if (titleMain != null) titleMain = Txt.parse(titleMain); - if (titleSub != null) titleSub = Txt.parse(titleSub); - return this.sendTitleMessage(watcherObject, ticksIn, ticksStay, ticksOut, titleMain, titleSub); - } - -} diff --git a/src/com/massivecraft/massivecore/mixin/VisibilityMixin.java b/src/com/massivecraft/massivecore/mixin/VisibilityMixin.java deleted file mode 100644 index 6cef7356..00000000 --- a/src/com/massivecraft/massivecore/mixin/VisibilityMixin.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -public interface VisibilityMixin -{ - public boolean isVisible(Object watcheeObject); - public boolean isVisible(Object watcheeObject, Object watcherObject); -} diff --git a/src/com/massivecraft/massivecore/mixin/VisibilityMixinAbstract.java b/src/com/massivecraft/massivecore/mixin/VisibilityMixinAbstract.java deleted file mode 100644 index 5cabc361..00000000 --- a/src/com/massivecraft/massivecore/mixin/VisibilityMixinAbstract.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -public abstract class VisibilityMixinAbstract implements VisibilityMixin -{ - -} diff --git a/src/com/massivecraft/massivecore/mixin/WorldMixin.java b/src/com/massivecraft/massivecore/mixin/WorldMixin.java deleted file mode 100644 index 26f2aabe..00000000 --- a/src/com/massivecraft/massivecore/mixin/WorldMixin.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -import java.util.List; - -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.Permissible; - -import com.massivecraft.massivecore.ps.PS; - -public interface WorldMixin -{ - public boolean canSeeWorld(Permissible permissible, String worldId); - - public List getWorldIds(); - - public List getVisibleWorldIds(Permissible permissible); - - public ChatColor getWorldColor(String worldId); - - public List getWorldAliases(String worldId); - - public String getWorldAliasOrId(String worldId); - - public String getWorldDisplayName(String worldId); - - public PS getWorldSpawnPs(String worldId); - - public void setWorldSpawnPs(String worldId, PS spawnPs); - - public boolean trySetWorldSpawnWp(CommandSender sender, String worldId, PS spawnPs, boolean verbooseChange, boolean verbooseSame); - -} diff --git a/src/com/massivecraft/massivecore/mixin/WorldMixinAbstract.java b/src/com/massivecraft/massivecore/mixin/WorldMixinAbstract.java deleted file mode 100644 index 7d89db3a..00000000 --- a/src/com/massivecraft/massivecore/mixin/WorldMixinAbstract.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.permissions.Permissible; - -public abstract class WorldMixinAbstract implements WorldMixin -{ - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public List getVisibleWorldIds(Permissible permissible) - { - // Create - List ret = new ArrayList(); - - // Fill - for (String worldId : this.getWorldIds()) - { - if ( ! this.canSeeWorld(permissible, worldId)) continue; - ret.add(worldId); - } - - // Return - return ret; - } - - @Override - public String getWorldAliasOrId(String worldId) - { - List aliases = this.getWorldAliases(worldId); - if (aliases.size() > 0) return aliases.get(0); - return worldId; - } - - @Override - public String getWorldDisplayName(String worldId) - { - return this.getWorldColor(worldId).toString() + this.getWorldAliasOrId(worldId); - } - -} diff --git a/src/com/massivecraft/massivecore/util/ReflectionUtil.java b/src/com/massivecraft/massivecore/util/ReflectionUtil.java index 8300f515..843c128b 100644 --- a/src/com/massivecraft/massivecore/util/ReflectionUtil.java +++ b/src/com/massivecraft/massivecore/util/ReflectionUtil.java @@ -264,6 +264,22 @@ public class ReflectionUtil }); } + public static Class getSuperclassDeclaringField(Class clazz, boolean includeSelf, final String fieldName) + { + return getSuperclassPredicate(clazz, includeSelf, new Predicate>() + { + @Override + public boolean apply(Class clazz) + { + for (Field field : clazz.getDeclaredFields()) + { + if (field.getName().equals(fieldName)) return true; + } + return false; + } + }); + } + // -------------------------------------------- // // AS RUNTIME EXCEPTION // -------------------------------------------- //