Added find_farm command

pull/2/head
Joey Hines 2020-01-07 09:55:06 -06:00
parent 2d5e0109ea
commit 6cf0cf5976
5 changed files with 70 additions and 1 deletions

View File

@ -55,7 +55,7 @@ public class FindAroundCommand extends GeoffreyCommand {
public void invoke(String s) { public void invoke(String s) {
try { try {
JsonElement json = parseJSON(s); 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); commandSender.sendMessage(ChatColor.GREEN + msg);
} }
catch (GeoffreyCommandError e) { catch (GeoffreyCommandError e) {

View File

@ -31,6 +31,7 @@ public class FindCommand extends GeoffreyCommand {
} }
else { else {
sender.sendMessage(ChatColor.RED + "You must specify a location or player name."); sender.sendMessage(ChatColor.RED + "You must specify a location or player name.");
return false;
} }
return true; return true;

View File

@ -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;
}
}
}
}

View File

@ -76,6 +76,9 @@ public final class GeoffreyMC extends JavaPlugin {
FindAroundCommand findAroundCommand = new FindAroundCommand(this); FindAroundCommand findAroundCommand = new FindAroundCommand(this);
this.getCommand("geoffrey_find_around").setExecutor(findAroundCommand); this.getCommand("geoffrey_find_around").setExecutor(findAroundCommand);
FindFarmCommand findFarmCommand = new FindFarmCommand(this);
this.getCommand("geoffrey_find_farm").setExecutor(findFarmCommand);
} }
} }

View File

@ -110,6 +110,10 @@ commands:
description: Finds locations around your current position description: Finds locations around your current position
aliases: [find_around] aliases: [find_around]
usage: /find_around [radius] usage: /find_around [radius]
geoffrey_find_farm:
description: Finds a farm producing a resource
aliases: [find_farm]
usage: /find_farm [resource name]
permissions: permissions:
add: add: