Added edit_tunnel command

+ Supported by the add_tunnel command
+ I hate past me sometimes
pull/2/head
Joey Hines 2019-12-29 20:03:21 -06:00
parent 7ecdb7b283
commit 2fcf01a7de
3 changed files with 34 additions and 7 deletions

View File

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

View File

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

View File

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