From 40afcaf26b2a5e9651274b5033b40a8442f5eb74 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Fri, 23 Oct 2015 15:07:53 -0400 Subject: [PATCH] Global Packet Commands --- .../globalpacket/GlobalPacketManager.java | 61 ++++++++++++++ .../command/GlobalPacketCommand.java | 30 +++++++ .../globalpacket/event/GlobalPacketEvent.java | 83 +++++++++++++++++++ .../redis/GlobalPacketHandler.java | 39 +++++++++ .../redis/GlobalPacketMessage.java | 50 +++++++++++ .../Mineplex.Hub/src/mineplex/hub/Hub.java | 2 + .../src/nautilus/game/arcade/Arcade.java | 9 +- 7 files changed, 268 insertions(+), 6 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/globalpacket/GlobalPacketManager.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/globalpacket/command/GlobalPacketCommand.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/globalpacket/event/GlobalPacketEvent.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/globalpacket/redis/GlobalPacketHandler.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/globalpacket/redis/GlobalPacketMessage.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/GlobalPacketManager.java b/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/GlobalPacketManager.java new file mode 100644 index 000000000..1329e1045 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/GlobalPacketManager.java @@ -0,0 +1,61 @@ +package mineplex.core.globalpacket; + +import java.util.Arrays; +import java.util.UUID; + +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.globalpacket.command.GlobalPacketCommand; +import mineplex.core.globalpacket.redis.GlobalPacketHandler; +import mineplex.core.globalpacket.redis.GlobalPacketMessage; +import mineplex.core.status.ServerStatusManager; +import mineplex.serverdata.commands.ServerCommandManager; + +public class GlobalPacketManager extends MiniPlugin +{ + private CoreClientManager _clientManager; + private ServerStatusManager _statusManager; + + public GlobalPacketManager(JavaPlugin plugin, CoreClientManager clientManager, ServerStatusManager statusManager) + { + super("Global Packet Manager", plugin); + + _clientManager = clientManager; + _statusManager = statusManager; + + ServerCommandManager.getInstance().registerCommandType("GlobalPacketMessage", GlobalPacketMessage.class, new GlobalPacketHandler(statusManager)); + } + + public void callGlobalCommand(Player caller, String[] args) + { + String callerName = null; + UUID callerUUID = null; + Rank callerRank = null; + + if (caller != null) + { + callerName = caller.getName(); + callerUUID = caller.getUniqueId(); + callerRank = _clientManager.Get(caller).GetRank(); + + UtilPlayer.message(caller, F.main("Global", "Sending Global Command with Arguments;")); + UtilPlayer.message(caller, F.main("Global", F.elem(Arrays.toString(args)))); + UtilPlayer.message(caller, F.main("Global", "Please be patient for a response.")); + } + + GlobalPacketMessage message = new GlobalPacketMessage(callerName, callerUUID, callerRank, _statusManager.getCurrentServerName(), args); + message.publish(); + } + + @Override + public void addCommands() + { + addCommand(new GlobalPacketCommand(this)); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/command/GlobalPacketCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/command/GlobalPacketCommand.java new file mode 100644 index 000000000..07a0ec31b --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/command/GlobalPacketCommand.java @@ -0,0 +1,30 @@ +package mineplex.core.globalpacket.command; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.globalpacket.GlobalPacketManager; + +public class GlobalPacketCommand extends CommandBase +{ + public GlobalPacketCommand(GlobalPacketManager plugin) + { + super(plugin, Rank.ADMIN, "global"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if (args == null || args.length < 1) + { + UtilPlayer.message(caller, F.main("Global", "Please call the global command with at least 1 argument")); + UtilPlayer.message(caller, F.main("Global", "For help please see /global google doc")); + return; + } + + Plugin.callGlobalCommand(caller, args); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/event/GlobalPacketEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/event/GlobalPacketEvent.java new file mode 100644 index 000000000..ba4c63fe5 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/event/GlobalPacketEvent.java @@ -0,0 +1,83 @@ +package mineplex.core.globalpacket.event; + +import java.util.UUID; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import mineplex.core.common.Rank; + +public class GlobalPacketEvent extends Event +{ + private Player _caller; + private String _callerName; + private UUID _callerUUID; + private Rank _callerRank; + private String _sourceServer; + private String[] _parts; + + public GlobalPacketEvent(Player caller, String callerName, UUID callerUUID, Rank callerRank, String sourceServer, String[] parts) + { + _caller = caller; + _callerName = callerName; + _callerUUID = callerUUID; + _callerRank = callerRank; + _sourceServer = sourceServer; + _parts = parts; + } + + /** + * The player that executed this global command. + * This player will be NULL when called on the servers that aren't _sourceServer + */ + public Player getCaller() + { + return _caller; + } + + /** + * The player name of the player that called the command + */ + public String getCallerName() + { + return _callerName; + } + + /** + * The UUID of the player that called the command + */ + public UUID getCallerUUID() + { + return _callerUUID; + } + + /** + * Get the rank of the player that called this global command + */ + public Rank getCallerRank() + { + return _callerRank; + } + + /** + * The server name that this global command came from + */ + public String getSourceServer() + { + return _sourceServer; + } + + /** + * Get the unprocessed parts of this command + */ + public String[] getParts() + { + return _parts; + } + + // Bukkit event stuff + private static final HandlerList handlers = new HandlerList(); + public static HandlerList getHandlerList() { return handlers; } + public HandlerList getHandlers() { return handlers; } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/redis/GlobalPacketHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/redis/GlobalPacketHandler.java new file mode 100644 index 000000000..c3a141231 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/redis/GlobalPacketHandler.java @@ -0,0 +1,39 @@ +package mineplex.core.globalpacket.redis; + +import org.bukkit.entity.Player; + +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.globalpacket.event.GlobalPacketEvent; +import mineplex.core.status.ServerStatusManager; +import mineplex.serverdata.commands.CommandCallback; +import mineplex.serverdata.commands.ServerCommand; + +public class GlobalPacketHandler implements CommandCallback +{ + private ServerStatusManager _serverStatus; + + public GlobalPacketHandler(ServerStatusManager serverStatus) + { + _serverStatus = serverStatus; + } + + @Override + public void run(ServerCommand command) + { + if (command instanceof GlobalPacketMessage) + { + GlobalPacketMessage packetMessage = ((GlobalPacketMessage) command); + + Player caller = null; + if (packetMessage.getSourceServer() != null && packetMessage.getSourceServer().equals(_serverStatus.getCurrentServerName())) + { + caller = UtilPlayer.searchExact(packetMessage.getCallerUUID()); + } + + GlobalPacketEvent event = new GlobalPacketEvent(caller, packetMessage.getCallerName(), packetMessage.getCallerUUID(), + packetMessage.getCallerRank(), packetMessage.getSourceServer(), packetMessage.getParts()); + UtilServer.getServer().getPluginManager().callEvent(event); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/redis/GlobalPacketMessage.java b/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/redis/GlobalPacketMessage.java new file mode 100644 index 000000000..2138942a5 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/globalpacket/redis/GlobalPacketMessage.java @@ -0,0 +1,50 @@ +package mineplex.core.globalpacket.redis; + +import java.util.UUID; + +import mineplex.core.common.Rank; +import mineplex.serverdata.commands.ServerCommand; + +public class GlobalPacketMessage extends ServerCommand +{ + private String _callerName; + private UUID _callerUUID; + private Rank _callerRank; + private String _sourceServer; + private String[] _parts; + + public GlobalPacketMessage(String callerName, UUID callerUUID, Rank callerRank, String sourceServer, String[] parts) + { + _callerName = callerName; + _callerUUID = callerUUID; + _callerRank = callerRank; + _sourceServer = sourceServer; + _parts = parts; + } + + public String getCallerName() + { + return _callerName; + } + + public UUID getCallerUUID() + { + return _callerUUID; + } + + public Rank getCallerRank() + { + return _callerRank; + } + + public String getSourceServer() + { + return _sourceServer; + } + + public String[] getParts() + { + return _parts; + } +} + diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index 6292320c1..979745883 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -19,6 +19,7 @@ import mineplex.core.elo.EloManager; import mineplex.core.energy.Energy; import mineplex.core.friend.FriendManager; import mineplex.core.give.Give; +import mineplex.core.globalpacket.GlobalPacketManager; import mineplex.core.hologram.HologramManager; import mineplex.core.ignore.IgnoreManager; import mineplex.core.inventory.InventoryManager; @@ -144,6 +145,7 @@ public class Hub extends JavaPlugin implements IRelation return true; } }); + new GlobalPacketManager(this, clientManager, serverStatusManager); //new Replay(this, packetHandler); AprilFoolsManager.Initialize(this, clientManager, disguiseManager); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index 85889628c..08a7f2bec 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -6,7 +6,7 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.FoodDupeFix; -import org.omg.CORBA._PolicyStub; +import mineplex.core.globalpacket.GlobalPacketManager; import net.minecraft.server.v1_7_R4.BiomeBase; import net.minecraft.server.v1_7_R4.MinecraftServer; @@ -27,9 +27,6 @@ import mineplex.core.disguise.DisguiseManager; import mineplex.core.donation.DonationManager; import mineplex.core.friend.FriendManager; import mineplex.core.gadget.GadgetManager; -import mineplex.core.gadget.gadgets.OutfitTeam; -import mineplex.core.gadget.types.Gadget; -import mineplex.core.gadget.types.GadgetType; import mineplex.core.give.Give; import mineplex.core.hologram.HologramManager; import mineplex.core.ignore.IgnoreManager; @@ -60,7 +57,6 @@ import mineplex.core.visibility.VisibilityManager; import mineplex.minecraft.game.core.combat.CombatManager; import mineplex.minecraft.game.core.damage.DamageManager; import nautilus.game.arcade.game.GameServerConfig; -import nautilus.game.arcade.game.Game.GameState; public class Arcade extends JavaPlugin { @@ -147,7 +143,8 @@ public class Arcade extends JavaPlugin CosmeticManager cosmeticManager = new CosmeticManager(this, _clientManager, _donationManager, inventoryManager, gadgetManager, mountManager, petManager, null); cosmeticManager.setInterfaceSlot(7); cosmeticManager.disableTeamArmor(); - + + new GlobalPacketManager(this, _clientManager, serverStatusManager); //Arcade Manager PollManager pollManager = new PollManager(this, _clientManager, _donationManager);