From 2d5e0109eaf481fd07f1c141a18dd782c3e3864b Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Tue, 7 Jan 2020 09:45:35 -0600 Subject: [PATCH] Added find_around command --- .../geoffrey/Commands/FindAroundCommand.java | 66 +++++++++++++++++++ .../com/zerohighdef/geoffrey/GeoffreyMC.java | 3 + src/main/resources/plugin.yml | 4 ++ 3 files changed, 73 insertions(+) create mode 100644 src/main/java/com/zerohighdef/geoffrey/Commands/FindAroundCommand.java diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/FindAroundCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/FindAroundCommand.java new file mode 100644 index 0000000..2fc3a34 --- /dev/null +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/FindAroundCommand.java @@ -0,0 +1,66 @@ +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.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; + +public class FindAroundCommand extends GeoffreyCommand { + + public FindAroundCommand(GeoffreyMC plugin) { + super(plugin); + } + + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (sender instanceof Player) { + int radius = 200; + Map params = new HashMap(); + if (args.length > 0) { + try { + radius = Integer.parseInt(args[0]); + } catch (NumberFormatException e) { + sender.sendMessage(ChatColor.RED + "Radius must be an integer value!"); + return false; + } + } + Player player = ((Player) sender).getPlayer(); + params.put("radius", Integer.toString(radius)); + params.put("x_pos", Integer.toString(player.getLocation().getBlockX())); + params.put("z_pos", Integer.toString(player.getLocation().getBlockZ())); + RunCommand("find_around", params, Method.GET, new CommandCallback(sender, radius)); + } else { + sender.sendMessage(ChatColor.RED + "Console can't use the find_around command"); + } + return true; + } + + + private class CommandCallback extends GeoffreyAPICallback { + CommandCallback(CommandSender sender, int radius) { + super(sender); + errors.put("LocationLookUpError", "There are no locations within " + radius + " blocks of your position."); + } + + @Override + 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); + 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 7a0c642..5402da0 100644 --- a/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java +++ b/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java @@ -73,6 +73,9 @@ public final class GeoffreyMC extends JavaPlugin { AddTunnelCommand editTunnelCommand = new AddTunnelCommand(this); this.getCommand("geoffrey_edit_tunnel").setExecutor(editTunnelCommand); + + FindAroundCommand findAroundCommand = new FindAroundCommand(this); + this.getCommand("geoffrey_find_around").setExecutor(findAroundCommand); } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index a6dbd4b..c254231 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -106,6 +106,10 @@ commands: aliases: [edit_tunnel] permission: geoffrey.add usage: /edit_tunnel [tunnel direction] [tunnel number] [location name] + geoffrey_find_around: + description: Finds locations around your current position + aliases: [find_around] + usage: /find_around [radius] permissions: add: