Give Item Command

This commit is contained in:
Shaun Bennett 2014-10-27 19:25:59 -05:00
parent a1c4b8840f
commit 01d44cd250
2 changed files with 77 additions and 0 deletions

View File

@ -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<ClientInventory>
}
});
}
@Override
public void AddCommands()
{
AddCommand(new GiveItemCommand(this));
}
}

View File

@ -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<InventoryManager>
{
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 <playername> <item name> <amount>")));
}
}