From d764c31208c3392ba66f6491fed82db8b69bb2a2 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Wed, 8 Jan 2020 13:32:33 -0600 Subject: [PATCH] Added location command and remove_resident command\ + Fixed AddTunnel command + Small wording change --- .../geoffrey/Commands/AddResidentCommand.java | 2 +- .../geoffrey/Commands/AddTunnelCommand.java | 4 +- .../geoffrey/Commands/LocationsCommand.java | 56 ++++++++++++++ .../Commands/RemoveResidentCommand.java | 74 +++++++++++++++++++ .../com/zerohighdef/geoffrey/GeoffreyMC.java | 6 ++ .../geoffrey/Models/GeoffreyLocation.java | 2 +- src/main/resources/plugin.yml | 21 +++++- 7 files changed, 160 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/zerohighdef/geoffrey/Commands/LocationsCommand.java create mode 100644 src/main/java/com/zerohighdef/geoffrey/Commands/RemoveResidentCommand.java diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/AddResidentCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/AddResidentCommand.java index e3ef87f..cc4ed05 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/AddResidentCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/AddResidentCommand.java @@ -43,7 +43,7 @@ public class AddResidentCommand extends GeoffreyCommand { } } else { - sender.sendMessage(ChatColor.RED + "Console can not add residents!"); + sender.sendMessage(ChatColor.RED + "Console cannot add residents!"); } return true; diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/AddTunnelCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/AddTunnelCommand.java index c0510a1..d6ec7eb 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/AddTunnelCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/AddTunnelCommand.java @@ -38,8 +38,8 @@ public class AddTunnelCommand extends GeoffreyCommand { if ((sender instanceof Player)) { Map params = new HashMap(); - if (args.length >= 3) { - String name[] = Arrays.copyOfRange(args, 3, args.length); + if (args.length > 2) { + String name[] = Arrays.copyOfRange(args, 2, args.length); // this is a hack String paramName = (commmandName.compareTo("edit_tunnel") == 0) ? "loc_name" : "location_name"; params.put(paramName, StringUtils.join(name, " ")); diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/LocationsCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/LocationsCommand.java new file mode 100644 index 0000000..584b20c --- /dev/null +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/LocationsCommand.java @@ -0,0 +1,56 @@ +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 LocationsCommand extends GeoffreyCommand { + public LocationsCommand(GeoffreyMC plugin) { + super(plugin); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + if (sender instanceof Player) { + Map params = new HashMap(); + + params.put("mc_uuid", ((Player) sender).getPlayer().getUniqueId().toString().replace("-", "")); + RunCommand("me", params, Method.GET, new CommandCallback(sender)); + } + else { + sender.sendMessage(ChatColor.RED + "Console does not have locations "); + return false; + } + + return true; + } + + + private class CommandCallback extends GeoffreyAPICallback { + CommandCallback(CommandSender sender) { + super(sender); + } + + @Override + public void invoke(String s) { + try { + JsonElement json = parseJSON(s); + String msg = ChatColor.BOLD + "You own the following locations:\n" + ChatColor.RESET + locationList(json, 5); + commandSender.sendMessage(ChatColor.GREEN + msg); + } + catch (GeoffreyCommandError e) { + return; + } + } + } +} diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/RemoveResidentCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/RemoveResidentCommand.java new file mode 100644 index 0000000..1c188f2 --- /dev/null +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/RemoveResidentCommand.java @@ -0,0 +1,74 @@ +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.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 RemoveResidentCommand extends GeoffreyCommand { + + public RemoveResidentCommand(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 > 1) { + String name[] = Arrays.copyOfRange(args, 1, args.length); + params.put("town_name", StringUtils.join(name, " ")); + Player player = ((Player) sender).getPlayer(); + + params.put("mc_uuid", player.getUniqueId().toString().replace("-", "")); + params.put("resident_name", args[0]); + RunCommand("remove_resident", params, Method.POST , new CommandCallback(sender, args[0])); + } + else if (args.length < 2) { + sender.sendMessage(ChatColor.RED + "Too few parameters given."); + return false; + } + } + else { + sender.sendMessage(ChatColor.RED + "Console cannot remove residents!"); + } + + return true; + } + + private class CommandCallback extends GeoffreyAPICallback { + private String residentName; + + CommandCallback(CommandSender sender, String residentName) { + super(sender); + errors.put("ResidentNotFoundError", "Ain't no one in this darn town named" + residentName + "you goob"); + errors.put("LocationLookUpError", "You do not have a town by that name you ding dong goober."); + this.residentName = residentName; + } + + @Override + public void invoke(String s) { + try { + JsonElement json = parseJSON(s); + + String msg = ChatColor.GREEN + residentName + "has been removed from your town"; + 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 27b2fa1..d86d416 100644 --- a/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java +++ b/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java @@ -83,6 +83,12 @@ public final class GeoffreyMC extends JavaPlugin { InfoCommand infoCommand = new InfoCommand(this); this.getCommand("geoffrey_info").setExecutor(infoCommand); + + LocationsCommand locationsCommand = new LocationsCommand(this); + this.getCommand("geoffrey_locations").setExecutor(locationsCommand); + + RemoveResidentCommand removeResidentCommand = new RemoveResidentCommand(this); + this.getCommand("geoffrey_remove_resident").setExecutor(removeResidentCommand); } } diff --git a/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyLocation.java b/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyLocation.java index e26add7..3709c3c 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyLocation.java +++ b/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyLocation.java @@ -51,7 +51,7 @@ public class GeoffreyLocation { } public String getInfoString() { - return ChatColor.BOLD + getFormattedLocationString() + ChatColor.RESET; + return ChatColor.BOLD + getFormattedLocationString().replace(" ", " " + ChatColor.BOLD) + ChatColor.RESET; } public int getxCoord() { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 0b33dc1..4304234 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -7,14 +7,17 @@ commands: geoffrey_find: description: Finds a location in Geoffrey aliases: [find, find_location] + permission: geoffrey.search usage: /find [location name] geoffrey_selling: description: Finds an item for sale in Geoffrey aliases: [selling] + permission: geoffrey.search usage: /selling [item name] geoffrey_selling_price: description: Finds an item for sale in Geoffrey, sorted by price aliases: [selling_price] + permission: geoffrey.search usage: /selling_price [item name] geoffrey_add_base: description: Adds a base to Geoffrey @@ -109,20 +112,36 @@ commands: geoffrey_find_around: description: Finds locations around your current position aliases: [find_around] + permission: geoffrey.search usage: /find_around [radius] geoffrey_find_farm: description: Finds a farm producing a resource aliases: [find_farm] + permission: geoffrey.search usage: /find_farm [resource name] geoffrey_info: description: Gives info on a location + permission: geoffrey.search aliases: [info] - usage: /info [location_name] + usage: /info [location name] + geoffrey_locations: + description: Displays all of your locations + permission: geoffrey.search + aliases: [locations] + usage: /locations + geoffrey_remove_resident: + description: Removes a resident from your town + aliases: [remove_resident] + permission: geoffrey.add + usage: /remove_resident [resident name] [town name] permissions: add: description: Permission to add things to Geoffrey default: false + search: + description: Permission use search commands in Geoffrey + default: false register: description: Permission to register for Geoffrey default: false