forked from Geoffrey/Geoffrey-MC-Plugin
77 lines
2.7 KiB
Java
77 lines
2.7 KiB
Java
package com.zerohighdef.geoffrey.Commands;
|
|
|
|
import com.google.gson.JsonElement;
|
|
import com.zerohighdef.geoffrey.GeoffreyMC;
|
|
import com.zerohighdef.geoffrey.Models.GeoffreyPlayer;
|
|
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.Arrays;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
public class AddResidentCommand extends GeoffreyCommand {
|
|
|
|
public AddResidentCommand(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);
|
|
params.put("town_name", StringUtils.join(name, " "));
|
|
Player player = ((Player) sender).getPlayer();
|
|
|
|
params.put("mc_uuid", player.getUniqueId().toString().replace("-", ""));
|
|
params.put("new_resident_name", args[0]);
|
|
RunCommand("add_resident", params, Method.POST , new CommandCallback(sender, args[0]));
|
|
}
|
|
else if (args.length < 2) {
|
|
sender.sendMessage(ChatColor.RED + "Too few parameters given.");
|
|
return false;
|
|
}
|
|
}
|
|
else {
|
|
sender.sendMessage(ChatColor.RED + "Console cannot add residents!");
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private class CommandCallback extends GeoffreyAPICallback {
|
|
private String newResidentName;
|
|
|
|
CommandCallback(CommandSender sender, String newResidentName) {
|
|
super(sender);
|
|
errors.put("ResidentNotFoundError", "Ain't no one in this darn database named " + newResidentName + " you goob");
|
|
errors.put("IsResidentError", newResidentName + " is already a resident, stop having amosia.");
|
|
errors.put("LocationLookUpError", "You do not have a town by that name you ding dong goober.");
|
|
this.newResidentName = newResidentName;
|
|
}
|
|
|
|
@Override
|
|
public void invoke(String s) {
|
|
try {
|
|
JsonElement json = parseJSON(s);
|
|
|
|
String msg = ChatColor.GREEN + newResidentName + " has been added to your town.";
|
|
commandSender.sendMessage(msg);
|
|
}
|
|
catch (GeoffreyCommandError e) {
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|