From e56518431e964d3389171f764b020697cdb1f679 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Wed, 8 Jan 2020 14:04:30 -0600 Subject: [PATCH] Added tunnel and restock commands + Added punctuation to some messages --- .../geoffrey/Commands/AddLocationCommand.java | 2 +- .../geoffrey/Commands/AddOwnerCommand.java | 2 +- .../geoffrey/Commands/AddResidentCommand.java | 2 +- .../geoffrey/Commands/AddTunnelCommand.java | 2 +- .../geoffrey/Commands/EditNameCommand.java | 2 +- .../geoffrey/Commands/FindCommand.java | 2 +- .../geoffrey/Commands/FindFarmCommand.java | 2 +- .../geoffrey/Commands/InfoCommand.java | 2 +- .../geoffrey/Commands/LocationsCommand.java | 2 +- .../Commands/RemoveResidentCommand.java | 2 +- .../geoffrey/Commands/RestockCommand.java | 90 +++++++++++++++++++ .../geoffrey/Commands/TunnelCommand.java | 71 +++++++++++++++ .../com/zerohighdef/geoffrey/GeoffreyMC.java | 6 ++ src/main/resources/plugin.yml | 10 +++ 14 files changed, 187 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/zerohighdef/geoffrey/Commands/RestockCommand.java create mode 100644 src/main/java/com/zerohighdef/geoffrey/Commands/TunnelCommand.java diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/AddLocationCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/AddLocationCommand.java index ec2aec5..c492ed0 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/AddLocationCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/AddLocationCommand.java @@ -60,7 +60,7 @@ public class AddLocationCommand extends GeoffreyCommand { JsonElement json = parseJSON(s); GeoffreyLocation location = new GeoffreyLocation(json.getAsJsonObject()); - String msg = ChatColor.GREEN + location.getLocationName() + " has been added to Geoffrey"; + String msg = ChatColor.GREEN + location.getLocationName() + " has been added to Geoffrey."; commandSender.sendMessage(msg); } catch (GeoffreyCommandError e) { diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/AddOwnerCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/AddOwnerCommand.java index b9683ec..000d347 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/AddOwnerCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/AddOwnerCommand.java @@ -66,7 +66,7 @@ public class AddOwnerCommand extends GeoffreyCommand { JsonElement json = parseJSON(s); GeoffreyLocation location = new GeoffreyLocation(json.getAsJsonObject()); - String msg = ChatColor.GREEN + new_owner_name + " has been added as an owner of " + location.getLocationName(); + String msg = ChatColor.GREEN + new_owner_name + " has been added as an owner of " + location.getLocationName() + "."; commandSender.sendMessage(msg); } catch (GeoffreyCommandError e) { diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/AddResidentCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/AddResidentCommand.java index cc4ed05..ec27214 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/AddResidentCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/AddResidentCommand.java @@ -65,7 +65,7 @@ public class AddResidentCommand extends GeoffreyCommand { try { JsonElement json = parseJSON(s); - String msg = ChatColor.GREEN + newResidentName + "has been added to your town"; + String msg = ChatColor.GREEN + newResidentName + "has been added to your town."; commandSender.sendMessage(msg); } catch (GeoffreyCommandError e) { diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/AddTunnelCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/AddTunnelCommand.java index d6ec7eb..241d5f3 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/AddTunnelCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/AddTunnelCommand.java @@ -80,7 +80,7 @@ public class AddTunnelCommand extends GeoffreyCommand { CommandCallback(CommandSender sender, String tunnelDirection) { super(sender); - errors.put("InvalidTunnelError", tunnelDirection + " is not a valid tunnel direction ya gub"); + 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."); } diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/EditNameCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/EditNameCommand.java index e23e44a..67957ed 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/EditNameCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/EditNameCommand.java @@ -63,7 +63,7 @@ public class EditNameCommand extends GeoffreyCommand { CommandCallback(CommandSender sender, String oldLocationName, String newLocationName) { super(sender); - errors.put("EntryNameNotUniqueError", "A location is already called " + newLocationName + " you ding dong goober"); + errors.put("EntryNameNotUniqueError", "A location is already called " + newLocationName + " you ding dong goober."); errors.put("LocationLookUpError", "You do not have a location by the name " + oldLocationName + " you ding dong goober."); } diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/FindCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/FindCommand.java index 580ac09..a791ead 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/FindCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/FindCommand.java @@ -43,7 +43,7 @@ public class FindCommand extends GeoffreyCommand { CommandCallback(CommandSender sender, String locationName) { super(sender); - errors.put("LocationLookUpError", "There are no locations that match " + locationName); + errors.put("LocationLookUpError", "There are no locations that match " + locationName + "."); this.locationName = locationName; } diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/FindFarmCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/FindFarmCommand.java index 2b699ab..a0189a5 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/FindFarmCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/FindFarmCommand.java @@ -43,7 +43,7 @@ public class FindFarmCommand extends GeoffreyCommand { CommandCallback(CommandSender sender, String resourceName) { super(sender); this.resourceName = resourceName; - errors.put("ResourceNotFoundError", "No farms found that produce " + this.resourceName); + errors.put("ResourceNotFoundError", "No farms found that produce " + this.resourceName + "."); } @Override diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/InfoCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/InfoCommand.java index 215ac53..b2b2c13 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/InfoCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/InfoCommand.java @@ -54,7 +54,7 @@ public class InfoCommand extends GeoffreyCommand { CommandCallback(CommandSender sender, String locationName) { super(sender); - errors.put("LocationLookUpError", "There are no locations that match " + locationName); + errors.put("LocationLookUpError", "There are no locations that match " + locationName + "."); this.locationName = locationName; } diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/LocationsCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/LocationsCommand.java index 584b20c..96b27d6 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/LocationsCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/LocationsCommand.java @@ -28,7 +28,7 @@ public class LocationsCommand extends GeoffreyCommand { RunCommand("me", params, Method.GET, new CommandCallback(sender)); } else { - sender.sendMessage(ChatColor.RED + "Console does not have locations "); + sender.sendMessage(ChatColor.RED + "Console cannot have locations."); return false; } diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/RemoveResidentCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/RemoveResidentCommand.java index 1c188f2..e85194f 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/RemoveResidentCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/RemoveResidentCommand.java @@ -63,7 +63,7 @@ public class RemoveResidentCommand extends GeoffreyCommand { try { JsonElement json = parseJSON(s); - String msg = ChatColor.GREEN + residentName + "has been removed from your town"; + String msg = ChatColor.GREEN + residentName + "has been removed from your town."; commandSender.sendMessage(msg); } catch (GeoffreyCommandError e) { diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/RestockCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/RestockCommand.java new file mode 100644 index 0000000..9a46710 --- /dev/null +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/RestockCommand.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.GeoffreyItemListing; +import com.zerohighdef.geoffrey.Objects.GeoffreyAPICallback; +import com.zerohighdef.geoffrey.Objects.GeoffreyCommand; +import com.zerohighdef.geoffrey.Objects.GeoffreyCommandError; +import com.zerohighdef.geoffrey.Objects.GeoffreyUtil; +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.text.ParseException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class RestockCommand extends GeoffreyCommand { + public RestockCommand(GeoffreyMC plugin) { + super(plugin); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + if ((sender instanceof Player)) { + Map params = new HashMap(); + List parsedArgs; + + try { + parsedArgs = GeoffreyUtil.parseArgs(args); + } + catch (ParseException e) { + sender.sendMessage(ChatColor.RED + e.getMessage()); + return false; + } + + if (parsedArgs.size() > 1) { + String name = StringUtils.join(parsedArgs.subList(1, parsedArgs.size()), " "); + params.put("shop_name", name); + } + else if (parsedArgs.size() < 1) { + sender.sendMessage(ChatColor.RED + "Too few parameters given."); + return false; + } + + Player player = ((Player) sender).getPlayer(); + + String itemName = parsedArgs.get(0); + + + params.put("mc_uuid", player.getUniqueId().toString().replace("-", "")); + params.put("item_name", itemName); + RunCommand("restock", params, Method.POST , new CommandCallback(sender, itemName)); + + } + else { + sender.sendMessage(ChatColor.RED + "Console can not restock items!"); + } + + return true; + } + + private class CommandCallback extends GeoffreyAPICallback { + + CommandCallback(CommandSender sender, String itemName) { + super(sender); + errors.put( "ItemNotFound", "that shop does not have " + itemName + " in its inventory"); + errors.put("LocationLookUpError", "You do not have a shop 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); + + GeoffreyItemListing itemListing = new GeoffreyItemListing(json.getAsJsonArray().get(0).getAsJsonObject()); + String msg = ChatColor.GREEN + itemListing.getItemName() + " has been restocked!"; + commandSender.sendMessage(msg); + } + catch (GeoffreyCommandError e) { + return; + } + } + } +} diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/TunnelCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/TunnelCommand.java new file mode 100644 index 0000000..73a7464 --- /dev/null +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/TunnelCommand.java @@ -0,0 +1,71 @@ +package com.zerohighdef.geoffrey.Commands; + +import com.google.gson.JsonElement; +import com.zerohighdef.geoffrey.GeoffreyMC; +import com.zerohighdef.geoffrey.Models.GeoffreyTunnel; +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 java.util.HashMap; +import java.util.Map; + +public class TunnelCommand extends GeoffreyCommand { + public TunnelCommand(GeoffreyMC plugin) { + super(plugin); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + if (args.length > 0) { + String playerName = args[0]; + Map params = new HashMap(); + + params.put("player_name", playerName); + RunCommand("tunnel", params, Method.GET, new CommandCallback(sender, playerName)); + } + else { + sender.sendMessage(ChatColor.RED + "You must specify a player name."); + return false; + } + + return true; + } + + + private class CommandCallback extends GeoffreyAPICallback { + private String playerName; + + CommandCallback(CommandSender sender, String playerName) { + super(sender); + errors.put("LocationLookUpError", playerName + " has no tunnels."); + this.playerName = playerName; + } + + @Override + public void invoke(String s) { + try { + JsonElement json = parseJSON(s); + StringBuilder tunnelList = new StringBuilder(); + + for (JsonElement jsonElement: json.getAsJsonArray()) { + GeoffreyTunnel tunnel = new GeoffreyTunnel(jsonElement.getAsJsonObject()); + tunnelList.append(tunnel.getLocationName()); + tunnelList.append(": "); + tunnelList.append(tunnel.getTunnelLocationString()); + tunnelList.append("\n"); + } + + String msg = ChatColor.BOLD + playerName + " has the following tunnels:\n" + ChatColor.RESET + tunnelList.toString(); + commandSender.sendMessage(ChatColor.GREEN + 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 d86d416..9361f1a 100644 --- a/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java +++ b/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java @@ -89,6 +89,12 @@ public final class GeoffreyMC extends JavaPlugin { RemoveResidentCommand removeResidentCommand = new RemoveResidentCommand(this); this.getCommand("geoffrey_remove_resident").setExecutor(removeResidentCommand); + + RestockCommand restockCommand = new RestockCommand(this); + this.getCommand("geoffrey_restock").setExecutor(restockCommand); + + TunnelCommand tunnelCommand = new TunnelCommand(this); + this.getCommand("geoffrey_tunnel").setExecutor(tunnelCommand); } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4304234..960f947 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -134,6 +134,16 @@ commands: aliases: [remove_resident] permission: geoffrey.add usage: /remove_resident [resident name] [town name] + geoffrey_restock: + description: Restocks an item in your shop + aliases: [restock] + permission: geoffrey.add + usage: /restock [item name] [shop name] + geoffrey_tunnel: + description: Displays all the tunnels a player owns + aliases: [tunnel] + permission: geoffrey.search + usage: /tunnel [player name] permissions: add: