From 4cf84003475894c29ec1c7c58194d7148e66d50e Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Thu, 26 Dec 2019 14:20:31 -0600 Subject: [PATCH] Added missing file (again) --- .../geoffrey/Commands/AddOwnerCommand.java | 76 +++++++++++++++++++ .../com/zerohighdef/geoffrey/GeoffreyMC.java | 3 + src/main/resources/plugin.yml | 9 ++- 3 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/zerohighdef/geoffrey/Commands/AddOwnerCommand.java diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/AddOwnerCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/AddOwnerCommand.java new file mode 100644 index 0000000..b7a279c --- /dev/null +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/AddOwnerCommand.java @@ -0,0 +1,76 @@ +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.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 AddOwnerCommand extends GeoffreyCommand { + + public AddOwnerCommand(GeoffreyMC plugin) { + super(plugin); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + if ((sender instanceof Player)) { + Map params = new HashMap(); + + if (args.length > 1) { + String name[] = Arrays.copyOfRange(args, 1, args.length); + params.put("location_name", StringUtils.join(name, " ")); + Player player = ((Player) sender).getPlayer(); + + params.put("mc_uuid", player.getUniqueId().toString().replace("-", "")); + params.put("new_owner_name", args[0]); + RunCommand("add_owner", 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 can not add residents!"); + } + + return true; + } + + private class CommandCallback extends GeoffreyAPICallback { + String new_owner_name; + + CommandCallback(CommandSender sender, String new_owner_name) { + super(sender); + errors.put("OwnerNotFoundError", "Ain't no one in this darn database named " + new_owner_name + "!"); + errors.put("IsOwnerError", new_owner_name + " is already an owner, stop having amosia."); + errors.put("LocationLookUpError", "You do not have a location by that name you ding dong goober."); + this.new_owner_name = new_owner_name; + } + + @Override + public void invoke(String s) { + try { + JsonElement json = parseJSON(s); + GeoffreyLocation location = new GeoffreyLocation(json.getAsJsonObject()); + + String msg = ChatColor.GREEN + new_owner_name + " has been added as an owner of " + location.getLocationName(); + commandSender.sendMessage(msg); + } + catch (GeoffreyCommandError e) { + return; + } + } + } +} diff --git a/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java b/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java index cdfb8db..34c3d56 100644 --- a/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java +++ b/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java @@ -44,6 +44,9 @@ public final class GeoffreyMC extends JavaPlugin { AddResidentCommand addResidentCommand = new AddResidentCommand(this); this.getCommand("geoffrey_add_resident").setExecutor(addResidentCommand); + + AddOwnerCommand addOwnerCommand = new AddOwnerCommand(this); + this.getCommand("geoffrey_add_owner").setExecutor(addOwnerCommand); } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f41a323..a5871e5 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -57,10 +57,15 @@ commands: permission: geoffrey.add usage: /add_item [item name] [amount per price] [price] [shop name] geoffrey_add_resident: - description: Adds a resident to a tow + description: Adds a resident to a town aliases: [add_resident] permission: geoffrey.add - usage: /add_resident [resident Name] [town name] + usage: /add_resident [resident name] [town name] + geoffrey_add_owner: + description: Adds a new owner to a location + aliases: [add_owner] + permission: geoffrey.add + usage: /add_owner [new owner name] [location name] permissions: add: