commit 03130c7e6da045306e895d31f13c048a439a12a0 Author: Joey Hines Date: Wed Dec 18 13:48:00 2019 -0600 Initial commit + Implemented a simple proof of concept `find` command diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3d13e3f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.idea/ +*.iml +target/ +dependency-reduced-pom.xml \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..4b94a85 --- /dev/null +++ b/pom.xml @@ -0,0 +1,150 @@ + + + 4.0.0 + com.zerohighdef + GeoffreyMC + + 1.0 + jar + + + + GeoffreyMC + A plugin for accessing Geoffrey in-game + https://geoffrey.zerohighdef.com/ + + + + + ZeroHD + https://www.zerohighdef.com + + + + + + ZeroHD + com.zerohighdef.geoffrey.GeoffreyMC + UTF-8 + + + + + org.spigotmc + spigot-api + 1.14.4-R0.1-SNAPSHOT + provided + + + commons-lang + commons-lang + 2.6 + + + log4j + log4j + 1.2.17 + + + xyz.etztech + EtzCore + 1.0.5 + + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + mvn-repo + https://mvnrepository.com/artifact/ + + + etztech-repo + http://repo.etztech.xyz + + + jcenter + http://jcenter.bintray.com + + + jitpack.io + https://jitpack.io + + + + + src/main/java + clean install + + + src/main/resources + + true + + plugin.yml + config.yml + + + + src/main/resources + + false + + **/*.java + plugin.yml + + + + + + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.0.2 + + + + true + lib/ + xyz.etztech.minecraftmanager.MinecraftManager + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.1.1 + + + package + + shade + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + + \ No newline at end of file diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/FindCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/FindCommand.java new file mode 100644 index 0000000..947a4fb --- /dev/null +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/FindCommand.java @@ -0,0 +1,64 @@ +package com.zerohighdef.geoffrey.Commands; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.zerohighdef.geoffrey.GeoffreyMC; +import com.zerohighdef.geoffrey.Models.GeoffreyLocation; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import xyz.etztech.core.web.ICallback; + +import java.util.HashMap; +import java.util.Map; + +public class FindCommand extends GeoffreyCommand { + + public FindCommand(GeoffreyMC plugin) { + super(plugin); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + String locationName = args[0]; + Map params = new HashMap(); + + params.put("search", locationName); + RunCommand("find_location", params, new CommandCallback((sender))); + + return true; + } + + protected String formatedCommand(String string) { + JsonArray list = new JsonParser().parse(string).getAsJsonArray(); + StringBuilder stringBuilder = new StringBuilder(); + + stringBuilder.append("The following locations match:\n"); + for (JsonElement element: list) { + JsonObject jsonObject = element.getAsJsonObject(); + GeoffreyLocation geoffreyLocation = new GeoffreyLocation(jsonObject); + + stringBuilder.append(geoffreyLocation.getFormattedLocationString()); + stringBuilder.append("\n"); + } + + return stringBuilder.toString(); + } + + private class CommandCallback implements ICallback { + private CommandSender sender; + + CommandCallback(CommandSender sender) { + this.sender = sender; + } + + @Override + public void invoke(String s) { + + String msg = formatedCommand(s); + sender.sendMessage(ChatColor.GREEN + msg); + } + } +} diff --git a/src/main/java/com/zerohighdef/geoffrey/Commands/GeoffreyCommand.java b/src/main/java/com/zerohighdef/geoffrey/Commands/GeoffreyCommand.java new file mode 100644 index 0000000..070b69f --- /dev/null +++ b/src/main/java/com/zerohighdef/geoffrey/Commands/GeoffreyCommand.java @@ -0,0 +1,31 @@ +package com.zerohighdef.geoffrey.Commands; + +import com.zerohighdef.geoffrey.GeoffreyMC; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import xyz.etztech.core.web.CoreWeb; +import xyz.etztech.core.web.ICallback; + +import java.util.Map; + +public class GeoffreyCommand implements CommandExecutor { + private GeoffreyMC plugin; + + public GeoffreyCommand(GeoffreyMC plugin) { + this.plugin = plugin; + } + + protected void RunCommand(String commandName, Map params, ICallback callback) { + String url = plugin.getBaseURL() + "/command/" + commandName + "/"; + params.put("api", plugin.getAPIToken()); + + CoreWeb.asyncGetCallback(plugin, url, params, callback); + } + + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + return false; + } +} diff --git a/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java b/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java new file mode 100644 index 0000000..fd97e53 --- /dev/null +++ b/src/main/java/com/zerohighdef/geoffrey/GeoffreyMC.java @@ -0,0 +1,39 @@ +package com.zerohighdef.geoffrey; + +import com.zerohighdef.geoffrey.Commands.FindCommand; +import org.bukkit.plugin.java.JavaPlugin; + +public final class GeoffreyMC extends JavaPlugin { + private String APIToken = "ZIcJJHJTBqkdjAzxqJUmDQfLc"; + private String BaseURL = "https://test.zerohighdef.com/GeoffreyApp/api"; + + @Override + public void onEnable() { + // Plugin startup logic + + FindCommand findCommand = new FindCommand(this); + this.getCommand("find").setExecutor(findCommand); + + } + + @Override + public void onDisable() { + // Plugin shutdown logic + } + + public String getAPIToken() { + return APIToken; + } + + public void setAPIToken(String APIToken) { + this.APIToken = APIToken; + } + + public String getBaseURL() { + return BaseURL; + } + + public void setBaseURL(String baseURL) { + BaseURL = baseURL; + } +} diff --git a/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyLocation.java b/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyLocation.java new file mode 100644 index 0000000..d806b9a --- /dev/null +++ b/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyLocation.java @@ -0,0 +1,73 @@ +package com.zerohighdef.geoffrey.Models; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +public class GeoffreyLocation { + private int xCoord; + private int zCoord; + private String locationName; + private GeoffreyPlayer owner; + private String dimension; + private String tunnelString = null; + + public GeoffreyLocation(JsonObject locationJSON) { + this.xCoord = locationJSON.get("x_coord").getAsInt(); + this.zCoord = locationJSON.get("z_coord").getAsInt(); + this.locationName = locationJSON.get("name").getAsString(); + this.owner = new GeoffreyPlayer(locationJSON.getAsJsonArray("owner").getAsJsonArray().get(0).getAsJsonObject()); + this.dimension = locationJSON.get("dimension").getAsString(); + + JsonElement tunnelElement = locationJSON.get("tunnel"); + + if (!tunnelElement.isJsonNull()) { + this.tunnelString = tunnelElement.getAsString(); + } + } + + public GeoffreyLocation(int xCoord, int zCoord, String locationName, GeoffreyPlayer owner, String dimension) { + this.xCoord = xCoord; + this.zCoord = zCoord; + this.locationName = locationName; + this.owner = owner; + this.dimension = dimension; + } + + public String getPositionString() { + return "(x=" + xCoord + ",z=" + zCoord + ")"; + } + + public String getFormattedLocationString() { + String locationString = locationName + " @ " + getPositionString() + " Owner: " + owner.getUsername(); + + if (tunnelString != null) { + locationString += " Tunnel: " + tunnelString; + } + + return locationString; + } + + public int getxCoord() { + return xCoord; + } + + public int getzCoord() { + return zCoord; + } + + public String getLocationName() { + return locationName; + } + + public GeoffreyPlayer getOwner() { + return owner; + } + + public String getDimension() { + return dimension; + } + + public String getTunnel() { + return tunnelString; + } +} diff --git a/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyPlayer.java b/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyPlayer.java new file mode 100644 index 0000000..350063e --- /dev/null +++ b/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyPlayer.java @@ -0,0 +1,29 @@ +package com.zerohighdef.geoffrey.Models; + + +import com.google.gson.JsonObject; + +import java.util.UUID; + +public class GeoffreyPlayer { + private String username; + private String mcUUID; + + public GeoffreyPlayer(JsonObject playerJSON) { + this.username = playerJSON.get("name").getAsString(); + this.mcUUID = playerJSON.get("mc_uuid").getAsString(); + } + + public GeoffreyPlayer(String username, String mcUUID) { + this.username = username; + this.mcUUID = mcUUID; + } + + public String getUsername() { + return username; + } + + public String getMcUUID() { + return mcUUID; + } +} diff --git a/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyTunnel.java b/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyTunnel.java new file mode 100644 index 0000000..6ccd165 --- /dev/null +++ b/src/main/java/com/zerohighdef/geoffrey/Models/GeoffreyTunnel.java @@ -0,0 +1,37 @@ +package com.zerohighdef.geoffrey.Models; + +import com.google.gson.JsonObject; + +public class GeoffreyTunnel { + private String locationName; + private String tunnelDirection; + private int tunnelNumber; + + public GeoffreyTunnel(JsonObject tunnelJSON) { + this.locationName = tunnelJSON.get("location_name").getAsString(); + this.tunnelDirection = tunnelJSON.get("tunnel_direction").getAsString(); + this.tunnelNumber = tunnelJSON.get("tunnel_number").getAsInt(); + } + + public GeoffreyTunnel(String locationName, String tunnelDirection, int tunnelNumber) { + this.locationName = locationName; + this.tunnelDirection = tunnelDirection; + this.tunnelNumber = tunnelNumber; + } + + public String getTunnelLocationString() { + return tunnelDirection + " " + tunnelNumber; + } + + public int getTunnelNumber() { + return tunnelNumber; + } + + public String getTunnelDirection() { + return tunnelDirection; + } + + public String getLocationName() { + return locationName; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..b760e93 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,9 @@ +name: version +version: ${version} +description: Geoffrey API Plugin for PaperMC +main: ${mainClass} + +commands: + geoffrey_find: + description: Finds a location in Geoffrey + aliases: [find, find_location]