diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/FindAroundCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/FindAroundCommand.java index 2fc3a34..ca3bb6d 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/FindAroundCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/FindAroundCommand.java @@ -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) { diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/FindCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/FindCommand.java index 84561b0..580ac09 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/FindCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/FindCommand.java @@ -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; diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/FindFarmCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/FindFarmCommand.java new file mode 100644 index 0000000..2b699ab --- /dev/null +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/FindFarmCommand.java @@ -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 params = new HashMap(); + + 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; + } + } + } +} diff --git a/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java b/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java index 5402da0..0686309 100644 --- a/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java +++ b/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java @@ -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); } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index c254231..1b323a0 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -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: