Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decommission zander-waterfall and create zander-velocity as new proxy. #19

Open
wants to merge 13 commits into
base: staging
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<packaging>pom</packaging>

<modules>
<module>zander-proxy</module>
<module>zander-waterfall</module>
<module>zander-velocity</module>
<module>zander-hub</module>
<module>zander-auth</module>
</modules>
Expand Down
90 changes: 90 additions & 0 deletions zander-velocity/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.modularsoft</groupId>
<artifactId>zander-velocity</artifactId>
<name>zander-velocity</name>
<version>1.2.0</version>
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.MF</exclude>
</excludes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>dev.dejvokep.boostedyaml</pattern>
<shadedPattern>org.modularsoft.zander.velocity.libs</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>papermc-repo</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>maven2</id>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>3.4.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<reporting>
<plugins>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.0</version>
</plugin>
</plugins>
</reporting>
<properties>
<maven.compiler.target>11</maven.compiler.target>
<java.version>17</java.version>
<maven.compiler.source>11</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
142 changes: 142 additions & 0 deletions zander-velocity/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>org.modularsoft</groupId>
<artifactId>zander-velocity</artifactId>
<version>1.2.0</version>
<packaging>jar</packaging>

<name>zander-velocity</name>

<properties>
<java.version>17</java.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.MF</exclude>
</excludes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>dev.dejvokep.boostedyaml</pattern>
<shadedPattern>org.modularsoft.zander.velocity.libs</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.0</version>
</plugin>
</plugins>
</reporting>

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

<dependencies>
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>3.4.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<scope>compile</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>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>dev.dejvokep</groupId>
<artifactId>boosted-yaml</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package org.modularsoft.zander.velocity;

import com.google.inject.Inject;
import com.velocitypowered.api.command.CommandManager;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.plugin.Dependency;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.PluginContainer;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
import dev.dejvokep.boostedyaml.YamlDocument;
import dev.dejvokep.boostedyaml.dvs.versioning.BasicVersioning;
import dev.dejvokep.boostedyaml.settings.dumper.DumperSettings;
import dev.dejvokep.boostedyaml.settings.general.GeneralSettings;
import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings;
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
import lombok.Getter;
import org.modularsoft.zander.velocity.commands.*;
import org.modularsoft.zander.velocity.events.*;
import org.modularsoft.zander.velocity.util.announcement.TipChatter;
import org.modularsoft.zander.velocity.util.api.Heartbeat;
import org.slf4j.Logger;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Objects;
import java.util.Optional;

@Plugin(
id = "zander-velocity",
authors = "ModularSoft",
description = "The proxy that allows the connection and integration of the Zander minecraft suite.",
name = "zander-velocity",
version = "1.2.0",
dependencies = {
@Dependency(id = "signedvelocity")
}
)
public class ZanderVelocityMain {
@Getter
private static Logger logger;
@Getter
public static ProxyServer proxy;
@Getter
private static YamlDocument config;
@Getter
private final CommandManager commandManager;

@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
// Event Listeners
proxy.getEventManager().register(this, new UserChatEvent());
proxy.getEventManager().register(this, new UserCommandSpyEvent()); // Issues
proxy.getEventManager().register(this, new UserOnDisconnect());
proxy.getEventManager().register(this, new UserOnLogin());
proxy.getEventManager().register(this, new UserOnProxyPing());
proxy.getEventManager().register(this, new UserOnSwitch());
proxy.getEventManager().register(this, new UserSocialSpyEvent()); // Issues

// Commands
CommandManager commandManager = proxy.getCommandManager();

commandManager.register(commandManager.metaBuilder("discord").build(), new discord());
commandManager.register(commandManager.metaBuilder("rules").build(), new rules());
commandManager.register(commandManager.metaBuilder("website").build(), new website());
commandManager.register(commandManager.metaBuilder("ping").build(), new ping());
commandManager.register(commandManager.metaBuilder("report").build(), new report());

// Start the Heartbeat task
Heartbeat.startHeartbeatTask();

// Start the Announcement Tip task
TipChatter.startAnnouncementTipTask();
}

@Inject
public ZanderVelocityMain(
ProxyServer proxy,
Logger logger,
CommandManager commandManager,
@DataDirectory Path dataDirectory
) {
this.proxy = proxy;
this.logger = logger;
this.commandManager = commandManager;

// Create configuration file
try {
config = YamlDocument.create(new File(dataDirectory.toFile(), "config.yml"),
Objects.requireNonNull(getClass().getResourceAsStream("/config.yml")),
GeneralSettings.DEFAULT,
LoaderSettings.builder().setAutoUpdate(true).build(),
DumperSettings.DEFAULT,
UpdaterSettings.builder().setVersioning(new BasicVersioning("config-version"))
.setOptionSorting(UpdaterSettings.OptionSorting.SORT_BY_DEFAULTS).build());

config.update();
config.save();
} catch (IOException e) {
logger.error("Could not create or load plugin configuration, plugin will now be disabled.");
Optional<PluginContainer> container = proxy.getPluginManager().getPlugin("zander-velocity");
container.ifPresent(pluginContainer -> pluginContainer.getExecutorService().shutdown());
}

logger.info("Zander Proxy has started.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.modularsoft.zander.velocity.commands;

import com.jayway.jsonpath.JsonPath;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand;
import dev.dejvokep.boostedyaml.route.Route;
import io.github.ModularEnigma.Request;
import io.github.ModularEnigma.Response;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import org.modularsoft.zander.velocity.ZanderVelocityMain;

public class discord implements SimpleCommand {
@Override
public void execute(final Invocation invocation) {
CommandSource source = invocation.source();
String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL"));
String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey"));

try {
// GET request to link to discord.
Request req = Request.builder()
.setURL(BaseAPIURL + "/web/configuration")
.setMethod(Request.Method.GET)
.addHeader("x-access-token", APIKey)
.build();

Response res = req.execute();
String json = res.getBody();
String siteAddress = JsonPath.read(json, "$.data.siteAddress");

Component message = Component.text("Get to know the community and join our Discord here: " + siteAddress + "/discord")
.color(NamedTextColor.BLUE);
message = message.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL,siteAddress + "/discord"));
source.sendMessage(message);
return;
} catch (Exception e) {
Component builder = Component.text("An error has occurred. Is the API down?").color(NamedTextColor.RED);
source.sendMessage(builder);
System.out.println(e);
}
}
}
Loading