Added find_around command

pull/2/head
Joey Hines 2020-01-07 09:45:35 -06:00
parent 2fcf01a7de
commit 2d5e0109ea
3 changed files with 73 additions and 0 deletions

View File

@ -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<String, String> params = new HashMap<String, String>();
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;
}
}
}
}

View File

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

View File

@ -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: