Initial commit

+ Implemented a simple proof of concept `find` command
master
Joey Hines 2019-12-18 13:48:00 -06:00
commit 03130c7e6d
9 changed files with 436 additions and 0 deletions

4
.gitignore vendored 100644
View File

@ -0,0 +1,4 @@
.idea/
*.iml
target/
dependency-reduced-pom.xml

150
pom.xml 100644
View File

@ -0,0 +1,150 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.zerohighdef</groupId>
<artifactId>GeoffreyMC</artifactId>
<!-- Version is used in plugin.yml -->
<version>1.0</version>
<packaging>jar</packaging>
<!-- Plugin Information -->
<!-- Name, Description, and URL are used in plugin.yml -->
<name>GeoffreyMC</name>
<description>A plugin for accessing Geoffrey in-game</description>
<url>https://geoffrey.zerohighdef.com/</url>
<developers>
<developer>
<name>ZeroHD</name>
<url>https://www.zerohighdef.com</url>
</developer>
</developers>
<properties>
<!-- Author and MainClass are used in plugin.yml -->
<author>ZeroHD</author>
<mainClass>com.zerohighdef.geoffrey.GeoffreyMC</mainClass>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.14.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>xyz.etztech</groupId>
<artifactId>EtzCore</artifactId>
<version>1.0.5</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>mvn-repo</id>
<url>https://mvnrepository.com/artifact/</url>
</repository>
<repository>
<id>etztech-repo</id>
<url>http://repo.etztech.xyz</url>
</repository>
<repository> <!-- This repo fixes issues with transitive dependencies -->
<id>jcenter</id>
<url>http://jcenter.bintray.com</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<defaultGoal>clean install</defaultGoal>
<resources>
<resource>
<directory>src/main/resources</directory>
<!-- Keeping filtering at true here reduces plugin.yml redundancy! -->
<filtering>true</filtering>
<includes>
<include>plugin.yml</include>
<include>config.yml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<!-- Keep filtering at false for other resources to prevent bad magic -->
<filtering>false</filtering>
<excludes>
<exclude>**/*.java</exclude>
<exclude>plugin.yml</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>xyz.etztech.minecraftmanager.MinecraftManager</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -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 <String, String> params = new HashMap<String, String>();
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);
}
}
}

View File

@ -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<String, String> 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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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]