forked from Geoffrey/Geoffrey-MC-Plugin
Added missing files
parent
88cb10b96c
commit
f59072d534
6
pom.xml
6
pom.xml
|
@ -50,6 +50,12 @@
|
|||
<artifactId>EtzCore</artifactId>
|
||||
<version>1.0.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>RELEASE</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
|
|
@ -6,14 +6,17 @@ import com.zerohighdef.geoffrey.Models.GeoffreyItemListing;
|
|||
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.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class AddItemCommand extends GeoffreyCommand {
|
||||
|
@ -27,20 +30,30 @@ public class AddItemCommand extends GeoffreyCommand {
|
|||
|
||||
if ((sender instanceof Player)) {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
List<String> parsedArgs;
|
||||
|
||||
if (args.length > 3) {
|
||||
String name[] = Arrays.copyOfRange(args, 3, args.length-1);
|
||||
params.put("shop_name", StringUtils.join(name, " "));
|
||||
try {
|
||||
parsedArgs = GeoffreyUtil.parseArgs(args);
|
||||
}
|
||||
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.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = ((Player) sender).getPlayer();
|
||||
|
||||
String quantity = args[1];
|
||||
String diamondPrice = args[2];
|
||||
String itemName = parsedArgs.get(0);
|
||||
String quantity = parsedArgs.get(1);
|
||||
String diamondPrice = parsedArgs.get(2);
|
||||
|
||||
try {
|
||||
Integer.parseInt(quantity);
|
||||
|
@ -59,7 +72,7 @@ public class AddItemCommand extends GeoffreyCommand {
|
|||
}
|
||||
|
||||
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("diamond_price", diamondPrice);
|
||||
RunCommand("add_item", params, Method.POST , new CommandCallback(sender));
|
||||
|
|
|
@ -6,14 +6,17 @@ 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 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.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class AddResourceCommand extends GeoffreyCommand {
|
||||
|
@ -27,12 +30,21 @@ public class AddResourceCommand extends GeoffreyCommand {
|
|||
|
||||
if ((sender instanceof Player)) {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
List<String> parsedArgs;
|
||||
|
||||
if (args.length > 1) {
|
||||
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.");
|
||||
return false;
|
||||
}
|
||||
|
@ -40,7 +52,7 @@ public class AddResourceCommand extends GeoffreyCommand {
|
|||
Player player = ((Player) sender).getPlayer();
|
||||
|
||||
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));
|
||||
|
||||
}
|
||||
|
|
|
@ -6,14 +6,17 @@ 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.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DeleteItemCommand extends GeoffreyCommand {
|
||||
|
@ -27,18 +30,27 @@ public class DeleteItemCommand extends GeoffreyCommand {
|
|||
|
||||
if ((sender instanceof Player)) {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
List<String> parsedArgs;
|
||||
|
||||
if (args.length > 1) {
|
||||
String name[] = Arrays.copyOfRange(args, 1, args.length);
|
||||
params.put("shop_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("shop_name", name);
|
||||
}
|
||||
else if (parsedArgs.size() == 0) {
|
||||
sender.sendMessage(ChatColor.RED + "Too few parameters given.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = ((Player) sender).getPlayer();
|
||||
String itemName = args[0];
|
||||
String itemName = parsedArgs.get(0);
|
||||
|
||||
params.put("mc_uuid", player.getUniqueId().toString().replace("-", ""));
|
||||
params.put("item", itemName);
|
||||
|
|
|
@ -6,14 +6,17 @@ 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.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DeleteResourceCommand extends GeoffreyCommand {
|
||||
|
@ -28,20 +31,32 @@ public class DeleteResourceCommand extends GeoffreyCommand {
|
|||
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, " "));
|
||||
List<String> parsedArgs;
|
||||
|
||||
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.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = ((Player) sender).getPlayer();
|
||||
String resource = args[0];
|
||||
|
||||
String resource = parsedArgs.get(0);
|
||||
|
||||
params.put("mc_uuid", player.getUniqueId().toString().replace("-", ""));
|
||||
params.put("resource", resource);
|
||||
|
||||
RunCommand("delete_resource", params, Method.POST , new CommandCallback(sender, resource));
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@ public class SellingCommand extends GeoffreyCommand {
|
|||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if (args.length > 0) {
|
||||
String item = StringUtils.join(args, " ");
|
||||
String item = StringUtils.join(args, " ").replace("\"", "");
|
||||
String commandName;
|
||||
|
||||
if (command.getName().contains("price")) {
|
||||
|
|
|
@ -64,6 +64,9 @@ public final class GeoffreyMC extends JavaPlugin {
|
|||
|
||||
DeleteResourceCommand deleteResourceCommand = new DeleteResourceCommand(this);
|
||||
this.getCommand("geoffrey_delete_resource").setExecutor(deleteResourceCommand);
|
||||
|
||||
EditNameCommand editNameCommand = new EditNameCommand(this);
|
||||
this.getCommand("geoffrey_edit_name").setExecutor(editNameCommand);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -91,6 +91,11 @@ commands:
|
|||
aliases: [delete_resource]
|
||||
permission: geoffrey.add
|
||||
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:
|
||||
add:
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue