From cc67bfd054ed0478796edc94ff670d5893ba286a Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Tue, 23 Apr 2024 00:58:35 -0400 Subject: [PATCH] Add demo Spigot plugin --- DemoSpigotPlugin/.gitignore | 28 ++++ DemoSpigotPlugin/pom.xml | 126 ++++++++++++++++++ .../me/braydon/demo/DemoSpigotPlugin.java | 15 +++ .../demo/listener/ServerPingListener.java | 57 ++++++++ .../src/main/resources/plugin.yml | 6 + 5 files changed, 232 insertions(+) create mode 100644 DemoSpigotPlugin/.gitignore create mode 100644 DemoSpigotPlugin/pom.xml create mode 100644 DemoSpigotPlugin/src/main/java/me/braydon/demo/DemoSpigotPlugin.java create mode 100644 DemoSpigotPlugin/src/main/java/me/braydon/demo/listener/ServerPingListener.java create mode 100644 DemoSpigotPlugin/src/main/resources/plugin.yml diff --git a/DemoSpigotPlugin/.gitignore b/DemoSpigotPlugin/.gitignore new file mode 100644 index 0000000..d1e6768 --- /dev/null +++ b/DemoSpigotPlugin/.gitignore @@ -0,0 +1,28 @@ +*.class +*.log +*.ctxt +.mtj.tmp/ +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar +hs_err_pid* +replay_pid* +.idea +cmake-build-*/ +.idea/**/mongoSettings.xml +*.iws +out/ +build/ +target/ +.idea_modules/ +atlassian-ide-plugin.xml +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +git.properties +pom.xml.versionsBackup \ No newline at end of file diff --git a/DemoSpigotPlugin/pom.xml b/DemoSpigotPlugin/pom.xml new file mode 100644 index 0000000..60ce53a --- /dev/null +++ b/DemoSpigotPlugin/pom.xml @@ -0,0 +1,126 @@ + + + 4.0.0 + + + me.braydon + DemoSpigotPlugin + 1.0.0 + + + + 8 + ${java.version} + ${java.version} + UTF-8 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + ${java.version} + ${java.version} + + + + false + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.5.0 + + false + + + + package + + shade + + + + + + + + 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 + 4.8.0 + provided + + + \ No newline at end of file diff --git a/DemoSpigotPlugin/src/main/java/me/braydon/demo/DemoSpigotPlugin.java b/DemoSpigotPlugin/src/main/java/me/braydon/demo/DemoSpigotPlugin.java new file mode 100644 index 0000000..0ab83ca --- /dev/null +++ b/DemoSpigotPlugin/src/main/java/me/braydon/demo/DemoSpigotPlugin.java @@ -0,0 +1,15 @@ +package me.braydon.demo; + +import com.comphenix.protocol.ProtocolLibrary; +import me.braydon.demo.listener.ServerPingListener; +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/me/braydon/demo/listener/ServerPingListener.java b/DemoSpigotPlugin/src/main/java/me/braydon/demo/listener/ServerPingListener.java new file mode 100644 index 0000000..13f4320 --- /dev/null +++ b/DemoSpigotPlugin/src/main/java/me/braydon/demo/listener/ServerPingListener.java @@ -0,0 +1,57 @@ +package me.braydon.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 me.braydon.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" + }; + 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"); + } +} \ No newline at end of file diff --git a/DemoSpigotPlugin/src/main/resources/plugin.yml b/DemoSpigotPlugin/src/main/resources/plugin.yml new file mode 100644 index 0000000..84e3b65 --- /dev/null +++ b/DemoSpigotPlugin/src/main/resources/plugin.yml @@ -0,0 +1,6 @@ +name: DemoSpigotPlugin +main: me.braydon.demo.DemoSpigotPlugin +version: ${project.version}-${git.commit.id.abbrev} +author: Braydon (Rainnny) +website: https://restfulmc.cc +depend: [ProtocolLib] \ No newline at end of file