Added missing files

pull/2/head
Joey Hines 2019-12-29 18:28:42 -06:00
parent 88cb10b96c
commit f59072d534
11 changed files with 245 additions and 23 deletions

View File

@ -50,6 +50,12 @@
<artifactId>EtzCore</artifactId> <artifactId>EtzCore</artifactId>
<version>1.0.5</version> <version>1.0.5</version>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>

View File

@ -6,14 +6,17 @@ import com.zerohighdef.geoffrey.Models.GeoffreyItemListing;
import com.zerohighdef.geoffrey.Objects.GeoffreyAPICallback; import com.zerohighdef.geoffrey.Objects.GeoffreyAPICallback;
import com.zerohighdef.geoffrey.Objects.GeoffreyCommand; import com.zerohighdef.geoffrey.Objects.GeoffreyCommand;
import com.zerohighdef.geoffrey.Objects.GeoffreyCommandError; import com.zerohighdef.geoffrey.Objects.GeoffreyCommandError;
import com.zerohighdef.geoffrey.Objects.GeoffreyUtil;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.text.ParseException;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
public class AddItemCommand extends GeoffreyCommand { public class AddItemCommand extends GeoffreyCommand {
@ -27,20 +30,30 @@ public class AddItemCommand extends GeoffreyCommand {
if ((sender instanceof Player)) { if ((sender instanceof Player)) {
Map<String, String> params = new HashMap<String, String>(); Map<String, String> params = new HashMap<String, String>();
List<String> parsedArgs;
if (args.length > 3) { try {
String name[] = Arrays.copyOfRange(args, 3, args.length-1); parsedArgs = GeoffreyUtil.parseArgs(args);
params.put("shop_name", StringUtils.join(name, " "));
} }
else if (args.length < 3) { catch (ParseException e) {
sender.sendMessage(ChatColor.RED + e.getMessage());
return false;
}
if (parsedArgs.size() > 3) {
String name = StringUtils.join(parsedArgs.subList(3, parsedArgs.size()), " ");
params.put("shop_name", name);
}
else if (parsedArgs.size() < 3) {
sender.sendMessage(ChatColor.RED + "Too few parameters given."); sender.sendMessage(ChatColor.RED + "Too few parameters given.");
return false; return false;
} }
Player player = ((Player) sender).getPlayer(); Player player = ((Player) sender).getPlayer();
String quantity = args[1]; String itemName = parsedArgs.get(0);
String diamondPrice = args[2]; String quantity = parsedArgs.get(1);
String diamondPrice = parsedArgs.get(2);
try { try {
Integer.parseInt(quantity); Integer.parseInt(quantity);
@ -59,7 +72,7 @@ public class AddItemCommand extends GeoffreyCommand {
} }
params.put("mc_uuid", player.getUniqueId().toString().replace("-", "")); params.put("mc_uuid", player.getUniqueId().toString().replace("-", ""));
params.put("item_name", args[0]); params.put("item_name", itemName);
params.put("quantity", quantity); params.put("quantity", quantity);
params.put("diamond_price", diamondPrice); params.put("diamond_price", diamondPrice);
RunCommand("add_item", params, Method.POST , new CommandCallback(sender)); RunCommand("add_item", params, Method.POST , new CommandCallback(sender));

View File

@ -6,14 +6,17 @@ import com.zerohighdef.geoffrey.Models.GeoffreyResource;
import com.zerohighdef.geoffrey.Objects.GeoffreyAPICallback; import com.zerohighdef.geoffrey.Objects.GeoffreyAPICallback;
import com.zerohighdef.geoffrey.Objects.GeoffreyCommand; import com.zerohighdef.geoffrey.Objects.GeoffreyCommand;
import com.zerohighdef.geoffrey.Objects.GeoffreyCommandError; import com.zerohighdef.geoffrey.Objects.GeoffreyCommandError;
import com.zerohighdef.geoffrey.Objects.GeoffreyUtil;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.text.ParseException;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
public class AddResourceCommand extends GeoffreyCommand { public class AddResourceCommand extends GeoffreyCommand {
@ -27,12 +30,21 @@ public class AddResourceCommand extends GeoffreyCommand {
if ((sender instanceof Player)) { if ((sender instanceof Player)) {
Map<String, String> params = new HashMap<String, String>(); Map<String, String> params = new HashMap<String, String>();
List<String> parsedArgs;
if (args.length > 1) { try {
String name[] = Arrays.copyOfRange(args, 1, args.length); parsedArgs = GeoffreyUtil.parseArgs(args);
params.put("farm_name", StringUtils.join(name, " "));
} }
else if (args.length == 0) { 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("farm_name", name);
}
else if (parsedArgs.size() < 1) {
sender.sendMessage(ChatColor.RED + "Too few parameters given."); sender.sendMessage(ChatColor.RED + "Too few parameters given.");
return false; return false;
} }
@ -40,7 +52,7 @@ public class AddResourceCommand extends GeoffreyCommand {
Player player = ((Player) sender).getPlayer(); Player player = ((Player) sender).getPlayer();
params.put("mc_uuid", player.getUniqueId().toString().replace("-", "")); params.put("mc_uuid", player.getUniqueId().toString().replace("-", ""));
params.put("resource_name", args[0]); params.put("resource_name", parsedArgs.get(0));
RunCommand("add_resource", params, Method.POST , new CommandCallback(sender)); RunCommand("add_resource", params, Method.POST , new CommandCallback(sender));
} }

View File

@ -6,14 +6,17 @@ import com.zerohighdef.geoffrey.Models.GeoffreyLocation;
import com.zerohighdef.geoffrey.Objects.GeoffreyAPICallback; import com.zerohighdef.geoffrey.Objects.GeoffreyAPICallback;
import com.zerohighdef.geoffrey.Objects.GeoffreyCommand; import com.zerohighdef.geoffrey.Objects.GeoffreyCommand;
import com.zerohighdef.geoffrey.Objects.GeoffreyCommandError; import com.zerohighdef.geoffrey.Objects.GeoffreyCommandError;
import com.zerohighdef.geoffrey.Objects.GeoffreyUtil;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.text.ParseException;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
public class DeleteItemCommand extends GeoffreyCommand { public class DeleteItemCommand extends GeoffreyCommand {
@ -27,18 +30,27 @@ public class DeleteItemCommand extends GeoffreyCommand {
if ((sender instanceof Player)) { if ((sender instanceof Player)) {
Map<String, String> params = new HashMap<String, String>(); Map<String, String> params = new HashMap<String, String>();
List<String> parsedArgs;
if (args.length > 1) { try {
String name[] = Arrays.copyOfRange(args, 1, args.length); parsedArgs = GeoffreyUtil.parseArgs(args);
params.put("shop_name", StringUtils.join(name, " "));
} }
else if (args.length == 0) { 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() == 0) {
sender.sendMessage(ChatColor.RED + "Too few parameters given."); sender.sendMessage(ChatColor.RED + "Too few parameters given.");
return false; return false;
} }
Player player = ((Player) sender).getPlayer(); Player player = ((Player) sender).getPlayer();
String itemName = args[0]; String itemName = parsedArgs.get(0);
params.put("mc_uuid", player.getUniqueId().toString().replace("-", "")); params.put("mc_uuid", player.getUniqueId().toString().replace("-", ""));
params.put("item", itemName); params.put("item", itemName);

View File

@ -6,14 +6,17 @@ import com.zerohighdef.geoffrey.Models.GeoffreyLocation;
import com.zerohighdef.geoffrey.Objects.GeoffreyAPICallback; import com.zerohighdef.geoffrey.Objects.GeoffreyAPICallback;
import com.zerohighdef.geoffrey.Objects.GeoffreyCommand; import com.zerohighdef.geoffrey.Objects.GeoffreyCommand;
import com.zerohighdef.geoffrey.Objects.GeoffreyCommandError; import com.zerohighdef.geoffrey.Objects.GeoffreyCommandError;
import com.zerohighdef.geoffrey.Objects.GeoffreyUtil;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.text.ParseException;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
public class DeleteResourceCommand extends GeoffreyCommand { public class DeleteResourceCommand extends GeoffreyCommand {
@ -28,20 +31,32 @@ public class DeleteResourceCommand extends GeoffreyCommand {
if ((sender instanceof Player)) { if ((sender instanceof Player)) {
Map<String, String> params = new HashMap<String, String>(); Map<String, String> params = new HashMap<String, String>();
if (args.length > 1) { List<String> parsedArgs;
String name[] = Arrays.copyOfRange(args, 1, args.length);
params.put("farm_name", StringUtils.join(name, " ")); try {
parsedArgs = GeoffreyUtil.parseArgs(args);
} }
else if (args.length == 0) { 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("farm_name", name);
}
else if (parsedArgs.size() < 1) {
sender.sendMessage(ChatColor.RED + "Too few parameters given."); sender.sendMessage(ChatColor.RED + "Too few parameters given.");
return false; return false;
} }
Player player = ((Player) sender).getPlayer(); Player player = ((Player) sender).getPlayer();
String resource = args[0];
String resource = parsedArgs.get(0);
params.put("mc_uuid", player.getUniqueId().toString().replace("-", "")); params.put("mc_uuid", player.getUniqueId().toString().replace("-", ""));
params.put("resource", resource); params.put("resource", resource);
RunCommand("delete_resource", params, Method.POST , new CommandCallback(sender, resource)); RunCommand("delete_resource", params, Method.POST , new CommandCallback(sender, resource));
} }

View File

@ -0,0 +1,84 @@
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 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 EditNameCommand extends GeoffreyCommand {
public EditNameCommand(GeoffreyMC plugin) {
super(plugin);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if ((sender instanceof Player)) {
List<String> parsedArgs;
try {
parsedArgs = GeoffreyUtil.parseArgs(args);
}
catch (ParseException e) {
sender.sendMessage(ChatColor.RED + e.getMessage());
return false;
}
Map<String, String> params = new HashMap<String, String>();
if (parsedArgs.size() < 2) {
sender.sendMessage(ChatColor.RED + "Not enough parameters!");
return false;
}
Player player = ((Player) sender).getPlayer();
String oldLocationName = parsedArgs.get(0);
String newLocationName = parsedArgs.get(1);
params.put("mc_uuid", player.getUniqueId().toString().replace("-", ""));
params.put("new_name", oldLocationName);
params.put("loc_name", newLocationName);
RunCommand("edit_name", params, Method.POST , new CommandCallback(sender, oldLocationName, newLocationName));
}
else {
sender.sendMessage(ChatColor.RED + "Console can not add locations!");
}
return true;
}
private class CommandCallback extends GeoffreyAPICallback {
CommandCallback(CommandSender sender, String oldLocationName, String newLocationName) {
super(sender);
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.");
}
@Override
public void invoke(String s) {
try {
JsonElement json = parseJSON(s);
GeoffreyLocation location = new GeoffreyLocation(json.getAsJsonObject());
String msg = ChatColor.GREEN + location.getLocationName() + " has been updated.";
commandSender.sendMessage(msg);
}
catch (GeoffreyCommandError e) {
return;
}
}
}
}

View File

@ -24,7 +24,7 @@ public class SellingCommand extends GeoffreyCommand {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length > 0) { if (args.length > 0) {
String item = StringUtils.join(args, " "); String item = StringUtils.join(args, " ").replace("\"", "");
String commandName; String commandName;
if (command.getName().contains("price")) { if (command.getName().contains("price")) {

View File

@ -64,6 +64,9 @@ public final class GeoffreyMC extends JavaPlugin {
DeleteResourceCommand deleteResourceCommand = new DeleteResourceCommand(this); DeleteResourceCommand deleteResourceCommand = new DeleteResourceCommand(this);
this.getCommand("geoffrey_delete_resource").setExecutor(deleteResourceCommand); this.getCommand("geoffrey_delete_resource").setExecutor(deleteResourceCommand);
EditNameCommand editNameCommand = new EditNameCommand(this);
this.getCommand("geoffrey_edit_name").setExecutor(editNameCommand);
} }
} }

View File

@ -0,0 +1,49 @@
package com.zerohighdef.geoffrey.Objects;
import java.text.ParseException;
import java.util.LinkedList;
import java.util.List;
public class GeoffreyUtil {
public static List<String> parseArgs(String [] args) throws ParseException {
LinkedList<String> parsedArgs = new LinkedList<>();
boolean parsingMultiWordArg = false;
StringBuilder parsedArg = new StringBuilder();
for (String arg: args) {
boolean foundEndOfString = false;
if (!parsingMultiWordArg) {
parsedArg = new StringBuilder();
}
for (char c: arg.toCharArray()) {
if (c == '"') {
if (parsingMultiWordArg) {
foundEndOfString = true;
parsingMultiWordArg = false;
}
else {
parsingMultiWordArg = true;
}
}
}
parsedArg.append(arg);
if (parsingMultiWordArg) {
parsedArg.append(" ");
}
if (foundEndOfString || !parsingMultiWordArg) {
parsedArgs.add(parsedArg.toString().replace("\"", ""));
}
}
if (parsingMultiWordArg) {
throw new ParseException("No matching \" found", 0);
}
return parsedArgs;
}
}

View File

@ -91,6 +91,11 @@ commands:
aliases: [delete_resource] aliases: [delete_resource]
permission: geoffrey.add permission: geoffrey.add
usage: /delete_resource [resource name] [farm name] usage: /delete_resource [resource name] [farm name]
geoffrey_edit_name:
description: Edits the name of a location in Geoffrey
aliases: [edit_name]
permission: geoffrey.add
usage: /edit_name [new name] [old name]
permissions: permissions:
add: add:

View File

@ -0,0 +1,23 @@
package com.zerohighdef.geoffrey.Objects;
import org.junit.runner.RunWith;
import java.util.List;
import static org.junit.Assert.*;
public class GeoffreyUtilTest {
@org.junit.Test
public void parseArgs() {
String testArgs []= {"\"this", "is", "a", "test"};
List<String> output;
try {
output = GeoffreyUtil.parseArgs(testArgs);
}
catch (Exception e) {
return;
}
System.out.println(output);
}
}