From 01d44cd25007217c76da32ca11ba11f3339895a1 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Mon, 27 Oct 2014 19:25:59 -0500 Subject: [PATCH] Give Item Command --- .../core/inventory/InventoryManager.java | 7 ++ .../inventory/command/GiveItemCommand.java | 70 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/inventory/command/GiveItemCommand.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/inventory/InventoryManager.java b/Plugins/Mineplex.Core/src/mineplex/core/inventory/InventoryManager.java index 09d37e81b..2bddb80eb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/inventory/InventoryManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/inventory/InventoryManager.java @@ -9,6 +9,7 @@ import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniClientPlugin; import mineplex.core.account.event.RetrieveClientInformationEvent; import mineplex.core.common.util.NautHashMap; +import mineplex.core.inventory.command.GiveItemCommand; import mineplex.core.inventory.data.Category; import mineplex.core.inventory.data.InventoryRepository; import mineplex.core.inventory.data.Item; @@ -129,4 +130,10 @@ public class InventoryManager extends MiniClientPlugin } }); } + + @Override + public void AddCommands() + { + AddCommand(new GiveItemCommand(this)); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/inventory/command/GiveItemCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/inventory/command/GiveItemCommand.java new file mode 100644 index 000000000..bf6303d14 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/inventory/command/GiveItemCommand.java @@ -0,0 +1,70 @@ +package mineplex.core.inventory.command; + +import java.util.UUID; + +import org.bukkit.entity.Player; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UUIDFetcher; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.inventory.InventoryManager; + +/** + * Created by Shaun on 10/26/2014. + */ +public class GiveItemCommand extends CommandBase +{ + public GiveItemCommand(InventoryManager plugin) + { + super(plugin, Rank.ADMIN, "giveitem"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if (args == null || args.length < 3) + { + displayUsage(caller); + return; + } + + final String playerName = args[0]; + final int amount = Integer.parseInt(args[1]); + String tempItemName = ""; + for (int i = 2; i < args.length; i++) + { + tempItemName += args[i] + " "; + } + final String itemName = tempItemName.trim(); + + Player player = UtilPlayer.searchExact(playerName); + + if (player != null) + { + Plugin.addItemToInventory(player, "Item", itemName, amount); + UtilPlayer.message(caller, F.main("Item", "You gave " + F.elem(amount + " " + itemName) + " to player " + F.name(playerName))); + UtilPlayer.message(player, F.main("Item", F.name(caller.getName()) + " gave you " + F.elem(amount + " " + itemName))); + } + else + { + UUID uuid = UUIDFetcher.getUUIDOf(playerName); + if (uuid != null) + { + Plugin.addItemToInventoryForOffline(uuid.toString(), "Item", itemName, amount); + UtilPlayer.message(caller, F.main("Item", "You gave " + F.elem(amount + " " + itemName) + " to offline player " + F.name(playerName))); + } + else + { + UtilPlayer.message(caller, F.main("Item", "Player " + F.name(playerName) + " does not exist!")); + } + } + } + + public void displayUsage(Player caller) + { + UtilPlayer.message(caller, F.main("Item", "Usage: " + F.elem("/giveitem "))); + } +} \ No newline at end of file