From b1c8158e2f9667b3d7aec1438f96ea39a75a50a3 Mon Sep 17 00:00:00 2001 From: Virizion <9b717b9d4e5f09e89fa3@gmail.com> Date: Tue, 8 Mar 2016 19:52:31 -0500 Subject: [PATCH] Added @a argument to /shard, /gem and /giveitem PC-13 --- .../core/donation/command/GemCommand.java | 43 ++++++++++++++++- .../core/donation/command/ShardCommand.java | 46 ++++++++++++++++++- .../inventory/command/GiveItemCommand.java | 10 ++++ 3 files changed, 96 insertions(+), 3 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/command/GemCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/command/GemCommand.java index 8690987bc..a19144834 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/command/GemCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/command/GemCommand.java @@ -10,6 +10,7 @@ import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UUIDFetcher; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.core.donation.DonationManager; public class GemCommand extends CommandBase @@ -32,7 +33,11 @@ public class GemCommand extends CommandBase String gemsString = args[1]; Player target = UtilPlayer.searchExact(targetName); - if (target == null) + if (targetName.equalsIgnoreCase("@a")) + { + rewardAllGems(caller, gemsString); + } + else if (target == null) { UUID uuid = UUIDFetcher.getUUIDOf(targetName); if (uuid != null) @@ -50,6 +55,42 @@ public class GemCommand extends CommandBase } } + private void rewardAllGems(Player caller, String gemsString) + { + try + { + int gems = Integer.parseInt(gemsString); + + if (gems > 1000) + { + UtilPlayer.message(caller, F.main("Gem", "You can only give everybody 1000 gems at a time.")); + return; + } + + rewardAllGems(caller, gems); + } + catch (Exception e) + { + UtilPlayer.message(caller, F.main("Gem", "Invalid gems Amount")); + } + } + + private void rewardAllGems(Player caller, int gems) + { + for (Player player : UtilServer.getPlayers()) + { + Plugin.RewardGems(new Callback() + { + public void run(Boolean completed) + { + + } + }, caller.getName(), player.getName(), player.getUniqueId(), gems); + } + + UtilPlayer.message(caller, F.main("Gem", "Gave everyone " + F.elem(gems + " gems"))); + } + private void rewardGems(final Player caller, final Player target, final String targetName, final UUID uuid, String gemsString) { try diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/command/ShardCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/command/ShardCommand.java index c65df1a4a..cbe9dc269 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/command/ShardCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/command/ShardCommand.java @@ -6,8 +6,8 @@ import mineplex.core.common.Rank; import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.core.donation.DonationManager; - import org.bukkit.entity.Player; public class ShardCommand extends CommandBase @@ -30,7 +30,11 @@ public class ShardCommand extends CommandBase final String coinsString = args[1]; Player target = UtilPlayer.searchExact(targetName); - if (target == null) + if (targetName.equalsIgnoreCase("@a")) + { + rewardAllShards(caller, coinsString); + } + else if (target == null) { Plugin.getClientManager().loadClientByName(targetName, new Runnable() { @@ -53,6 +57,44 @@ public class ShardCommand extends CommandBase } } + private void rewardAllShards(Player caller, String shardsString) + { + try + { + int shards = Integer.parseInt(shardsString); + + if (shards > 1000) + { + UtilPlayer.message(caller, F.main("Shards", "You can only give everybody 1000 shards at a time.")); + return; + } + + rewardAllShards(caller, shards); + } + catch (Exception e) + { + UtilPlayer.message(caller, F.main("Shards", "Invalid Shards Amount")); + } + } + + private void rewardAllShards(Player caller, int shards) + { + for (Player player : UtilServer.getPlayers()) + { + CoreClient client = Plugin.getClientManager().Get(player); + + Plugin.RewardCoins(new Callback() + { + public void run(Boolean completed) + { + + } + }, caller.getName(), player.getName(), client.getAccountId(), shards); + } + + UtilPlayer.message(caller, F.main("Shards", "Gave everyone " + F.elem(shards + " Treasure Shards"))); + } + private void rewardCoins(final Player caller, final Player target, final String targetName, final int accountId, String coinsString) { try diff --git a/Plugins/Mineplex.Core/src/mineplex/core/inventory/command/GiveItemCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/inventory/command/GiveItemCommand.java index 94e726ad8..b5f03fe3e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/inventory/command/GiveItemCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/inventory/command/GiveItemCommand.java @@ -9,6 +9,7 @@ import mineplex.core.common.Rank; import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.core.inventory.InventoryManager; import mineplex.core.inventory.data.Item; @@ -47,6 +48,15 @@ public class GiveItemCommand extends CommandBase { UtilPlayer.message(caller, F.main("Item", "Item with the name " + F.item(itemName) + " not found!")); } + else if (playerName.equalsIgnoreCase("@a")) + { + for (Player pl : UtilServer.getPlayers()) + { + Plugin.addItemToInventory(pl, item.Name, amount); + } + + UtilPlayer.message(caller, F.main("Item", "You gave " + F.elem(amount + " " + itemName) + " to everyone")); + } else if (player != null) { Plugin.addItemToInventory(player, item.Name, amount);