Added find_farm command
parent
2d5e0109ea
commit
6cf0cf5976
|
@ -55,7 +55,7 @@ public class FindAroundCommand extends GeoffreyCommand {
|
|||
public void invoke(String s) {
|
||||
try {
|
||||
JsonElement json = parseJSON(s);
|
||||
String msg = ChatColor.BOLD + "The following locations are around your position\n" + ChatColor.RESET + locationList(json, 5);
|
||||
String msg = ChatColor.BOLD + "The following locations are around your position:\n" + ChatColor.RESET + locationList(json, 5);
|
||||
commandSender.sendMessage(ChatColor.GREEN + msg);
|
||||
}
|
||||
catch (GeoffreyCommandError e) {
|
||||
|
|
|
@ -31,6 +31,7 @@ public class FindCommand extends GeoffreyCommand {
|
|||
}
|
||||
else {
|
||||
sender.sendMessage(ChatColor.RED + "You must specify a location or player name.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
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 FindFarmCommand extends GeoffreyCommand {
|
||||
public FindFarmCommand(GeoffreyMC plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if (args.length > 0) {
|
||||
String resourceName = StringUtils.join(args, " ");
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
|
||||
params.put("resource_name", resourceName);
|
||||
RunCommand("find_farm", params, Method.GET, new CommandCallback(sender, resourceName));
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(ChatColor.RED + "You must specify a resource name.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private class CommandCallback extends GeoffreyAPICallback {
|
||||
private String resourceName;
|
||||
|
||||
CommandCallback(CommandSender sender, String resourceName) {
|
||||
super(sender);
|
||||
this.resourceName = resourceName;
|
||||
errors.put("ResourceNotFoundError", "No farms found that produce " + this.resourceName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String s) {
|
||||
try {
|
||||
JsonElement json = parseJSON(s);
|
||||
String msg = ChatColor.BOLD + "The following farms produce " + resourceName + ":\n" + ChatColor.RESET + locationList(json, 5);
|
||||
commandSender.sendMessage(ChatColor.GREEN + msg);
|
||||
}
|
||||
catch (GeoffreyCommandError e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -76,6 +76,9 @@ public final class GeoffreyMC extends JavaPlugin {
|
|||
|
||||
FindAroundCommand findAroundCommand = new FindAroundCommand(this);
|
||||
this.getCommand("geoffrey_find_around").setExecutor(findAroundCommand);
|
||||
|
||||
FindFarmCommand findFarmCommand = new FindFarmCommand(this);
|
||||
this.getCommand("geoffrey_find_farm").setExecutor(findFarmCommand);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -110,6 +110,10 @@ commands:
|
|||
description: Finds locations around your current position
|
||||
aliases: [find_around]
|
||||
usage: /find_around [radius]
|
||||
geoffrey_find_farm:
|
||||
description: Finds a farm producing a resource
|
||||
aliases: [find_farm]
|
||||
usage: /find_farm [resource name]
|
||||
|
||||
permissions:
|
||||
add:
|
||||
|
|
Loading…
Reference in New Issue