From f00854ee4c36ebffa56deae2f0428ce6b398a345 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Tue, 23 Dec 2014 03:43:56 -0500 Subject: [PATCH] Removed bad code thats bad from the bad birdy. Hooked in PersonalServer item click and command. Re-enabled redis transport commands. Added transfer command sending on personal server start. Updated Enjin to handle more versatile inventory purchases. --- .../personalServer/HostServerCommand.java | 20 ++++++ .../personalServer/PersonalServerManager.java | 71 ++++++++++++++----- .../src/mineplex/enjinTranslator/Enjin.java | 39 ++++++++-- .../src/mineplex/hub/HubManager.java | 3 - .../hub/commands/HostServerCommand.java | 22 ------ .../hub/modules/PrivateServerManager.java | 57 --------------- .../serverdata/ServerCommandManager.java | 2 - .../nautilus/game/arcade/ArcadeManager.java | 5 ++ 8 files changed, 113 insertions(+), 106 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/personalServer/HostServerCommand.java delete mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/commands/HostServerCommand.java delete mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/modules/PrivateServerManager.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/personalServer/HostServerCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/personalServer/HostServerCommand.java new file mode 100644 index 000000000..b447376bf --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/personalServer/HostServerCommand.java @@ -0,0 +1,20 @@ +package mineplex.core.personalServer; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; + +public class HostServerCommand extends CommandBase +{ + public HostServerCommand(PersonalServerManager plugin) + { + super(plugin, Rank.LEGEND, "host"); + } + + @Override + public void Execute(Player caller, String[] args) + { + Plugin.hostServer(caller, caller.getName()); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/personalServer/PersonalServerManager.java b/Plugins/Mineplex.Core/src/mineplex/core/personalServer/PersonalServerManager.java index 6b7dd2d8f..6cbc738e3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/personalServer/PersonalServerManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/personalServer/PersonalServerManager.java @@ -1,21 +1,33 @@ package mineplex.core.personalServer; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.itemstack.ItemStackFactory; import mineplex.serverdata.Region; import mineplex.serverdata.ServerGroup; import mineplex.serverdata.ServerManager; import mineplex.serverdata.ServerRepository; public class PersonalServerManager extends MiniPlugin -{ +{ private ServerRepository _repository; private boolean _us; + + private int _interfaceSlot = 6; + private ItemStack _interfaceItem; + private boolean _giveInterfaceItem = true; public PersonalServerManager(JavaPlugin plugin, CoreClientManager clientManager) { @@ -27,6 +39,32 @@ public class PersonalServerManager extends MiniPlugin Region region = _us ? Region.US : Region.EU; _repository = ServerManager.getServerRepository(region); + + _interfaceItem = ItemStackFactory.Instance.CreateStack(Material.SPECKLED_MELON, (byte)0, 1, C.cGreen + "/hostserver"); + } + + @EventHandler + public void onJoin(PlayerJoinEvent event) + { + if (_giveInterfaceItem) + { + event.getPlayer().getInventory().setItem(_interfaceSlot, _interfaceItem); + } + } + + @EventHandler + public void openServer(PlayerInteractEvent event) + { + if (_interfaceItem.equals(event.getPlayer().getItemInHand())) + { + hostServer(event.getPlayer(), event.getPlayer().getName()); + } + } + + @Override + public void AddCommands() + { + addCommand(new HostServerCommand(this)); } private void setupConfigValues() @@ -41,28 +79,17 @@ public class PersonalServerManager extends MiniPlugin catch (Exception e) { e.printStackTrace(); - } + } } - @EventHandler - public void testing(PlayerCommandPreprocessEvent event) + public void hostServer(Player player, String serverName) { - String[] parts = event.getMessage().split(" "); - String[] args = new String[parts.length - 1]; - System.arraycopy(parts, 1, args, 0, parts.length - 1); - - if (event.getMessage().toLowerCase().startsWith("/host")) - { - if (args == null || args.length == 0) - { - createGroup(event.getPlayer().getName(), event.getPlayer().getName(), 16, 16, "Smash"); - } - } + createGroup(player, serverName, 24, 24, "Smash"); } - private void createGroup(String host, String serverName, int minPlayers, int maxPlayers, String games) + private void createGroup(final Player host, final String serverName, int minPlayers, int maxPlayers, String games) { - final ServerGroup serverGroup = new ServerGroup(host, serverName, host, 1024, 1, 1, 0, 19999, true, "arcade.zip", "Arcade.jar", "plugins/Arcade/", minPlayers, maxPlayers, + final ServerGroup serverGroup = new ServerGroup(serverName, serverName, host.getName(), 1024, 1, 1, 0, 19999, true, "arcade.zip", "Arcade.jar", "plugins/Arcade/", minPlayers, maxPlayers, true, false, false, games, "Player", false, false, true, false, true, true, false, false, false, false, true, true, true, false, false, "", _us ? Region.US : Region.EU); GetPlugin().getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable() @@ -70,6 +97,14 @@ public class PersonalServerManager extends MiniPlugin public void run() { _repository.updateServerGroup(serverGroup); + Bukkit.getScheduler().runTask(GetPlugin(), new Runnable() + { + public void run() + { + host.sendMessage(F.main(getName(), serverName + "-1 successfully created. You will be sent to it shortly.")); + host.sendMessage(F.main(getName(), "If you haven't been connected in 20 seconds, type /server " + serverName + "-1.")); + } + }); } }); } diff --git a/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/Enjin.java b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/Enjin.java index 3b0d36cc5..d4765620b 100644 --- a/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/Enjin.java +++ b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/Enjin.java @@ -336,14 +336,45 @@ public class Enjin extends MiniPlugin implements CommandExecutor } else if (args.length >= 3 && args[0].equalsIgnoreCase("purchase")) { - String packageName = args[2]; + final int amount = Integer.parseInt(args[2]); + final String category = args[3]; + String tempName = args[4]; - for (int i = 3; i < args.length; i++) + for (int i = 5; i < args.length; i++) { - packageName += " " + args[i]; + tempName += " " + args[i]; } - _donationManager.PurchaseUnknownSalesPackage(null, name, playerUUID, packageName, false, 0, false); + final String packageName = tempName; + + _donationManager.PurchaseUnknownSalesPackage(new Callback() + { + public void run(TransactionResponse data) + { + if (data == TransactionResponse.Success) + { + _inventoryManager.addItemToInventoryForOffline(new Callback() + { + public void run(Boolean success) + { + if (success) + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " " + packageName + "."); + else + { + // Add arg so we don't add back to windows api call + _commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + packageName + ". Queuing for run later."); + } + } + }, playerUUID.toString(), category, packageName, amount); + } + else + { + _commandQueue.add(new QueuedCommand(sender, command, label, args)); + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Keys. Queuing for run later."); + } + } + }, name, playerUUID, packageName, false, 0, false); System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + packageName + "."); } else if (args.length >= 3 && args[0].equalsIgnoreCase("unban")) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 747a48aa1..51ac080b3 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -91,7 +91,6 @@ import mineplex.hub.modules.JumpManager; import mineplex.hub.modules.MapManager; import mineplex.hub.modules.NewsManager; import mineplex.hub.modules.ParkourManager; -import mineplex.hub.modules.PrivateServerManager; import mineplex.hub.modules.TextManager; import mineplex.hub.modules.UHCManager; import mineplex.hub.modules.VisibilityManager; @@ -202,8 +201,6 @@ public class HubManager extends MiniClientPlugin // NotificationManager notificationManager = new NotificationManager(plugin, clientManager, donationManager); // new MailManager(_plugin, notificationManager); - - new PrivateServerManager(_plugin); _ruleBook = ItemStackFactory.Instance.CreateStack(Material.WRITTEN_BOOK, (byte)0, 1, ChatColor.GREEN + "Rule Book", new String[] { }); BookMeta meta = (BookMeta)_ruleBook.getItemMeta(); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/HostServerCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/HostServerCommand.java deleted file mode 100644 index ce26e1297..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/HostServerCommand.java +++ /dev/null @@ -1,22 +0,0 @@ -package mineplex.hub.commands; - -import org.bukkit.entity.Player; - -import mineplex.core.command.CommandBase; -import mineplex.core.common.Rank; -import mineplex.hub.modules.PrivateServerManager; - -public class HostServerCommand extends CommandBase -{ - public HostServerCommand(PrivateServerManager plugin) - { - super(plugin, Rank.HERO, "hostserver"); - } - - @Override - public void Execute(Player caller, String[] args) - { - // TODO - Plugin.hostServer(caller); - } -} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/PrivateServerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/PrivateServerManager.java deleted file mode 100644 index 12fc31c9a..000000000 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/PrivateServerManager.java +++ /dev/null @@ -1,57 +0,0 @@ -package mineplex.hub.modules; - -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.java.JavaPlugin; - -import mineplex.core.MiniPlugin; -import mineplex.core.common.util.C; -import mineplex.core.itemstack.ItemStackFactory; -import mineplex.hub.commands.HostServerCommand; - -public class PrivateServerManager extends MiniPlugin -{ - private int _interfaceSlot = 6; - private ItemStack _interfaceItem; - private boolean _giveInterfaceItem = true; - - public PrivateServerManager(JavaPlugin plugin) - { - super("Private Server", plugin); - - _interfaceItem = ItemStackFactory.Instance.CreateStack(Material.SPECKLED_MELON, (byte)0, 1, C.cGreen + "/hostserver"); - } - - @EventHandler - public void onJoin(PlayerJoinEvent event) - { - if (_giveInterfaceItem) - { - event.getPlayer().getInventory().setItem(_interfaceSlot, _interfaceItem); - } - } - - @EventHandler - public void openServer(PlayerInteractEvent event) - { - if (_interfaceItem.equals(event.getPlayer().getItemInHand())) - { - hostServer(event.getPlayer()); - } - } - - public void hostServer(Player player) - { - //do stuff???? - } - - @Override - public void AddCommands() - { - addCommand(new HostServerCommand(this)); - } -} diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommandManager.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommandManager.java index 9cd1b4542..ca1820e0c 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommandManager.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommandManager.java @@ -44,7 +44,6 @@ public class ServerCommandManager */ private void initialize() { - /* CAUSING STUTTER LAG IN HUBS final Jedis jedis = _jedisPool.getResource(); // Spin up a new thread and subscribe to the Redis pubsub network @@ -68,7 +67,6 @@ public class ServerCommandManager }); thread.start(); - */ } /** diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index 07fd6e6bf..b4592b034 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -287,6 +287,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation _classShop = new ClassCombatShop(_classShopManager, clientManager, donationManager, false, "Class Shop"); _eloManager = new EloManager(_plugin, clientManager); + + if (GetHost() != null && !GetHost().isEmpty()) + { + Portal.transferPlayer(GetHost(), _serverStatusManager.getCurrentServerName()); + } } @Override