From d834c95b003fdb893ca6c9199f09b2cdd0fce4c7 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sat, 21 Dec 2019 15:43:53 -0500 Subject: [PATCH] Added register command --- .../geoffrey/Commands/RegisterCommand.java | 62 +++++++++++++++++++ .../com/zerohighdef/geoffrey/GeoffreyMC.java | 4 ++ src/main/resources/plugin.yml | 9 +++ 3 files changed, 75 insertions(+) create mode 100644 src/main/java/com/zerohighdef/geoffrey/Commands/RegisterCommand.java diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/RegisterCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/RegisterCommand.java new file mode 100644 index 0000000..0ac3e36 --- /dev/null +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/RegisterCommand.java @@ -0,0 +1,62 @@ +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.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 RegisterCommand extends GeoffreyCommand{ + + public RegisterCommand(GeoffreyMC plugin) { + super(plugin); + } + + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + if ((sender instanceof Player)) { + Map params = new HashMap(); + Player player = ((Player) sender).getPlayer(); + + params.put("player_name", player.getName()); + params.put("discord_uuid", ""); + + RunCommand("register", params, Method.POST , new CommandCallback(sender)); + } + else { + sender.sendMessage(ChatColor.RED + "Console can not register!"); + } + + return true; + } + + private class CommandCallback extends GeoffreyAPICallback { + + CommandCallback(CommandSender sender) { + super(sender); + errors.put("LocationLookUpError", "You have more than one location. Please specify a name."); + } + + @Override + public void invoke(String s) { + try { + JsonElement json = parseJSON(s); + commandSender.sendMessage(ChatColor.GREEN + "You have been registered for Geoffrey!"); + + } + 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 68195d0..bfa5e9d 100644 --- a/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java +++ b/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java @@ -2,6 +2,7 @@ package com.zerohighdef.geoffrey; import com.zerohighdef.geoffrey.Commands.AddLocationCommand; import com.zerohighdef.geoffrey.Commands.FindCommand; +import com.zerohighdef.geoffrey.Commands.RegisterCommand; import com.zerohighdef.geoffrey.Commands.SellingCommand; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; @@ -37,6 +38,9 @@ public final class GeoffreyMC extends JavaPlugin { this.getCommand("geoffrey_add_town").setExecutor(addLocationCommand); this.getCommand("geoffrey_add_farm").setExecutor(addLocationCommand); this.getCommand("geoffrey_add_attraction").setExecutor(addLocationCommand); + + RegisterCommand registerCommand = new RegisterCommand(this); + this.getCommand("geoffrey_register").setExecutor(registerCommand); } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 63e3c49..b805fa5 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -43,7 +43,16 @@ commands: aliases: [add_market] permission: geoffrey.add usage: Adds a market at your current location to Geoffrey + geoffrey_register: + description: Registers a player for Geoffrey + aliases: [register] + permission: geoffrey.register + usage: Registers you in Geoffrey permissions: add: description: Permission to add things to Geoffrey + default: false + register: + description: Permission to register in Geoffrey + default: false