Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<module>zander-velocity</module>
<module>zander-hub</module>
<module>zander-auth</module>
<module>zander-addon</module>
</modules>

<properties>
Expand Down
112 changes: 112 additions & 0 deletions zander-addon/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<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">
<parent>
<artifactId>zander</artifactId>
<groupId>org.modularsoft</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>zander-addon</artifactId>
<version>0.1.0</version>

<repositories>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.21.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.36</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.github.ModularEnigma</groupId>
<artifactId>Requests</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<release>21</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<configuration>
<relocations>
<relocation>
<pattern>io.github.ModularEnigma</pattern>
<shadedPattern>org.modularsoft.zander.addon.libs.requests</shadedPattern>
</relocation>
<relocation>
<pattern>com.jayway.jsonpath</pattern>
<shadedPattern>org.modularsoft.zander.addon.libs.jsonpath</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.gson</pattern>
<shadedPattern>org.modularsoft.zander.addon.libs.gson</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.MF</exclude>
<exclude>META-INF/*.txt</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.modularsoft.zander.addon;

import lombok.Getter;
import org.bukkit.plugin.java.JavaPlugin;
import org.modularsoft.zander.addon.api.PolicyApiServer;
import org.modularsoft.zander.addon.commands.PetTrustCommand;
import org.modularsoft.zander.addon.commands.PolicyCommand;
import org.modularsoft.zander.addon.commands.SocialCommand;
import org.modularsoft.zander.addon.events.PetTrustDamageListener;
import org.modularsoft.zander.addon.events.PetTrustInteractListener;
import org.modularsoft.zander.addon.events.PlayerEvents;
import org.modularsoft.zander.addon.gui.PolicyGUI;
import org.modularsoft.zander.addon.gui.SocialGUI;
import org.modularsoft.zander.addon.service.PetTrustService;
import org.modularsoft.zander.addon.service.PolicyService;

public class ZanderAddonMain extends JavaPlugin {
@Getter
private static ZanderAddonMain instance;
@Getter
private PolicyService policyService;
@Getter
private PetTrustService petTrustService;
private PolicyApiServer apiServer;

@Override
public void onEnable() {
instance = this;

saveDefaultConfig();

this.policyService = new PolicyService(this);
this.petTrustService = new PetTrustService(this);

if (getConfig().getBoolean("api-server.enabled", true)) {
this.apiServer = new PolicyApiServer(this);
this.apiServer.start();
}

PolicyGUI policyGUI = new PolicyGUI(this);
SocialGUI socialGUI = new SocialGUI(this);
getServer().getPluginManager().registerEvents(policyGUI, this);
getServer().getPluginManager().registerEvents(socialGUI, this);
getServer().getPluginManager().registerEvents(new PlayerEvents(this, policyGUI, socialGUI), this);
getServer().getPluginManager().registerEvents(new PetTrustInteractListener(this, petTrustService), this);
getServer().getPluginManager().registerEvents(new PetTrustDamageListener(this, petTrustService), this);

getCommand("policy").setExecutor(new PolicyCommand(this, policyService));
getCommand("social").setExecutor(new SocialCommand(this, socialGUI));
getCommand("pettrust").setExecutor(new PetTrustCommand(this, petTrustService));

getLogger().info("Zander Addon has been enabled.");
}

@Override
public void onDisable() {
if (this.apiServer != null) {
this.apiServer.stop();
}
getLogger().info("Zander Addon has been disabled.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package org.modularsoft.zander.addon.api;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import org.modularsoft.zander.addon.ZanderAddonMain;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;

public class PolicyApiServer {
private final ZanderAddonMain plugin;
private HttpServer server;
private final Gson gson = new Gson();

public PolicyApiServer(ZanderAddonMain plugin) {
this.plugin = plugin;
}

public void start() {
int port = plugin.getConfig().getInt("api-server.port", 8080);
try {
server = HttpServer.create(new InetSocketAddress(port), 0);
server.createContext("/api/config/policy", new PolicyHandler());
server.createContext("/api/config/social", new SocialHandler());
server.setExecutor(null); // creates a default executor
server.start();
plugin.getLogger().info("API Server started on port " + port);
} catch (IOException e) {
plugin.getLogger().severe("Could not start API Server: " + e.getMessage());
}
}

public void stop() {
if (server != null) {
server.stop(0);
plugin.getLogger().info("API Server stopped.");
}
}

private class PolicyHandler implements HttpHandler {
@Override
public void handle(HttpExchange exchange) throws IOException {
if (!exchange.getRequestMethod().equalsIgnoreCase("GET")) {
exchange.sendResponseHeaders(405, -1); // Method Not Allowed
return;
}

JsonObject data = new JsonObject();
data.addProperty("termsOfService", "https://raw.githubusercontent.com/craftingforchrist/Legal/master/terms.md");
data.addProperty("rules", "https://raw.githubusercontent.com/craftingforchrist/Legal/master/rules.md");
data.addProperty("privacy", "https://raw.githubusercontent.com/craftingforchrist/Legal/master/privacy.md");
data.addProperty("refund", "https://raw.githubusercontent.com/craftingforchrist/Legal/master/refund.md");

JsonObject response = new JsonObject();
response.addProperty("success", true);
response.add("data", data);

String jsonResponse = gson.toJson(response);
exchange.getResponseHeaders().set("Content-Type", "application/json");
exchange.sendResponseHeaders(200, jsonResponse.getBytes().length);
OutputStream os = exchange.getResponseBody();
os.write(jsonResponse.getBytes());
os.close();
}
}

private class SocialHandler implements HttpHandler {
@Override
public void handle(HttpExchange exchange) throws IOException {
if (!exchange.getRequestMethod().equalsIgnoreCase("GET")) {
exchange.sendResponseHeaders(405, -1);
return;
}

JsonObject data = new JsonObject();
data.addProperty("discord", "https://discord.gg/fGWNchS");
data.addProperty("facebook", "https://www.facebook.com/craft4christ/");
data.addProperty("twitter", "https://twitter.com/craft4christmc");
data.addProperty("instagram", "https://instagram.com/craftingforchrist");
data.addProperty("twitch", "https://www.twitch.tv/craftingforchrist");
data.addProperty("youtube", "https://www.youtube.com/channel/UCeijz6MNnya85LprMjPmYag");
data.addProperty("linkedin", "https://www.linkedin.com/company/68885022/");
data.addProperty("tiktok", "https://www.tiktok.com/@craftingforchrist");

JsonObject response = new JsonObject();
response.addProperty("success", true);
response.add("data", data);

String jsonResponse = gson.toJson(response);
exchange.getResponseHeaders().set("Content-Type", "application/json");
exchange.sendResponseHeaders(200, jsonResponse.getBytes().length);
OutputStream os = exchange.getResponseBody();
os.write(jsonResponse.getBytes());
os.close();
}
}
}
Loading