Added delete_resource command and moved GeoffreyCommand to objects

+ GeoffreyCommand is now in the objects package
master
Joey Hines 2019-12-29 13:16:23 -06:00
parent 3c15b9e770
commit 88cb10b96c
15 changed files with 110 additions and 13 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
@ -29,7 +29,7 @@ public class DeleteItemCommand extends GeoffreyCommand{
Map<String, String> params = new HashMap<String, String>();
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) {

View File

@ -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<String, String> params = new HashMap<String, String>();
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;
}
}
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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
}

View File

@ -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: