From 2fcf01a7dee943a1fd81a769b502c24e5755e048 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sun, 29 Dec 2019 20:03:21 -0600 Subject: [PATCH] Added edit_tunnel command + Supported by the add_tunnel command + I hate past me sometimes --- .../geoffrey/Commands/AddTunnelCommand.java | 33 +++++++++++++++---- .../com/zerohighdef/geoffrey/GeoffreyMC.java | 3 ++ src/main/resources/plugin.yml | 5 +++ 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/AddTunnelCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/AddTunnelCommand.java index 487b52d..c0510a1 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/AddTunnelCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/AddTunnelCommand.java @@ -1,7 +1,9 @@ package com.zerohighdef.geoffrey.Commands; import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import com.zerohighdef.geoffrey.GeoffreyMC; +import com.zerohighdef.geoffrey.Models.GeoffreyLocation; import com.zerohighdef.geoffrey.Models.GeoffreyTunnel; import com.zerohighdef.geoffrey.Objects.GeoffreyAPICallback; import com.zerohighdef.geoffrey.Objects.GeoffreyCommand; @@ -24,15 +26,25 @@ public class AddTunnelCommand extends GeoffreyCommand { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + String commmandName; + + if (label.contains("edit")) { + commmandName = "edit_tunnel"; + } + else { + commmandName = "add_tunnel"; + } if ((sender instanceof Player)) { Map params = new HashMap(); - if (args.length > 2) { - String name[] = Arrays.copyOfRange(args, 2, args.length); - params.put("location_name", StringUtils.join(name, " ")); + if (args.length >= 3) { + String name[] = Arrays.copyOfRange(args, 3, args.length); + // this is a hack + String paramName = (commmandName.compareTo("edit_tunnel") == 0) ? "loc_name" : "location_name"; + params.put(paramName, StringUtils.join(name, " ")); } - else if (args.length < 2) { + else { sender.sendMessage(ChatColor.RED + "Too few parameters given."); return false; } @@ -54,7 +66,7 @@ public class AddTunnelCommand extends GeoffreyCommand { params.put("mc_uuid", player.getUniqueId().toString().replace("-", "")); params.put("tunnel_direction", tunnelDirection); params.put("tunnel_number", tunnelNumber); - RunCommand("add_tunnel", params, GeoffreyCommand.Method.POST , new CommandCallback(sender, tunnelDirection)); + RunCommand(commmandName, params, GeoffreyCommand.Method.POST , new CommandCallback(sender, tunnelDirection)); } else { @@ -77,9 +89,16 @@ public class AddTunnelCommand extends GeoffreyCommand { public void invoke(String s) { try { JsonElement json = parseJSON(s); + JsonObject jsonObj = json.getAsJsonObject(); + String locationName; + if (jsonObj.has("type")) { + locationName = new GeoffreyLocation(jsonObj).getLocationName(); + } + else { + locationName = new GeoffreyTunnel(jsonObj).getLocationName(); + } - GeoffreyTunnel geoffreyTunnel = new GeoffreyTunnel(json.getAsJsonObject()); - String msg = ChatColor.GREEN + "A tunnel has been added to " + geoffreyTunnel.getLocationName(); + String msg = ChatColor.GREEN + "The tunnel has been updated for " + locationName; commandSender.sendMessage(msg); } catch (GeoffreyCommandError e) { diff --git a/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java b/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java index 8bf988e..7a0c642 100644 --- a/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java +++ b/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java @@ -70,6 +70,9 @@ public final class GeoffreyMC extends JavaPlugin { EditPosCommand editPosCommand = new EditPosCommand(this); this.getCommand("geoffrey_edit_pos").setExecutor(editPosCommand); + + AddTunnelCommand editTunnelCommand = new AddTunnelCommand(this); + this.getCommand("geoffrey_edit_tunnel").setExecutor(editTunnelCommand); } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4acf84f..a6dbd4b 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -101,6 +101,11 @@ commands: aliases: [edit_pos] permission: geoffrey.add usage: /edit_pos [location name] + geoffrey_edit_tunnel: + description: Updates a location's tunnel in Geoffrey + aliases: [edit_tunnel] + permission: geoffrey.add + usage: /edit_tunnel [tunnel direction] [tunnel number] [location name] permissions: add: