From 1962110dbdb4190d517f352b7051e3192c45f242 Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Fri, 26 Apr 2024 14:45:52 -0400 Subject: [PATCH] Spigot -> Velocity --- {DemoSpigotPlugin => DemoPlugin}/.gitignore | 0 {DemoSpigotPlugin => DemoPlugin}/README.md | 0 DemoPlugin/pom.xml | 85 ++++++++++++ .../java/cc/restfulmc/demo/DemoPlugin.java | 26 ++++ .../demo/listener/ServerPingListener.java | 59 ++++++++ DemoSpigotPlugin/pom.xml | 131 ------------------ .../cc/restfulmc/demo/DemoSpigotPlugin.java | 15 -- .../demo/listener/ServerPingListener.java | 58 -------- .../src/main/resources/plugin.yml | 6 - 9 files changed, 170 insertions(+), 210 deletions(-) rename {DemoSpigotPlugin => DemoPlugin}/.gitignore (100%) rename {DemoSpigotPlugin => DemoPlugin}/README.md (100%) create mode 100644 DemoPlugin/pom.xml create mode 100644 DemoPlugin/src/main/java/cc/restfulmc/demo/DemoPlugin.java create mode 100644 DemoPlugin/src/main/java/cc/restfulmc/demo/listener/ServerPingListener.java delete mode 100644 DemoSpigotPlugin/pom.xml delete mode 100644 DemoSpigotPlugin/src/main/java/cc/restfulmc/demo/DemoSpigotPlugin.java delete mode 100644 DemoSpigotPlugin/src/main/java/cc/restfulmc/demo/listener/ServerPingListener.java delete mode 100644 DemoSpigotPlugin/src/main/resources/plugin.yml diff --git a/DemoSpigotPlugin/.gitignore b/DemoPlugin/.gitignore similarity index 100% rename from DemoSpigotPlugin/.gitignore rename to DemoPlugin/.gitignore diff --git a/DemoSpigotPlugin/README.md b/DemoPlugin/README.md similarity index 100% rename from DemoSpigotPlugin/README.md rename to DemoPlugin/README.md diff --git a/DemoPlugin/pom.xml b/DemoPlugin/pom.xml new file mode 100644 index 0000000..63317c2 --- /dev/null +++ b/DemoPlugin/pom.xml @@ -0,0 +1,85 @@ + + + 4.0.0 + + + me.braydon + DemoPlugin + 1.0.0 + + + + 8 + ${java.version} + ${java.version} + UTF-8 + + + + ${project.artifactId} + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 + + ${java.version} + ${java.version} + + + + false + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.5.3 + + false + + + + package + + shade + + + + + + + + + + src/main/resources + true + + + + + + + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + + + com.velocitypowered + velocity-api + 3.3.0-SNAPSHOT + provided + + + \ No newline at end of file diff --git a/DemoPlugin/src/main/java/cc/restfulmc/demo/DemoPlugin.java b/DemoPlugin/src/main/java/cc/restfulmc/demo/DemoPlugin.java new file mode 100644 index 0000000..f1c9a01 --- /dev/null +++ b/DemoPlugin/src/main/java/cc/restfulmc/demo/DemoPlugin.java @@ -0,0 +1,26 @@ +package cc.restfulmc.demo; + +import cc.restfulmc.demo.listener.ServerPingListener; +import com.google.inject.Inject; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; +import com.velocitypowered.api.plugin.Plugin; +import com.velocitypowered.api.proxy.ProxyServer; + +/** + * @author Braydon + */ +@Plugin(id = "demoplugin", name = "DemoPlugin", version = "1.0.0") +public final class DemoPlugin { + private final ProxyServer server; + + @Inject + public DemoPlugin(ProxyServer server) { + this.server = server; + } + + @Subscribe + public void onProxyInitialize(ProxyInitializeEvent event) { + server.getEventManager().register(this, new ServerPingListener()); + } +} \ No newline at end of file diff --git a/DemoPlugin/src/main/java/cc/restfulmc/demo/listener/ServerPingListener.java b/DemoPlugin/src/main/java/cc/restfulmc/demo/listener/ServerPingListener.java new file mode 100644 index 0000000..5044f44 --- /dev/null +++ b/DemoPlugin/src/main/java/cc/restfulmc/demo/listener/ServerPingListener.java @@ -0,0 +1,59 @@ +package cc.restfulmc.demo.listener; + +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.proxy.ProxyPingEvent; +import com.velocitypowered.api.proxy.server.ServerPing; +import com.velocitypowered.api.util.ModInfo; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.ThreadLocalRandom; + +/** + * @author Braydon + */ +public final class ServerPingListener { + private static final String[] MESSAGES = new String[] { + "wow omg so cool!", + "Hello World!", + "Rainnny was here", + "Star on GitHub!", + "restfulmc.cc", + "discord.restfulmc.cc" + }; + private static final String[] PLAYERS = new String[] { + "Rainnny", "Notch", "jeb_", "hypixel", "Dinnerbone", "C418", "g", "hey" + }; + + @Subscribe + public void onProxyPing(ProxyPingEvent event) { + ServerPing ping = event.getPing(); // Get the ping response + ThreadLocalRandom random = ThreadLocalRandom.current(); + + // Update the version + ServerPing.Version version = new ServerPing.Version(ping.getVersion().getProtocol(), "RESTfulMC Demo"); + + // Update the player count + List playerSamples = new ArrayList<>(); + for (int i = 0; i < 3; i++) { + playerSamples.add(new ServerPing.SamplePlayer(PLAYERS[random.nextInt(PLAYERS.length)], UUID.randomUUID())); + } + ServerPing.Players players = new ServerPing.Players(random.nextInt(300, 25000), 30000, playerSamples); + + TextComponent motd = Component.text(String.join("\n", + "§f §2§lRESTfulMC §7Demo Server", + "§7 " + MESSAGES[random.nextInt(MESSAGES.length)] + )); + + // Update the mod info + ModInfo modInfo = ping.getModinfo().orElse(ModInfo.DEFAULT); + modInfo.getMods().add(new ModInfo.Mod("bob", "1.0")); + modInfo.getMods().add(new ModInfo.Mod("ross", "1.0")); + + // Set the ping response + event.setPing(new ServerPing(version, players, motd, ping.getFavicon().orElse(null), modInfo)); + } +} \ No newline at end of file diff --git a/DemoSpigotPlugin/pom.xml b/DemoSpigotPlugin/pom.xml deleted file mode 100644 index 866f920..0000000 --- a/DemoSpigotPlugin/pom.xml +++ /dev/null @@ -1,131 +0,0 @@ - - - 4.0.0 - - - me.braydon - DemoSpigotPlugin - 1.0.0 - - - - 8 - ${java.version} - ${java.version} - UTF-8 - - - - ${project.artifactId} - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.13.0 - - ${java.version} - ${java.version} - - - - false - - - - - - org.apache.maven.plugins - maven-assembly-plugin - 3.7.1 - - ${project.basedir}/jars - false - - jar-with-dependencies - - - - - package - - single - - - - - - - - pl.project13.maven - git-commit-id-plugin - 4.9.10 - - - - revision - - - - - git - $PROJECT.BASEDIR$/.git - true - true - src/main/resources/git.properties - full - $USER.TIMEZONE$ - MM-dd-yyyy@HH:mm:ss - - ^git.branch$ - ^git.build.(time|version)$ - ^git.commit.id.(abbrev|full)$ - ^git.build.user.name$ - - - - - - - - - src/main/resources - true - - - - - - - - rainnny-repo-serverjars - https://maven.rainnny.club/serverjars - - - - - dmulloy2-repo - https://repo.dmulloy2.net/repository/public/ - - - - - - - org.github - PaperSpigot - 1.8.8 - provided - - - - - com.comphenix.protocol - ProtocolLib - 5.1.0 - provided - - - \ No newline at end of file diff --git a/DemoSpigotPlugin/src/main/java/cc/restfulmc/demo/DemoSpigotPlugin.java b/DemoSpigotPlugin/src/main/java/cc/restfulmc/demo/DemoSpigotPlugin.java deleted file mode 100644 index f19672c..0000000 --- a/DemoSpigotPlugin/src/main/java/cc/restfulmc/demo/DemoSpigotPlugin.java +++ /dev/null @@ -1,15 +0,0 @@ -package cc.restfulmc.demo; - -import cc.restfulmc.demo.listener.ServerPingListener; -import com.comphenix.protocol.ProtocolLibrary; -import org.bukkit.plugin.java.JavaPlugin; - -/** - * @author Braydon - */ -public final class DemoSpigotPlugin extends JavaPlugin { - @Override - public void onEnable() { - ProtocolLibrary.getProtocolManager().addPacketListener(new ServerPingListener(this)); - } -} \ No newline at end of file diff --git a/DemoSpigotPlugin/src/main/java/cc/restfulmc/demo/listener/ServerPingListener.java b/DemoSpigotPlugin/src/main/java/cc/restfulmc/demo/listener/ServerPingListener.java deleted file mode 100644 index e522a9e..0000000 --- a/DemoSpigotPlugin/src/main/java/cc/restfulmc/demo/listener/ServerPingListener.java +++ /dev/null @@ -1,58 +0,0 @@ -package cc.restfulmc.demo.listener; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.events.PacketAdapter; -import com.comphenix.protocol.events.PacketEvent; -import com.comphenix.protocol.wrappers.WrappedGameProfile; -import com.comphenix.protocol.wrappers.WrappedServerPing; -import cc.restfulmc.demo.DemoSpigotPlugin; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.ThreadLocalRandom; - -/** - * @author Braydon - */ -public final class ServerPingListener extends PacketAdapter { - private static final String[] MESSAGES = new String[] { - "wow omg so cool!", - "Hello World!", - "Rainnny was here", - "Star on GitHub!", - "restfulmc.cc", - "discord.restfulmc.cc" - }; - private static final String[] PLAYERS = new String[] { - "Rainnny", "Notch", "jeb_", "hypixel", "Dinnerbone", "C418", "g", "hey" - }; - - public ServerPingListener(DemoSpigotPlugin plugin) { - super(plugin, PacketType.Status.Server.SERVER_INFO); - } - - @Override - public void onPacketSending(PacketEvent event) { - WrappedServerPing ping = event.getPacket().getServerPings().read(0); - ThreadLocalRandom random = ThreadLocalRandom.current(); - - // Update the MOTD - ping.setMotD(String.join("\n", - "§f §2§lRESTfulMC §7Demo Server", - "§7 " + MESSAGES[random.nextInt(MESSAGES.length)] - )); - - // Update the player count - ping.setPlayersOnline(random.nextInt(300, 25000)); - ping.setPlayersMaximum(30000); - - List playerSamples = new ArrayList<>(); - for (int i = 0; i < 3; i++) { - playerSamples.add(new WrappedGameProfile(UUID.randomUUID(), PLAYERS[random.nextInt(PLAYERS.length)])); - } - ping.setPlayers(playerSamples); - - ping.setVersionName("RESTfulMC Demo"); - } -} \ No newline at end of file diff --git a/DemoSpigotPlugin/src/main/resources/plugin.yml b/DemoSpigotPlugin/src/main/resources/plugin.yml deleted file mode 100644 index 8787661..0000000 --- a/DemoSpigotPlugin/src/main/resources/plugin.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: DemoSpigotPlugin -main: cc.restfulmc.demo.DemoSpigotPlugin -version: ${project.version}-${git.commit.id.abbrev} -author: Braydon (Rainnny) -website: https://restfulmc.cc -depend: [ProtocolLib] \ No newline at end of file