forked from Geoffrey/Geoffrey-MC-Plugin
Added delete_item command
parent
6088b84b72
commit
3c15b9e770
|
@ -0,0 +1,80 @@
|
|||
package com.zerohighdef.geoffrey.Commands;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.zerohighdef.geoffrey.GeoffreyMC;
|
||||
import com.zerohighdef.geoffrey.Models.GeoffreyLocation;
|
||||
import com.zerohighdef.geoffrey.Models.GeoffreyShop;
|
||||
import com.zerohighdef.geoffrey.Objects.GeoffreyAPICallback;
|
||||
import com.zerohighdef.geoffrey.Objects.GeoffreyCommandError;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DeleteItemCommand extends GeoffreyCommand{
|
||||
public DeleteItemCommand(GeoffreyMC plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if ((sender instanceof Player)) {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
|
||||
if (args.length > 1) {
|
||||
String name[] = Arrays.copyOfRange(args, 1, args.length-1);
|
||||
params.put("shop_name", StringUtils.join(name, " "));
|
||||
}
|
||||
else if (args.length == 0) {
|
||||
sender.sendMessage(ChatColor.RED + "Too few parameters given.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = ((Player) sender).getPlayer();
|
||||
String itemName = args[0];
|
||||
|
||||
params.put("mc_uuid", player.getUniqueId().toString().replace("-", ""));
|
||||
params.put("item", itemName);
|
||||
RunCommand("delete_item", params, Method.POST , new CommandCallback(sender, itemName));
|
||||
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(ChatColor.RED + "Console can not add items!");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private class CommandCallback extends GeoffreyAPICallback {
|
||||
String itemName;
|
||||
|
||||
CommandCallback(CommandSender sender, String itemName) {
|
||||
super(sender);
|
||||
this.itemName = itemName;
|
||||
errors.put("LocationLookUpError", "You do not have a shop by that name, goober.");
|
||||
errors.put("EntryNameNotUniqueError", "You have more than one location. Please specify a name, dingus.");
|
||||
errors.put("ItemNotFound", "Your shop does not sell " + itemName + ". Try again buddy boi!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String s) {
|
||||
try {
|
||||
JsonElement json = parseJSON(s);
|
||||
|
||||
GeoffreyLocation geoffreyLocation = new GeoffreyLocation(json.getAsJsonObject());
|
||||
String msg = ChatColor.GREEN + itemName + " has been deleted from " + geoffreyLocation.getLocationName() + ".";
|
||||
commandSender.sendMessage(msg);
|
||||
}
|
||||
catch (GeoffreyCommandError e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -56,6 +56,9 @@ public final class GeoffreyMC extends JavaPlugin {
|
|||
|
||||
DeleteCommand deleteCommand = new DeleteCommand(this);
|
||||
this.getCommand("geoffrey_delete").setExecutor(deleteCommand);
|
||||
|
||||
DeleteItemCommand deleteItemCommand = new DeleteItemCommand(this);
|
||||
this.getCommand("geoffrey_delete_item").setExecutor(deleteItemCommand);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -81,6 +81,11 @@ commands:
|
|||
aliases: [delete]
|
||||
permission: geoffrey.add
|
||||
usage: /delete [location name]
|
||||
geoffrey_delete_item:
|
||||
description: Deletes an item from a shop in Geoffrey
|
||||
aliases: [delete_item]
|
||||
permission: geoffrey.add
|
||||
usage: /delete [item name] [shop name]
|
||||
|
||||
permissions:
|
||||
add:
|
||||
|
|
Loading…
Reference in New Issue