forked from Geoffrey/Geoffrey-MC-Plugin
Added missing files
parent
a3c12f8dd6
commit
2cecd8d0c5
|
@ -0,0 +1,90 @@
|
||||||
|
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.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 AddTunnelCommand extends GeoffreyCommand{
|
||||||
|
|
||||||
|
public AddTunnelCommand(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 > 2) {
|
||||||
|
String name[] = Arrays.copyOfRange(args, 2, args.length);
|
||||||
|
params.put("location_name", StringUtils.join(name, " "));
|
||||||
|
}
|
||||||
|
else if (args.length < 2) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Too few parameters given.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = ((Player) sender).getPlayer();
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
Integer.parseInt(args[1]);
|
||||||
|
}
|
||||||
|
catch (NumberFormatException e) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Tunnel number must be an integer value!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String tunnelDirection = args[0];
|
||||||
|
String tunnelNumber = args[1];
|
||||||
|
|
||||||
|
params.put("mc_uuid", player.getUniqueId().toString().replace("-", ""));
|
||||||
|
params.put("tunnel_direction", tunnelDirection);
|
||||||
|
params.put("tunnel_number", tunnelNumber);
|
||||||
|
RunCommand("add_tunnel", params, GeoffreyCommand.Method.POST , new CommandCallback(sender, tunnelDirection));
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Console can not add items!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class CommandCallback extends GeoffreyAPICallback {
|
||||||
|
|
||||||
|
CommandCallback(CommandSender sender, String tunnelDirection) {
|
||||||
|
super(sender);
|
||||||
|
errors.put("InvalidTunnelError", tunnelDirection + " is not a valid tunnel direction ya gub");
|
||||||
|
errors.put("LocationLookUpError", "You do not have a location 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);
|
||||||
|
|
||||||
|
GeoffreyTunnel geoffreyTunnel = new GeoffreyTunnel(json.getAsJsonObject());
|
||||||
|
String msg = ChatColor.GREEN + "A tunnel has been added to " + geoffreyTunnel.getLocationName();
|
||||||
|
commandSender.sendMessage(msg);
|
||||||
|
}
|
||||||
|
catch (GeoffreyCommandError e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
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.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.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class DeleteCommand extends GeoffreyCommand {
|
||||||
|
public DeleteCommand(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 == 0) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Too few parameters");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = ((Player) sender).getPlayer();
|
||||||
|
String locationNmae = StringUtils.join(args, " ");
|
||||||
|
params.put("name", locationNmae);
|
||||||
|
params.put("mc_uuid", player.getUniqueId().toString().replace("-", ""));
|
||||||
|
RunCommand("delete", params, Method.POST , new CommandCallback(sender, locationNmae));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Console can not add locations!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class CommandCallback extends GeoffreyAPICallback {
|
||||||
|
|
||||||
|
CommandCallback(CommandSender sender, String locationName) {
|
||||||
|
super(sender);
|
||||||
|
errors.put("LocationLookUpError", "You do not have a location by the name " + locationName + "!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invoke(String s) {
|
||||||
|
try {
|
||||||
|
JsonElement json = parseJSON(s);
|
||||||
|
|
||||||
|
String msg = ChatColor.GREEN + json.getAsString() + " has been deleted, good riddance!";
|
||||||
|
commandSender.sendMessage(msg);
|
||||||
|
}
|
||||||
|
catch (GeoffreyCommandError e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -50,6 +50,12 @@ public final class GeoffreyMC extends JavaPlugin {
|
||||||
|
|
||||||
AddResourceCommand addResourceCommand = new AddResourceCommand(this);
|
AddResourceCommand addResourceCommand = new AddResourceCommand(this);
|
||||||
this.getCommand("geoffrey_add_resource").setExecutor(addResourceCommand);
|
this.getCommand("geoffrey_add_resource").setExecutor(addResourceCommand);
|
||||||
|
|
||||||
|
AddTunnelCommand addTunnelCommand = new AddTunnelCommand(this);
|
||||||
|
this.getCommand("geoffrey_add_tunnel").setExecutor(addTunnelCommand);
|
||||||
|
|
||||||
|
DeleteCommand deleteCommand = new DeleteCommand(this);
|
||||||
|
this.getCommand("geoffrey_delete").setExecutor(deleteCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,8 @@ public abstract class GeoffreyAPICallback implements ICallback {
|
||||||
errors.put("PlayerNotFound", "You are not in the database, you must register first!");
|
errors.put("PlayerNotFound", "You are not in the database, you must register first!");
|
||||||
errors.put("NoLocationsInDatabase", "You have no locations in the database, you must add some first!");
|
errors.put("NoLocationsInDatabase", "You have no locations in the database, you must add some first!");
|
||||||
errors.put("DataError", "Slow down their slugger, that's a long word or number you are trying to cram into me, try again with something smaller, please");
|
errors.put("DataError", "Slow down their slugger, that's a long word or number you are trying to cram into me, try again with something smaller, please");
|
||||||
errors.put("LocationHasTunnelError", "that location already has a tunnel you goober.");
|
errors.put("LocationHasTunnelError", "That location already has a tunnel you goober.");
|
||||||
errors.put( "EntryNameNotUniqueError", "that name has already been used, be more creative dingus kong");
|
errors.put( "EntryNameNotUniqueError", "That name has already been used, be more creative dingus kong");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected JsonElement parseJSON(String string) throws GeoffreyCommandError {
|
protected JsonElement parseJSON(String string) throws GeoffreyCommandError {
|
||||||
|
|
|
@ -71,6 +71,16 @@ commands:
|
||||||
aliases: [add_resource]
|
aliases: [add_resource]
|
||||||
permission: geoffrey.add
|
permission: geoffrey.add
|
||||||
usage: /add_resource [resource name] [farm name]
|
usage: /add_resource [resource name] [farm name]
|
||||||
|
geoffrey_add_tunnel:
|
||||||
|
description: Adds a tunnel to a location
|
||||||
|
aliases: [add_tunnel]
|
||||||
|
permission: geoffrey.add
|
||||||
|
usage: /add_tunnel [tunnel direction] [tunnel number] [location name]
|
||||||
|
geoffrey_delete:
|
||||||
|
description: Deletes a location in Geoffrey
|
||||||
|
aliases: [delete]
|
||||||
|
permission: geoffrey.add
|
||||||
|
usage: /delete [location name]
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
add:
|
add:
|
||||||
|
|
Loading…
Reference in New Issue