Mixins Reworked

This commit is contained in:
Olof Larsson 2016-03-28 22:25:11 +02:00
parent 615a212847
commit 5b6b29f6a9
52 changed files with 1187 additions and 1519 deletions

View File

@ -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

View File

@ -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();
}

View File

@ -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));
}
}

View File

@ -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);
}

View File

@ -1,6 +0,0 @@
package com.massivecraft.massivecore.mixin;
public abstract class ActualMixinAbstract implements ActualMixin
{
}

View File

@ -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
}

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -1,6 +0,0 @@
package com.massivecraft.massivecore.mixin;
public abstract class GamemodeMixinAbstract implements GamemodeMixin
{
}

View File

@ -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);
}

View File

@ -1,6 +0,0 @@
package com.massivecraft.massivecore.mixin;
public abstract class InventoryMixinAbstract implements InventoryMixin
{
}

View File

@ -1,7 +0,0 @@
package com.massivecraft.massivecore.mixin;
public interface KickMixin
{
public boolean kick(Object senderObject);
public boolean kick(Object senderObject, String message);
}

View File

@ -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);
}
}

View File

@ -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<String> msgs);
// Predicate
public boolean msgPredicate(Predicate<CommandSender> predicate, String msg);
public boolean msgPredicate(Predicate<CommandSender> predicate, String msg, Object... args);
public boolean msgPredicate(Predicate<CommandSender> predicate, Collection<String> msgs);
// One
public boolean msgOne(Object sendeeObject, String msg);
public boolean msgOne(Object sendeeObject, String msg, Object... args);
public boolean msgOne(Object sendeeObject, Collection<String> msgs);
// -------------------------------------------- //
// MESSAGE
// -------------------------------------------- //
// All
public boolean messageAll(Object message);
public boolean messageAll(Object... messages);
public boolean messageAll(Collection<?> messages);
// Predicate
public boolean messagePredicate(Predicate<CommandSender> predicate, Object message);
public boolean messagePredicate(Predicate<CommandSender> predicate, Object... messages);
public boolean messagePredicate(Predicate<CommandSender> 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);
}

View File

@ -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<String> msgs)
{
return this.messageAll(Txt.parse(msgs));
}
// Predicate
@Override
public boolean msgPredicate(Predicate<CommandSender> predicate, String msg)
{
return this.messagePredicate(predicate, Txt.parse(msg));
}
@Override
public boolean msgPredicate(Predicate<CommandSender> predicate, String msg, Object... args)
{
return this.messagePredicate(predicate, Txt.parse(msg, args));
}
@Override
public boolean msgPredicate(Predicate<CommandSender> predicate, Collection<String> 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<String> 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<CommandSender> predicate, Object message)
{
return this.messagePredicate(predicate, asCollection(message));
}
@Override
public boolean messagePredicate(Predicate<CommandSender> 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);
}
}

View File

@ -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<CommandSender> 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;
}
}

View File

@ -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<String> getWorldIds()
{
return getWorldMixin().getWorldIds();
return MixinWorld.get().getWorldIds();
}
public static List<String> 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<String> 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<String> msgs)
{
return getMessageMixin().msgAll(msgs);
return MixinMessage.get().msgAll(msgs);
}
// MSG: Predicate
public static boolean msgPredicate(Predicate<CommandSender> predicate, String msg)
{
return getMessageMixin().msgPredicate(predicate, msg);
return MixinMessage.get().msgPredicate(predicate, msg);
}
public static boolean msgPredicate(Predicate<CommandSender> predicate, String msg, Object... args)
{
return getMessageMixin().msgPredicate(predicate, msg, args);
return MixinMessage.get().msgPredicate(predicate, msg, args);
}
public static boolean msgPredicate(Predicate<CommandSender> predicate, Collection<String> 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<String> 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<CommandSender> predicate, Object message)
{
return getMessageMixin().messagePredicate(predicate, message);
return MixinMessage.get().messagePredicate(predicate, message);
}
public static boolean messagePredicate(Predicate<CommandSender> predicate, Object... messages)
{
return getMessageMixin().messagePredicate(predicate, messages);
return MixinMessage.get().messagePredicate(predicate, messages);
}
public static boolean messagePredicate(Predicate<CommandSender> 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);
}
}

View File

@ -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());
}
}

View File

@ -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();

View File

@ -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;
}
}
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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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 <E extends Event & Serializable> void distribute(E event)
{
this.distribute(event, false);
}
public <E extends Event & Serializable> void distribute(E event, boolean includeSelf)
{
this.distributeOthers(event);
if (includeSelf) this.distributeSelf(event);
}
protected <E extends Event & Serializable> void distributeSelf(E event)
{
Bukkit.getPluginManager().callEvent(event);
}
protected <E extends Event & Serializable> void distributeOthers(E event)
{
// NOTE: This is where the event would be sent to all other servers in the network.
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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<String> msgs)
{
return this.messageAll(Txt.parse(msgs));
}
// -------------------------------------------- //
// MSG > PREDICATE
// -------------------------------------------- //
public boolean msgPredicate(Predicate<CommandSender> predicate, String msg)
{
return this.messagePredicate(predicate, Txt.parse(msg));
}
public boolean msgPredicate(Predicate<CommandSender> predicate, String msg, Object... args)
{
return this.messagePredicate(predicate, Txt.parse(msg, args));
}
public boolean msgPredicate(Predicate<CommandSender> predicate, Collection<String> 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<String> 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<CommandSender> predicate, Object message)
{
return this.messagePredicate(predicate, asCollection(message));
}
public boolean messagePredicate(Predicate<CommandSender> predicate, Object... messages)
{
return this.messagePredicate(predicate, asCollection(messages));
}
public boolean messagePredicate(Predicate<CommandSender> 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);
}
}

View File

@ -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
}
}

View File

@ -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);
}
}

View File

@ -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.
}
}

View File

@ -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("<b>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("<white>%s <b>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, "<i>Teleporting to <h>"+desc+" <i>in <h>"+delaySeconds+"s <i>unless you move.");
}
else
{
Mixin.msgOne(teleporteeId, "<i>Teleporting in <h>"+delaySeconds+"s <i>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, "<i>Teleporting to <h>"+desc+"<i>.");
}
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("<b>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("<white>%s <b>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, "<i>Teleporting to <h>"+desc+" <i>in <h>"+delaySeconds+"s <i>unless you move.");
}
else
{
Mixin.msgOne(teleporteeId, "<i>Teleporting in <h>"+delaySeconds+"s <i>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, "<i>Teleporting to <h>"+desc+"<i>.");
}
Player teleportee = IdUtil.getPlayer(teleporteeId);
if (teleportee != null)
{
teleportPlayer(teleportee, ps);
}
else
{
Mixin.setSenderPs(teleporteeId, ps);
}
}
}
}

View File

@ -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();

View File

@ -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);
}
}

View File

@ -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<String> getWorldIds()
{
// Create
List<String> ret = new ArrayList<String>();
// 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<String> getWorldAliases(String worldId)
{
return new ArrayList<String>();
}
@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, "<b>Unknown world <h>%s<b>.", 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, "<i>Spawn location is already <h>%s <i>for <h>%s<i>.", currentFormatted, worldDisplayName);
}
return true;
}
// Report
if (verbooseChange)
{
Mixin.msgOne(sender, "<i>Changing spawn location from <h>%s <i>to <h>%s <i>for <h>%s<i>.", 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<String> getWorldIds()
{
// Create
List<String> ret = new ArrayList<String>();
// Fill
for (World world : Bukkit.getWorlds())
{
ret.add(world.getName());
}
// Return
return ret;
}
public List<String> getVisibleWorldIds(Permissible permissible)
{
// Create
List<String> ret = new ArrayList<String>();
// 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<String> getWorldAliases(String worldId)
{
return new ArrayList<String>();
}
public String getWorldAliasOrId(String worldId)
{
List<String> 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, "<b>Unknown world <h>%s<b>.", 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, "<i>Spawn location is already <h>%s <i>for <h>%s<i>.", currentFormatted, worldDisplayName);
}
return true;
}
// Report
if (verbooseChange)
{
Mixin.msgOne(sender, "<i>Changing spawn location from <h>%s <i>to <h>%s <i>for <h>%s<i>.", currentFormatted, goalFormatted, worldDisplayName);
}
// Set it
this.setWorldSpawnPs(worldId, goal);
// Return
return true;
}
}

View File

@ -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);
}

View File

@ -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());
}
}

View File

@ -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
}
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -1,6 +0,0 @@
package com.massivecraft.massivecore.mixin;
public abstract class SenderPsMixinAbstract implements SenderPsMixin
{
}

View File

@ -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;
}

View File

@ -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
}
*/
}

View File

@ -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();
}

View File

@ -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);
}
}

View File

@ -1,7 +0,0 @@
package com.massivecraft.massivecore.mixin;
public interface VisibilityMixin
{
public boolean isVisible(Object watcheeObject);
public boolean isVisible(Object watcheeObject, Object watcherObject);
}

View File

@ -1,6 +0,0 @@
package com.massivecraft.massivecore.mixin;
public abstract class VisibilityMixinAbstract implements VisibilityMixin
{
}

View File

@ -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<String> getWorldIds();
public List<String> getVisibleWorldIds(Permissible permissible);
public ChatColor getWorldColor(String worldId);
public List<String> 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);
}

View File

@ -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<String> getVisibleWorldIds(Permissible permissible)
{
// Create
List<String> ret = new ArrayList<String>();
// 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<String> 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);
}
}

View File

@ -264,6 +264,22 @@ public class ReflectionUtil
});
}
public static Class<?> getSuperclassDeclaringField(Class<?> clazz, boolean includeSelf, final String fieldName)
{
return getSuperclassPredicate(clazz, includeSelf, new Predicate<Class<?>>()
{
@Override
public boolean apply(Class<?> clazz)
{
for (Field field : clazz.getDeclaredFields())
{
if (field.getName().equals(fieldName)) return true;
}
return false;
}
});
}
// -------------------------------------------- //
// AS RUNTIME EXCEPTION
// -------------------------------------------- //