71 lines
2.1 KiB
Java
71 lines
2.1 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 java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
public class SellingCommand extends GeoffreyCommand {
|
|
|
|
public SellingCommand(GeoffreyMC plugin) {
|
|
super(plugin);
|
|
}
|
|
|
|
@Override
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
|
|
if (args.length > 0) {
|
|
String item = StringUtils.join(args, " ").replace("\"", "");
|
|
String commandName;
|
|
|
|
if (command.getName().contains("price")) {
|
|
commandName = "selling_price";
|
|
}
|
|
else {
|
|
commandName = "selling";
|
|
}
|
|
|
|
Map<String, String> params = new HashMap<String, String>();
|
|
|
|
params.put("item_name", item);
|
|
RunCommand(commandName, params, Method.GET ,new CommandCallback(sender, item));
|
|
}
|
|
else {
|
|
sender.sendMessage(ChatColor.RED + "You must specify what item you are looking to buy!");
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
private class CommandCallback extends GeoffreyAPICallback {
|
|
private String item;
|
|
|
|
CommandCallback(CommandSender sender, String item) {
|
|
super(sender);
|
|
errors.put("ItemNotFound", "No shop was found selling " + item);
|
|
this.item = item;
|
|
}
|
|
|
|
@Override
|
|
public void invoke(String s) {
|
|
try {
|
|
JsonElement json = parseJSON(s);
|
|
String msg = ChatColor.BOLD + "The following shops sell " + item + ":\n" + ChatColor.RESET + sellingList(json, 5);
|
|
commandSender.sendMessage(ChatColor.GREEN + msg);
|
|
}
|
|
catch (GeoffreyCommandError e) {
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
} |