Update to Velocity 4.0.0

This commit is contained in:
Telesphoreo 2023-12-01 18:11:45 -06:00
parent d4710f1808
commit 60b32b05f1
8 changed files with 42 additions and 30 deletions

View File

@ -1,5 +1,6 @@
plugins { plugins {
id("net.kyori.blossom") version "1.3.1" id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.7"
id("net.kyori.blossom") version "2.1.0"
} }
group = rootProject.group group = rootProject.group
@ -24,8 +25,14 @@ tasks {
} }
} }
blossom { sourceSets {
replaceToken("@version@", rootProject.version) main {
blossom {
javaSources {
property("version", project.version.toString())
}
}
}
} }
publishing { publishing {
@ -40,6 +47,7 @@ dependencies {
compileOnly("org.projectlombok:lombok:1.18.30") compileOnly("org.projectlombok:lombok:1.18.30")
annotationProcessor("org.projectlombok:lombok:1.18.30") annotationProcessor("org.projectlombok:lombok:1.18.30")
compileOnly("org.json:json:20231013") compileOnly("org.json:json:20231013")
compileOnly("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT") implementation("net.kyori:adventure-text-minimessage:4.14.0")
annotationProcessor("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT") compileOnly("com.velocitypowered:velocity-api:4.0.0-SNAPSHOT")
annotationProcessor("com.velocitypowered:velocity-api:4.0.0-SNAPSHOT")
} }

View File

@ -0,0 +1,5 @@
package dev.plex;
class BuildParameters {
public static final String VERSION = "{{ version }}";
}

View File

@ -2,7 +2,7 @@ package dev.plex;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.event.lifecycle.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
@ -28,7 +28,7 @@ import java.util.logging.Logger;
@Plugin( @Plugin(
name = "Plex", name = "Plex",
id = "plex", id = "plex",
version = "@version@", version = "{{ version }}",
url = "https://plex.us.org", url = "https://plex.us.org",
description = "Plex provides a new experience for freedom servers.", description = "Plex provides a new experience for freedom servers.",
authors = {"Telesphoreo", "Taah"} authors = {"Telesphoreo", "Taah"}

View File

@ -2,9 +2,9 @@ package dev.plex.command;
import com.velocitypowered.api.command.CommandMeta; import com.velocitypowered.api.command.CommandMeta;
import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.ConsoleCommandSource;
import com.velocitypowered.api.command.SimpleCommand; import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.proxy.ConsoleCommandSource; import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.Player;
import dev.plex.Plex; import dev.plex.Plex;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
@ -43,10 +43,9 @@ public abstract class PlexCommand implements SimpleCommand
this.perms = getClass().getAnnotation(CommandPermissions.class); this.perms = getClass().getAnnotation(CommandPermissions.class);
this.commandSource = this.perms.source(); this.commandSource = this.perms.source();
CommandMeta.Builder meta = plugin.getServer().getCommandManager().metaBuilder(this.params.name()); CommandMeta.Builder meta = plugin.getServer().commandManager().createMetaBuilder(this.params.name());
meta.aliases(this.params.aliases()); meta.aliases(this.params.aliases());
meta.plugin(Plex.get()); plugin.getServer().commandManager().register(meta.build(), this);
plugin.getServer().getCommandManager().register(meta.build(), this);
} }
protected abstract Component execute(@NotNull CommandSource source, @Nullable Player player, @NotNull String[] args); protected abstract Component execute(@NotNull CommandSource source, @Nullable Player player, @NotNull String[] args);

View File

@ -8,6 +8,6 @@ public class PlexListener
public PlexListener() public PlexListener()
{ {
Plex.get().getServer().getEventManager().register(Plex.get(), this); Plex.get().getServer().eventManager().register(Plex.get(), this);
} }
} }

View File

