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