Spigot -> Velocity

This commit is contained in:
Braydon 2024-04-26 14:45:52 -04:00
parent 758a3bf0aa
commit 1962110dbd
9 changed files with 170 additions and 210 deletions

85
DemoPlugin/pom.xml Normal file

@ -0,0 +1,85 @@
<?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>
<!--Project Details-->
<groupId>me.braydon</groupId>
<artifactId>DemoPlugin</artifactId>
<version>1.0.0</version>
<!-- Properties -->
<properties>
<java.version>8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- Used for compiling the source code with the proper Java version -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<!-- Enable incremental builds, this is reversed due to -->
<!-- a bug as seen in https://issues.apache.org/jira/browse/MCOMPILER-209 -->
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
<!-- Handles shading of dependencies in the final output jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<!-- Filter the resources dir for placeholders -->
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<!-- Repositories -->
<repositories>
<!-- Used by Velocity -->
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>
<!-- Dependencies -->
<dependencies>
<!-- Server Jars -->
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>3.3.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

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

@ -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<ServerPing.SamplePlayer> 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));
}
}

@ -1,131 +0,0 @@
<?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>
<!--Project Details-->
<groupId>me.braydon</groupId>
<artifactId>DemoSpigotPlugin</artifactId>
<version>1.0.0</version>
<!-- Properties -->
<properties>
<java.version>8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- Used for compiling the source code with the proper Java version -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<!-- Enable incremental builds, this is reversed due to -->
<!-- a bug as seen in https://issues.apache.org/jira/browse/MCOMPILER-209 -->
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
<!-- Handles shading of dependencies in the final output jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.7.1</version>
<configuration>
<outputDirectory>${project.basedir}/jars</outputDirectory>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Used for generating a git properties file during build -->
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>4.9.10</version>
<executions>
<execution>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<prefix>git</prefix>
<dotGitDirectory>$PROJECT.BASEDIR$/.git</dotGitDirectory>
<injectAllReactorProjects>true</injectAllReactorProjects>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>src/main/resources/git.properties</generateGitPropertiesFilename>
<commitIdGenerationMode>full</commitIdGenerationMode>
<dateFormatTimeZone>$USER.TIMEZONE$</dateFormatTimeZone>
<dateFormat>MM-dd-yyyy@HH:mm:ss</dateFormat>
<includeOnlyProperties>
<includeOnlyProperty>^git.branch$</includeOnlyProperty>
<includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
<includeOnlyProperty>^git.build.user.name$</includeOnlyProperty>
</includeOnlyProperties>
</configuration>
</plugin>
</plugins>
<!-- Filter the resources dir for placeholders -->
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<!-- Repos -->
<repositories>
<repository>
<id>rainnny-repo-serverjars</id>
<url>https://maven.rainnny.club/serverjars</url>
</repository>
<!-- Used by ProtocolLib -->
<repository>
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/repository/public/</url>
</repository>
</repositories>
<dependencies>
<!-- Server Jars -->
<dependency>
<groupId>org.github</groupId>
<artifactId>PaperSpigot</artifactId>
<version>1.8.8</version>
<scope>provided</scope>
</dependency>
<!-- Libraries -->
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>5.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

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

@ -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<WrappedGameProfile> 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");
}
}

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