diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/AddItemCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/AddItemCommand.java index c4d9159..f4ce54a 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/AddItemCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/AddItemCommand.java @@ -3,10 +3,9 @@ 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.GeoffreyCommand; 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; @@ -17,7 +16,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; -public class AddItemCommand extends GeoffreyCommand{ +public class AddItemCommand extends GeoffreyCommand { public AddItemCommand(GeoffreyMC plugin) { super(plugin); } diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/AddLocationCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/AddLocationCommand.java index 57c0b77..ec2aec5 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/AddLocationCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/AddLocationCommand.java @@ -4,6 +4,7 @@ import com.google.gson.JsonElement; import com.zerohighdef.geoffrey.GeoffreyMC; import com.zerohighdef.geoffrey.Models.GeoffreyLocation; 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; @@ -14,7 +15,7 @@ import org.bukkit.entity.Player; import java.util.HashMap; import java.util.Map; -public class AddLocationCommand extends GeoffreyCommand{ +public class AddLocationCommand extends GeoffreyCommand { public AddLocationCommand(GeoffreyMC plugin) { super(plugin); diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/AddOwnerCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/AddOwnerCommand.java index b7a279c..477b728 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/AddOwnerCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/AddOwnerCommand.java @@ -4,6 +4,7 @@ import com.google.gson.JsonElement; import com.zerohighdef.geoffrey.GeoffreyMC; import com.zerohighdef.geoffrey.Models.GeoffreyLocation; 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; diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/AddResidentCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/AddResidentCommand.java index 8123022..72cb4f1 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/AddResidentCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/AddResidentCommand.java @@ -4,6 +4,7 @@ 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.GeoffreyCommand; import com.zerohighdef.geoffrey.Objects.GeoffreyCommandError; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/AddResourceCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/AddResourceCommand.java index 1eeb90d..acf9e97 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/AddResourceCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/AddResourceCommand.java @@ -4,6 +4,7 @@ import com.google.gson.JsonElement; import com.zerohighdef.geoffrey.GeoffreyMC; import com.zerohighdef.geoffrey.Models.GeoffreyResource; 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; diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/AddTunnelCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/AddTunnelCommand.java index 6a54f9e..99a0d30 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/AddTunnelCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/AddTunnelCommand.java @@ -2,9 +2,9 @@ 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.GeoffreyCommand; import com.zerohighdef.geoffrey.Objects.GeoffreyCommandError; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; @@ -16,7 +16,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; -public class AddTunnelCommand extends GeoffreyCommand{ +public class AddTunnelCommand extends GeoffreyCommand { public AddTunnelCommand(GeoffreyMC plugin) { super(plugin); diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/DeleteCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/DeleteCommand.java index fa3ce81..71157ee 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/DeleteCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/DeleteCommand.java @@ -4,6 +4,7 @@ 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; diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/DeleteItemCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/DeleteItemCommand.java index 5fd4e9e..797d8a0 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/DeleteItemCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/DeleteItemCommand.java @@ -3,8 +3,8 @@ package com.zerohighdef.geoffrey.Commands; import com.google.gson.JsonElement; import com.zerohighdef.geoffrey.GeoffreyMC; import com.zerohighdef.geoffrey.Models.GeoffreyLocation; -import com.zerohighdef.geoffrey.Models.GeoffreyShop; 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; @@ -16,7 +16,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; -public class DeleteItemCommand extends GeoffreyCommand{ +public class DeleteItemCommand extends GeoffreyCommand { public DeleteItemCommand(GeoffreyMC plugin) { super(plugin); } @@ -29,7 +29,7 @@ public class DeleteItemCommand extends GeoffreyCommand{ Map params = new HashMap(); if (args.length > 1) { - String name[] = Arrays.copyOfRange(args, 1, args.length-1); + String name[] = Arrays.copyOfRange(args, 1, args.length); params.put("shop_name", StringUtils.join(name, " ")); } else if (args.length == 0) { diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/DeleteResourceCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/DeleteResourceCommand.java new file mode 100644 index 0000000..47d3103 --- /dev/null +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/DeleteResourceCommand.java @@ -0,0 +1,80 @@ +package com.zerohighdef.geoffrey.Commands; + +import com.google.gson.JsonElement; +import com.zerohighdef.geoffrey.GeoffreyMC; +import com.zerohighdef.geoffrey.Models.GeoffreyLocation; +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 DeleteResourceCommand extends GeoffreyCommand { + public DeleteResourceCommand(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("farm_name", StringUtils.join(name, " ")); + } + else if (args.length == 0) { + sender.sendMessage(ChatColor.RED + "Too few parameters given."); + return false; + } + + Player player = ((Player) sender).getPlayer(); + String resource = args[0]; + + params.put("mc_uuid", player.getUniqueId().toString().replace("-", "")); + params.put("resource", resource); + RunCommand("delete_resource", params, Method.POST , new CommandCallback(sender, resource)); + + } + else { + sender.sendMessage(ChatColor.RED + "Console can not add items!"); + } + + return true; + } + + private class CommandCallback extends GeoffreyAPICallback { + private String resourceName; + + CommandCallback(CommandSender sender, String resourceName) { + super(sender); + this.resourceName = resourceName; + errors.put("LocationLookUpError", "You do not have a farm by that name, goober."); + errors.put("EntryNameNotUniqueError", "You have more than one location. Please specify a name, dingus."); + errors.put("ResourceNotFoundError", "Your farm does not produce " + resourceName + ". Try again buddy boi!"); + } + + @Override + public void invoke(String s) { + try { + JsonElement json = parseJSON(s); + + GeoffreyLocation geoffreyLocation = new GeoffreyLocation(json.getAsJsonObject()); + String msg = ChatColor.GREEN + resourceName + " has been deleted from " + geoffreyLocation.getLocationName() + "."; + 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 ce51e6d..84561b0 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/FindCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/FindCommand.java @@ -3,6 +3,7 @@ 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; diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/RegisterCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/RegisterCommand.java index 7e72c4a..22f029e 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/RegisterCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/RegisterCommand.java @@ -3,6 +3,7 @@ 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; @@ -12,7 +13,7 @@ import org.bukkit.entity.Player; import java.util.HashMap; import java.util.Map; -public class RegisterCommand extends GeoffreyCommand{ +public class RegisterCommand extends GeoffreyCommand { public RegisterCommand(GeoffreyMC plugin) { super(plugin); diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/SellingCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/SellingCommand.java index b4321b2..76cacc6 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/SellingCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/SellingCommand.java @@ -4,6 +4,7 @@ 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; diff --git a/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java b/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java index e212bab..c5aa121 100644 --- a/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java +++ b/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java @@ -1,6 +1,8 @@ package com.zerohighdef.geoffrey; import com.zerohighdef.geoffrey.Commands.*; +import com.zerohighdef.geoffrey.Models.GeoffreyItemListing; +import com.zerohighdef.geoffrey.Models.GeoffreyLocation; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; @@ -59,6 +61,9 @@ public final class GeoffreyMC extends JavaPlugin { DeleteItemCommand deleteItemCommand = new DeleteItemCommand(this); this.getCommand("geoffrey_delete_item").setExecutor(deleteItemCommand); + + DeleteResourceCommand deleteResourceCommand = new DeleteResourceCommand(this); + this.getCommand("geoffrey_delete_resource").setExecutor(deleteResourceCommand); } } diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/GeoffreyCommand.java b/src/main/java/com/zerohighdef/geoffrey/Objects/GeoffreyCommand.java similarity index 93% rename from src/main/java/com/zerohighdef/geoffrey/Commands/GeoffreyCommand.java rename to src/main/java/com/zerohighdef/geoffrey/Objects/GeoffreyCommand.java index 0d11f48..ac54358 100644 --- a/src/main/java/com/zerohighdef/geoffrey/Commands/GeoffreyCommand.java +++ b/src/main/java/com/zerohighdef/geoffrey/Objects/GeoffreyCommand.java @@ -1,4 +1,4 @@ -package com.zerohighdef.geoffrey.Commands; +package com.zerohighdef.geoffrey.Objects; import com.zerohighdef.geoffrey.GeoffreyMC; import org.bukkit.command.Command; @@ -12,7 +12,7 @@ import java.util.Map; public class GeoffreyCommand implements CommandExecutor { private GeoffreyMC plugin; - static enum Method { + protected enum Method { GET, POST } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index c9d734a..1fb7a8c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -85,7 +85,12 @@ commands: description: Deletes an item from a shop in Geoffrey aliases: [delete_item] permission: geoffrey.add - usage: /delete [item name] [shop name] + usage: /delete_item [item name] [shop name] + geoffrey_delete_resource: + description: Deletes a resource from a farm in Geoffrey + aliases: [delete_resource] + permission: geoffrey.add + usage: /delete_resource [resource name] [farm name] permissions: add: