From 2cecd8d0c56ac8fe7a96724be3e2e8bfb8f213bf Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sun, 29 Dec 2019 10:46:04 -0600 Subject: [PATCH] Added missing files --- .../geoffrey/Commands/AddTunnelCommand.java | 90 +++++++++++++++++++ .../geoffrey/Commands/DeleteCommand.java | 67 ++++++++++++++ .../com/zerohighdef/geoffrey/GeoffreyMC.java | 6 ++ .../geoffrey/Objects/GeoffreyAPICallback.java | 4 +- src/main/resources/plugin.yml | 10 +++ 5 files changed, 175 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/zerohighdef/geoffrey/Commands/AddTunnelCommand.java create mode 100644 src/main/java/com/zerohighdef/geoffrey/Commands/DeleteCommand.java diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/AddTunnelCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/AddTunnelCommand.java new file mode 100644 index 0000000..6a54f9e --- /dev/null +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/AddTunnelCommand.java @@ -0,0 +1,90 @@ +package com.zerohighdef.geoffrey.Commands; + +import com.google.gson.JsonElement; +import com.zerohighdef.geoffrey.GeoffreyMC; +import com.zerohighdef.geoffrey.Models.GeoffreyResource; +import com.zerohighdef.geoffrey.Models.GeoffreyTunnel; +import com.zerohighdef.geoffrey.Objects.GeoffreyAPICallback; +import com.zerohighdef.geoffrey.Objects.GeoffreyCommandError; +import org.apache.commons.lang.StringUtils; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +public class AddTunnelCommand extends GeoffreyCommand{ + + public AddTunnelCommand(GeoffreyMC plugin) { + super(plugin); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + 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, " ")); + } + else if (args.length < 2) { + sender.sendMessage(ChatColor.RED + "Too few parameters given."); + return false; + } + + Player player = ((Player) sender).getPlayer(); + + + try { + Integer.parseInt(args[1]); + } + catch (NumberFormatException e) { + sender.sendMessage(ChatColor.RED + "Tunnel number must be an integer value!"); + return false; + } + + String tunnelDirection = args[0]; + String tunnelNumber = args[1]; + + 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)); + + } + else { + sender.sendMessage(ChatColor.RED + "Console can not add items!"); + } + + return true; + } + + private class CommandCallback extends GeoffreyAPICallback { + + CommandCallback(CommandSender sender, String tunnelDirection) { + super(sender); + errors.put("InvalidTunnelError", tunnelDirection + " is not a valid tunnel direction ya gub"); + errors.put("LocationLookUpError", "You do not have a location by that name, goober."); + errors.put("EntryNameNotUniqueError", "You have more than one location. Please specify a name, dingus."); + } + + @Override + public void invoke(String s) { + try { + JsonElement json = parseJSON(s); + + GeoffreyTunnel geoffreyTunnel = new GeoffreyTunnel(json.getAsJsonObject()); + String msg = ChatColor.GREEN + "A tunnel has been added to " + geoffreyTunnel.getLocationName(); + commandSender.sendMessage(msg); + } + catch (GeoffreyCommandError e) { + return; + } + } + } +} diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/DeleteCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/DeleteCommand.java new file mode 100644 index 0000000..fa3ce81 --- /dev/null +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/DeleteCommand.java @@ -0,0 +1,67 @@ +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.GeoffreyCommandError; +import org.apache.commons.lang.StringUtils; +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 DeleteCommand extends GeoffreyCommand { + public DeleteCommand(GeoffreyMC plugin) { + super(plugin); + } + + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + if ((sender instanceof Player)) { + Map params = new HashMap(); + + if (args.length == 0) { + sender.sendMessage(ChatColor.RED + "Too few parameters"); + return false; + } + + Player player = ((Player) sender).getPlayer(); + String locationNmae = StringUtils.join(args, " "); + params.put("name", locationNmae); + params.put("mc_uuid", player.getUniqueId().toString().replace("-", "")); + RunCommand("delete", params, Method.POST , new CommandCallback(sender, locationNmae)); + } + else { + sender.sendMessage(ChatColor.RED + "Console can not add locations!"); + } + + return true; + } + + private class CommandCallback extends GeoffreyAPICallback { + + CommandCallback(CommandSender sender, String locationName) { + super(sender); + errors.put("LocationLookUpError", "You do not have a location by the name " + locationName + "!"); + } + + @Override + public void invoke(String s) { + try { + JsonElement json = parseJSON(s); + + String msg = ChatColor.GREEN + json.getAsString() + " has been deleted, good riddance!"; + commandSender.sendMessage(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 c4e2d47..feac043 100644 --- a/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java +++ b/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java @@ -50,6 +50,12 @@ public final class GeoffreyMC extends JavaPlugin { AddResourceCommand addResourceCommand = new AddResourceCommand(this); this.getCommand("geoffrey_add_resource").setExecutor(addResourceCommand); + + AddTunnelCommand addTunnelCommand = new AddTunnelCommand(this); + this.getCommand("geoffrey_add_tunnel").setExecutor(addTunnelCommand); + + DeleteCommand deleteCommand = new DeleteCommand(this); + this.getCommand("geoffrey_delete").setExecutor(deleteCommand); } } diff --git a/src/main/java/com/zerohighdef/geoffrey/Objects/GeoffreyAPICallback.java b/src/main/java/com/zerohighdef/geoffrey/Objects/GeoffreyAPICallback.java index 1c2628a..3e23f16 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Objects/GeoffreyAPICallback.java +++ b/src/main/java/com/zerohighdef/geoffrey/Objects/GeoffreyAPICallback.java @@ -25,8 +25,8 @@ public abstract class GeoffreyAPICallback implements ICallback { errors.put("PlayerNotFound", "You are not in the database, you must register first!"); errors.put("NoLocationsInDatabase", "You have no locations in the database, you must add some first!"); errors.put("DataError", "Slow down their slugger, that's a long word or number you are trying to cram into me, try again with something smaller, please"); - errors.put("LocationHasTunnelError", "that location already has a tunnel you goober."); - errors.put( "EntryNameNotUniqueError", "that name has already been used, be more creative dingus kong"); + errors.put("LocationHasTunnelError", "That location already has a tunnel you goober."); + errors.put( "EntryNameNotUniqueError", "That name has already been used, be more creative dingus kong"); } protected JsonElement parseJSON(String string) throws GeoffreyCommandError { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 16cbd15..ba88f28 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -71,6 +71,16 @@ commands: aliases: [add_resource] permission: geoffrey.add usage: /add_resource [resource name] [farm name] + geoffrey_add_tunnel: + description: Adds a tunnel to a location + aliases: [add_tunnel] + permission: geoffrey.add + usage: /add_tunnel [tunnel direction] [tunnel number] [location name] + geoffrey_delete: + description: Deletes a location in Geoffrey + aliases: [delete] + permission: geoffrey.add + usage: /delete [location name] permissions: add: