forked from Geoffrey/Geoffrey-MC-Plugin
69 lines
2.2 KiB
Java
69 lines
2.2 KiB
Java
package com.zerohighdef.geoffrey.Commands;
|
|
|
|
|
|
import com.google.gson.JsonElement;
|
|
import com.zerohighdef.geoffrey.GeoffreyMC;
|
|
import com.zerohighdef.geoffrey.Objects.GeoffreyAPICallback;
|
|
import com.zerohighdef.geoffrey.Objects.GeoffreyCommand;
|
|
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.HashMap;
|
|
import java.util.Map;
|
|
|
|
public class DeleteCommand extends GeoffreyCommand {
|
|
public DeleteCommand(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 == 0) {
|
|
sender.sendMessage(ChatColor.RED + "Too few parameters");
|
|
return false;
|
|
}
|
|
|
|
Player player = ((Player) sender).getPlayer();
|
|
String locationNmae = StringUtils.join(args, " ");
|
|
params.put("name", locationNmae);
|
|
params.put("mc_uuid", player.getUniqueId().toString().replace("-", ""));
|
|
RunCommand("delete", params, Method.POST , new CommandCallback(sender, locationNmae));
|
|
}
|
|
else {
|
|
sender.sendMessage(ChatColor.RED + "Console can not add locations!");
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private class CommandCallback extends GeoffreyAPICallback {
|
|
|
|
CommandCallback(CommandSender sender, String locationName) {
|
|
super(sender);
|
|
errors.put("LocationLookUpError", "You do not have a location by the name " + locationName + "!");
|
|
}
|
|
|
|
@Override
|
|
public void invoke(String s) {
|
|
try {
|
|
JsonElement json = parseJSON(s);
|
|
|
|
String msg = ChatColor.GREEN + json.getAsString() + " has been deleted, good riddance!";
|
|
commandSender.sendMessage(msg);
|
|
}
|
|
catch (GeoffreyCommandError e) {
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|