Added location command and remove_resident command\

+ Fixed AddTunnel command
+ Small wording change
pull/2/head
Joey Hines 2020-01-08 13:32:33 -06:00
parent e7bddf51cb
commit d764c31208
7 changed files with 160 additions and 5 deletions

View File

@ -43,7 +43,7 @@ public class AddResidentCommand extends GeoffreyCommand {
}
}
else {
sender.sendMessage(ChatColor.RED + "Console can not add residents!");
sender.sendMessage(ChatColor.RED + "Console cannot add residents!");
}
return true;

View File

@ -38,8 +38,8 @@ public class AddTunnelCommand extends GeoffreyCommand {
if ((sender instanceof Player)) {
Map<String, String> params = new HashMap<String, String>();
if (args.length >= 3) {
String name[] = Arrays.copyOfRange(args, 3, args.length);
if (args.length > 2) {
String name[] = Arrays.copyOfRange(args, 2, args.length);
// this is a hack
String paramName = (commmandName.compareTo("edit_tunnel") == 0) ? "loc_name" : "location_name";
params.put(paramName, StringUtils.join(name, " "));

View File

@ -0,0 +1,56 @@
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;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Map;
public class LocationsCommand extends GeoffreyCommand {
public LocationsCommand(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>();
params.put("mc_uuid", ((Player) sender).getPlayer().getUniqueId().toString().replace("-", ""));
RunCommand("me", params, Method.GET, new CommandCallback(sender));
}
else {
sender.sendMessage(ChatColor.RED + "Console does not have locations ");
return false;
}
return true;
}
private class CommandCallback extends GeoffreyAPICallback {
CommandCallback(CommandSender sender) {
super(sender);
}
@Override
public void invoke(String s) {
try {
JsonElement json = parseJSON(s);
String msg = ChatColor.BOLD + "You own the following locations:\n" + ChatColor.RESET + locationList(json, 5);
commandSender.sendMessage(ChatColor.GREEN + msg);
}
catch (GeoffreyCommandError e) {
return;
}
}
}
}

View File

@ -0,0 +1,74 @@
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;
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 RemoveResidentCommand extends GeoffreyCommand {
public RemoveResidentCommand(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("town_name", StringUtils.join(name, " "));
Player player = ((Player) sender).getPlayer();
params.put("mc_uuid", player.getUniqueId().toString().replace("-", ""));
params.put("resident_name", args[0]);
RunCommand("remove_resident", params, Method.POST , new CommandCallback(sender, args[0]));
}
else if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "Too few parameters given.");
return false;
}
}
else {
sender.sendMessage(ChatColor.RED + "Console cannot remove residents!");
}
return true;
}
private class CommandCallback extends GeoffreyAPICallback {
private String residentName;
CommandCallback(CommandSender sender, String residentName) {
super(sender);
errors.put("ResidentNotFoundError", "Ain't no one in this darn town named" + residentName + "you goob");
errors.put("LocationLookUpError", "You do not have a town by that name you ding dong goober.");
this.residentName = residentName;
}
@Override
public void invoke(String s) {
try {
JsonElement json = parseJSON(s);
String msg = ChatColor.GREEN + residentName + "has been removed from your town";
commandSender.sendMessage(msg);
}
catch (GeoffreyCommandError e) {
return;
}
}
}
}

View File

@ -83,6 +83,12 @@ public final class GeoffreyMC extends JavaPlugin {
InfoCommand infoCommand = new InfoCommand(this);
this.getCommand("geoffrey_info").setExecutor(infoCommand);
LocationsCommand locationsCommand = new LocationsCommand(this);
this.getCommand("geoffrey_locations").setExecutor(locationsCommand);
RemoveResidentCommand removeResidentCommand = new RemoveResidentCommand(this);
this.getCommand("geoffrey_remove_resident").setExecutor(removeResidentCommand);
}
}

View File

@ -51,7 +51,7 @@ public class GeoffreyLocation {
}
public String getInfoString() {
return ChatColor.BOLD + getFormattedLocationString() + ChatColor.RESET;
return ChatColor.BOLD + getFormattedLocationString().replace(" ", " " + ChatColor.BOLD) + ChatColor.RESET;
}
public int getxCoord() {

View File

@ -7,14 +7,17 @@ commands:
geoffrey_find:
description: Finds a location in Geoffrey
aliases: [find, find_location]
permission: geoffrey.search
usage: /find [location name]
geoffrey_selling:
description: Finds an item for sale in Geoffrey
aliases: [selling]
permission: geoffrey.search
usage: /selling [item name]
geoffrey_selling_price:
description: Finds an item for sale in Geoffrey, sorted by price
aliases: [selling_price]
permission: geoffrey.search
usage: /selling_price [item name]
geoffrey_add_base:
description: Adds a base to Geoffrey
@ -109,20 +112,36 @@ commands:
geoffrey_find_around:
description: Finds locations around your current position
aliases: [find_around]
permission: geoffrey.search
usage: /find_around [radius]
geoffrey_find_farm:
description: Finds a farm producing a resource
aliases: [find_farm]
permission: geoffrey.search
usage: /find_farm [resource name]
geoffrey_info:
description: Gives info on a location
permission: geoffrey.search
aliases: [info]
usage: /info [location_name]
usage: /info [location name]
geoffrey_locations:
description: Displays all of your locations
permission: geoffrey.search
aliases: [locations]
usage: /locations
geoffrey_remove_resident:
description: Removes a resident from your town
aliases: [remove_resident]
permission: geoffrey.add
usage: /remove_resident [resident name] [town name]
permissions:
add:
description: Permission to add things to Geoffrey
default: false
search:
description: Permission use search commands in Geoffrey
default: false
register:
description: Permission to register for Geoffrey
default: false