64 lines
1.8 KiB
Java
64 lines
1.8 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.GeoffreyCommandError;
|
|
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) {
|
|
String item = args[0];
|
|
String commandName = "selling";
|
|
|
|
if (args.length > 1) {
|
|
String sort = args[1];
|
|
|
|
if (sort.compareToIgnoreCase("price") == 0) {
|
|
commandName = "selling_price";
|
|
}
|
|
}
|
|
|
|
Map <String, String> params = new HashMap<String, String>();
|
|
|
|
params.put("item_name", item);
|
|
RunCommand(commandName, params, new CommandCallback(sender, item));
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
} |