From 4804ca5ad47a939fe7fabea51f15d999740f9fd3 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Tue, 24 Dec 2019 17:12:09 -0600 Subject: [PATCH] Added missing files from last commit --- pom.xml | 8 -- .../geoffrey/Commands/AddItemCommand.java | 98 +++++++++++++++++++ .../geoffrey/Commands/AddLocationCommand.java | 3 +- .../geoffrey/Commands/AddResidentCommand.java | 74 ++++++++++++++ .../geoffrey/Commands/FindCommand.java | 3 +- .../geoffrey/Commands/RegisterCommand.java | 1 - .../geoffrey/Commands/SellingCommand.java | 3 +- .../com/zerohighdef/geoffrey/GeoffreyMC.java | 11 ++- .../geoffrey/Objects/GeoffreyAPICallback.java | 6 +- src/main/resources/plugin.yml | 29 ++++-- 10 files changed, 211 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/zerohighdef/geoffrey/Commands/AddItemCommand.java create mode 100644 src/main/java/com/zerohighdef/geoffrey/Commands/AddResidentCommand.java diff --git a/pom.xml b/pom.xml index 4b94a85..40c7685 100644 --- a/pom.xml +++ b/pom.xml @@ -137,14 +137,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - - 8 - 8 - - \ No newline at end of file diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/AddItemCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/AddItemCommand.java new file mode 100644 index 0000000..c4d9159 --- /dev/null +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/AddItemCommand.java @@ -0,0 +1,98 @@ +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.Models.GeoffreyLocation; +import com.zerohighdef.geoffrey.Objects.GeoffreyAPICallback; +import com.zerohighdef.geoffrey.Objects.GeoffreyCommandError; +import org.apache.commons.lang.NumberUtils; +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 AddItemCommand extends GeoffreyCommand{ + public AddItemCommand(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 > 3) { + String name[] = Arrays.copyOfRange(args, 3, args.length-1); + params.put("shop_name", StringUtils.join(name, " ")); + } + else if (args.length < 3) { + sender.sendMessage(ChatColor.RED + "Too few parameters given."); + return false; + } + + Player player = ((Player) sender).getPlayer(); + + String quantity = args[1]; + String diamondPrice = args[2]; + + try { + Integer.parseInt(quantity); + } + catch (NumberFormatException e) { + sender.sendMessage(ChatColor.RED + "Quantity must be an integer value!"); + return false; + } + + try { + Integer.parseInt(diamondPrice); + } + catch (NumberFormatException e) { + sender.sendMessage(ChatColor.RED + "Price must be an integer value!"); + return false; + } + + params.put("mc_uuid", player.getUniqueId().toString().replace("-", "")); + params.put("item_name", args[0]); + params.put("quantity", quantity); + params.put("diamond_price", diamondPrice); + RunCommand("add_item", params, Method.POST , new CommandCallback(sender)); + + } + else { + sender.sendMessage(ChatColor.RED + "Console can not add items!"); + } + + return true; + } + + private class CommandCallback extends GeoffreyAPICallback { + + CommandCallback(CommandSender sender) { + super(sender); + 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.getAsJsonObject()); + String msg = ChatColor.GREEN + itemListing.getItemName() + " has been added to your shop."; + commandSender.sendMessage(msg); + } + catch (GeoffreyCommandError e) { + return; + } + } + } +} diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/AddLocationCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/AddLocationCommand.java index 502d64c..57c0b77 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/AddLocationCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/AddLocationCommand.java @@ -5,6 +5,7 @@ import com.zerohighdef.geoffrey.GeoffreyMC; import com.zerohighdef.geoffrey.Models.GeoffreyLocation; 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; @@ -28,7 +29,7 @@ public class AddLocationCommand extends GeoffreyCommand{ Map params = new HashMap(); if (args.length > 0) { - params.put("name", String.join(" ", args)); + params.put("name", StringUtils.join(args, " ")); } Player player = ((Player) sender).getPlayer(); diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/AddResidentCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/AddResidentCommand.java new file mode 100644 index 0000000..8123022 --- /dev/null +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/AddResidentCommand.java @@ -0,0 +1,74 @@ +package com.zerohighdef.geoffrey.Commands; + +import com.google.gson.JsonElement; +import com.zerohighdef.geoffrey.GeoffreyMC; +import com.zerohighdef.geoffrey.Models.GeoffreyPlayer; +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 AddResidentCommand extends GeoffreyCommand { + + public AddResidentCommand(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("new_resident_name", args[0]); + RunCommand("add_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 can not add residents!"); + } + + return true; + } + + private class CommandCallback extends GeoffreyAPICallback { + + CommandCallback(CommandSender sender, String new_resident_name) { + super(sender); + errors.put("ResidentNotFoundError", "Ain't no one in this darn database named" + new_resident_name + "you goob"); + errors.put("IsResidentError", new_resident_name + " is already a resident, stop having amosia."); + errors.put("LocationLookUpError", "You do not have a town by that name you ding dong goober."); + } + + @Override + public void invoke(String s) { + try { + JsonElement json = parseJSON(s); + GeoffreyPlayer player = new GeoffreyPlayer(json.getAsJsonObject()); + + String msg = ChatColor.GREEN + player.getUsername() + "has been added to your town"; + commandSender.sendMessage(msg); + } + catch (GeoffreyCommandError e) { + return; + } + } + } +} diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/FindCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/FindCommand.java index 7286f7c..ce51e6d 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/FindCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/FindCommand.java @@ -4,6 +4,7 @@ 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; @@ -21,7 +22,7 @@ public class FindCommand extends GeoffreyCommand { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (args.length > 0) { - String locationName = String.join(" ", args); + String locationName = StringUtils.join(args, " "); Map params = new HashMap(); params.put("search", locationName); diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/RegisterCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/RegisterCommand.java index 0ac3e36..7e72c4a 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/RegisterCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/RegisterCommand.java @@ -27,7 +27,6 @@ public class RegisterCommand extends GeoffreyCommand{ Player player = ((Player) sender).getPlayer(); params.put("player_name", player.getName()); - params.put("discord_uuid", ""); RunCommand("register", params, Method.POST , new CommandCallback(sender)); } diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/SellingCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/SellingCommand.java index 50d83e4..b4321b2 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/SellingCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/SellingCommand.java @@ -5,6 +5,7 @@ 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; @@ -22,7 +23,7 @@ public class SellingCommand extends GeoffreyCommand { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (args.length > 0) { - String item = String.join(" ", args); + String item = StringUtils.join(args, " "); String commandName; if (command.getName().contains("price")) { diff --git a/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java b/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java index bfa5e9d..cdfb8db 100644 --- a/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java +++ b/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java @@ -1,9 +1,6 @@ package com.zerohighdef.geoffrey; -import com.zerohighdef.geoffrey.Commands.AddLocationCommand; -import com.zerohighdef.geoffrey.Commands.FindCommand; -import com.zerohighdef.geoffrey.Commands.RegisterCommand; -import com.zerohighdef.geoffrey.Commands.SellingCommand; +import com.zerohighdef.geoffrey.Commands.*; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; @@ -41,6 +38,12 @@ public final class GeoffreyMC extends JavaPlugin { RegisterCommand registerCommand = new RegisterCommand(this); this.getCommand("geoffrey_register").setExecutor(registerCommand); + + AddItemCommand addItemCommand = new AddItemCommand(this); + this.getCommand("geoffrey_add_item").setExecutor(addItemCommand); + + AddResidentCommand addResidentCommand = new AddResidentCommand(this); + this.getCommand("geoffrey_add_resident").setExecutor(addResidentCommand); } } diff --git a/src/main/java/com/zerohighdef/geoffrey/Objects/GeoffreyAPICallback.java b/src/main/java/com/zerohighdef/geoffrey/Objects/GeoffreyAPICallback.java index f4fe7d5..1c2628a 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Objects/GeoffreyAPICallback.java +++ b/src/main/java/com/zerohighdef/geoffrey/Objects/GeoffreyAPICallback.java @@ -12,11 +12,12 @@ import org.bukkit.command.CommandSender; import xyz.etztech.core.web.ICallback; import java.util.HashMap; -import java.util.Map; +import java.util.logging.Logger; public abstract class GeoffreyAPICallback implements ICallback { protected CommandSender commandSender; protected HashMap errors = new HashMap<>(); + private Logger log = Logger.getLogger( "Minecraft" ); public GeoffreyAPICallback(CommandSender commandSender) { @@ -40,6 +41,9 @@ public abstract class GeoffreyAPICallback implements ICallback { if (errors.containsKey(error)) { errorMessage = errors.get(error); } + else { + log.info("[Geoffrey] " + object.get("error").getAsString() + " " + object.get("error_message").getAsString()); + } commandSender.sendMessage(ChatColor.RED + errorMessage); throw new GeoffreyCommandError(); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b805fa5..f41a323 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -7,52 +7,65 @@ commands: geoffrey_find: description: Finds a location in Geoffrey aliases: [find, find_location] + usage: /find [location name] geoffrey_selling: description: Finds an item for sale in Geoffrey aliases: [selling] + usage: /selling [item name] geoffrey_selling_price: description: Finds an item for sale in Geoffrey, sorted by price aliases: [selling_price] + usage: /selling_price [item name] geoffrey_add_base: description: Adds a base to Geoffrey aliases: [add_base] permission: geoffrey.add - usage: Adds a base at your current location to Geoffrey + usage: /add_base [base name] geoffrey_add_shop: description: Adds a shop to Geoffrey aliases: [add_shop] permission: geoffrey.add - usage: Adds a shop at your current location to Geoffrey + usage: /add_shop [shop name] geoffrey_add_farm: description: Adds a public farm to Geoffrey aliases: [add_farm] permission: geoffrey.add - usage: Adds a farm at your current location to Geoffrey + usage: /add_farm [farm name] geoffrey_add_attraction: description: Adds an attraction to Geoffrey aliases: [add_attraction] permission: geoffrey.add - usage: Adds an attraction at your current location to Geoffrey + usage: /add_attraction [attraction name] geoffrey_add_town: description: Adds a town to Geoffrey aliases: [add_town] permission: geoffrey.add - usage: Adds a town at your current location to Geoffrey + usage: /add_town [town name] geoffrey_add_market: description: Adds a market to Geoffrey aliases: [add_market] permission: geoffrey.add - usage: Adds a market at your current location to Geoffrey + usage: /add_market [market name] geoffrey_register: description: Registers a player for Geoffrey aliases: [register] permission: geoffrey.register - usage: Registers you in Geoffrey + usage: /register + geoffrey_add_item: + description: Adds an item to a shop in Geoffrey + aliases: [add_item] + permission: geoffrey.add + usage: /add_item [item name] [amount per price] [price] [shop name] + geoffrey_add_resident: + description: Adds a resident to a tow + aliases: [add_resident] + permission: geoffrey.add + usage: /add_resident [resident Name] [town name] permissions: add: description: Permission to add things to Geoffrey default: false register: - description: Permission to register in Geoffrey + description: Permission to register for Geoffrey default: false