@ -2,7 +2,7 @@ package dev.plex.listener.impl;
import com.velocitypowered.api.event.PostOrder; import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.player.DisconnectEvent;
import com.velocitypowered.api.event.player.ServerConnectedEvent; import com.velocitypowered.api.event.player.ServerConnectedEvent;
import dev.plex.Plex; import dev.plex.Plex;
import dev.plex.listener.PlexListener; import dev.plex.listener.PlexListener;
@ -14,27 +14,27 @@ public class ConnectionListener extends PlexListener
@Subscribe(order = PostOrder.FIRST) @Subscribe(order = PostOrder.FIRST)
public void onPlayerJoin(ServerConnectedEvent event) public void onPlayerJoin(ServerConnectedEvent event)
{ {
if (event.getPreviousServer().isPresent()) if (event.previousServer() != null)
{ {
Plex.get().server.sendMessage(miniMessage("<dark_gray>[<#ffbf00>o<dark_gray>] <yellow>" Plex.get().server.sendMessage(miniMessage("<dark_gray>[<#ffbf00>o<dark_gray>] <yellow>"
+ event.getPlayer().getUsername() + " switched from " + event.getPreviousServer().get().getServerInfo().getName() + event.player().username() + " switched from " + event.previousServer().serverInfo().name()
+ " to " + event.getServer().getServerInfo().getName())); + " to " + event.target().serverInfo().name()));
} }
else else
{ {
Plex.get().server.sendMessage(miniMessage("<dark_gray>[<green>+<dark_gray>] <yellow>" Plex.get().server.sendMessage(miniMessage("<dark_gray>[<green>+<dark_gray>] <yellow>"
+ event.getPlayer().getUsername() + " joined server " + event.getServer().getServerInfo().getName())); + event.player().username() + " joined server " + event.target().serverInfo().name()));
} }
} }
@Subscribe(order = PostOrder.FIRST) @Subscribe(order = PostOrder.FIRST)
public void onPlayerLeave(DisconnectEvent event) public void onPlayerLeave(DisconnectEvent event)
{ {
if (event.getPlayer().getCurrentServer().isPresent()) if (event.player().connectedServer() != null)
{ {
Plex.get().server.sendMessage(miniMessage("<dark_gray>[<red>-<dark_gray>] <yellow>" Plex.get().server.sendMessage(miniMessage("<dark_gray>[<red>-<dark_gray>] <yellow>"
+ event.getPlayer().getUsername() + " left server " + + event.player().username() + " left server " +
event.getPlayer().getCurrentServer().get().getServerInfo().getName())); event.player().connectedServer().serverInfo().name()));
} }
} }

View File

@ -2,7 +2,7 @@ package dev.plex.listener.impl;
import com.velocitypowered.api.event.PostOrder; import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyPingEvent; import com.velocitypowered.api.event.connection.ProxyPingEvent;
import com.velocitypowered.api.proxy.server.ServerPing; import com.velocitypowered.api.proxy.server.ServerPing;
import dev.plex.listener.PlexListener; import dev.plex.listener.PlexListener;
import dev.plex.settings.ServerSettings; import dev.plex.settings.ServerSettings;
@ -24,10 +24,10 @@ public class ServerListener extends PlexListener
String baseMotd = plugin.getConfig().as(ServerSettings.class).getServer().getMotd().get(ThreadLocalRandom.current().nextInt(plugin.getConfig().as(ServerSettings.class).getServer().getMotd().size())); String baseMotd = plugin.getConfig().as(ServerSettings.class).getServer().getMotd().get(ThreadLocalRandom.current().nextInt(plugin.getConfig().as(ServerSettings.class).getServer().getMotd().size()));
baseMotd = baseMotd.replace("\\n", "\n"); baseMotd = baseMotd.replace("\\n", "\n");
baseMotd = baseMotd.replace("%servername%", plugin.getConfig().as(ServerSettings.class).getServer().getName()); baseMotd = baseMotd.replace("%servername%", plugin.getConfig().as(ServerSettings.class).getServer().getName());
baseMotd = baseMotd.replace("%mcversion%", plugin.getServer().getVersion().getVersion().split(" ")[0]); baseMotd = baseMotd.replace("%mcversion%", plugin.getServer().version().version().split(" ")[0]);
baseMotd = baseMotd.replace("%randomgradient%", "<gradient:" + RandomUtil.getRandomColor().toString() + ":" + RandomUtil.getRandomColor().toString() + ">"); baseMotd = baseMotd.replace("%randomgradient%", "<gradient:" + RandomUtil.getRandomColor().toString() + ":" + RandomUtil.getRandomColor().toString() + ">");
ServerPing.Builder builder = event.getPing().asBuilder(); ServerPing.Builder builder = event.ping().asBuilder();
if (plugin.getConfig().as(ServerSettings.class).getServer().isColorizeMotd()) if (plugin.getConfig().as(ServerSettings.class).getServer().isColorizeMotd())
{ {
@ -45,7 +45,7 @@ public class ServerListener extends PlexListener
} }
builder.samplePlayers(plugin.getConfig().as(ServerSettings.class).getServer().getSample().stream().map(s -> new ServerPing.SamplePlayer(convertColorCodes(s), UUID.randomUUID())).toArray(ServerPing.SamplePlayer[]::new)); builder.samplePlayers(plugin.getConfig().as(ServerSettings.class).getServer().getSample().stream().map(s -> new ServerPing.SamplePlayer(convertColorCodes(s), UUID.randomUUID())).toArray(ServerPing.SamplePlayer[]::new));
builder.onlinePlayers(plugin.getServer().getPlayerCount() + plugin.getConfig().as(ServerSettings.class).getServer().getAddPlayerCount()); builder.onlinePlayers(plugin.getServer().countConnectedPlayers() + plugin.getConfig().as(ServerSettings.class).getServer().getAddPlayerCount());
if (plugin.getConfig().as(ServerSettings.class).getServer().isPlusOneMaxPlayer()) if (plugin.getConfig().as(ServerSettings.class).getServer().isPlusOneMaxPlayer())
{ {
builder.maximumPlayers(builder.getOnlinePlayers() + 1); builder.maximumPlayers(builder.getOnlinePlayers() + 1);

View File

@ -17,12 +17,12 @@ public class PlexLog
message = message.replace("{" + i + "}", strings[i].toString()); message = message.replace("{" + i + "}", strings[i].toString());
} }
} }
Plex.get().getServer().getConsoleCommandSource().sendMessage(MiniMessage.miniMessage().deserialize("<yellow>[Plex] <gray>" + message)); Plex.get().getServer().consoleCommandSource().sendMessage(MiniMessage.miniMessage().deserialize("<yellow>[Plex] <gray>" + message));
} }
public static void log(Component component) public static void log(Component component)
{ {
Plex.get().getServer().getConsoleCommandSource().sendMessage(Component.text("[Plex] ").color(NamedTextColor.YELLOW).append(component).colorIfAbsent(NamedTextColor.GRAY)); Plex.get().getServer().consoleCommandSource().sendMessage(Component.text("[Plex] ").color(NamedTextColor.YELLOW).append(component).colorIfAbsent(NamedTextColor.GRAY));
} }
public static void error(String message, Object... strings) public static void error(String message, Object... strings)
@ -34,7 +34,7 @@ public class PlexLog
message = message.replace("{" + i + "}", strings[i].toString()); message = message.replace("{" + i + "}", strings[i].toString());
} }
} }
Plex.get().getServer().getConsoleCommandSource().sendMessage(MiniMessage.miniMessage().deserialize("<red>[Plex Error] <gold>" + message)); Plex.get().getServer().consoleCommandSource().sendMessage(MiniMessage.miniMessage().deserialize("<red>[Plex Error] <gold>" + message));
} }
public static void warn(String message, Object... strings) public static void warn(String message, Object... strings)
@ -46,7 +46,7 @@ public class PlexLog
message = message.replace("{" + i + "}", strings[i].toString()); message = message.replace("{" + i + "}", strings[i].toString());
} }
} }
Plex.get().getServer().getConsoleCommandSource().sendMessage(MiniMessage.miniMessage().deserialize("<#eb7c0e>[Plex Warning] <gold>" + message)); Plex.get().getServer().consoleCommandSource().sendMessage(MiniMessage.miniMessage().deserialize("<#eb7c0e>[Plex Warning] <gold>" + message));
} }
public static void debug(String message, Object... strings) public static void debug(String message, Object... strings)
@ -60,7 +60,7 @@ public class PlexLog
} }
if (Plex.get().getConfig().as(ServerSettings.class).getServer().isDebug()) if (Plex.get().getConfig().as(ServerSettings.class).getServer().isDebug())
{ {
Plex.get().getServer().getConsoleCommandSource().sendMessage(MiniMessage.miniMessage().deserialize("<dark_purple>[Plex Debug] <gold>" + message)); Plex.get().getServer().consoleCommandSource().sendMessage(MiniMessage.miniMessage().deserialize("<dark_purple>[Plex Debug] <gold>" + message));
} }
} }
} }