diff --git a/.versionrc.js b/.versionrc.js index ad5cf20..fd45455 100644 --- a/.versionrc.js +++ b/.versionrc.js @@ -1,5 +1,5 @@ let versionRegex = /(\nversion:\s)([0-9.-]+)/; -let velocityVersionRegex = /(\sversion\s=\s")([0-9.-]+)("\))/; +let velocityVersionRegex = /(\sversion\s=\s")([0-9.-]+)(",)/; const ymlUpdater = { diff --git a/build.gradle b/build.gradle index 291363a..ec63797 100644 --- a/build.gradle +++ b/build.gradle @@ -82,8 +82,8 @@ dependencies { implementation "org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT" implementation "net.md-5:bungeecord-api:1.15-SNAPSHOT" - implementation "com.velocitypowered:velocity-api:1.1.0-SNAPSHOT" - annotationProcessor "com.velocitypowered:velocity-api:1.1.0-SNAPSHOT" + implementation "com.velocitypowered:velocity-api:2.0.0-SNAPSHOT" + annotationProcessor "com.velocitypowered:velocity-annotation-processor:2.0.0-SNAPSHOT" implementation "io.netty:netty-all:4.0.4.Final" compileOnly 'com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT' diff --git a/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsPlugin.java b/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsPlugin.java index 0a0a415..4b52e13 100644 --- a/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsPlugin.java +++ b/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsPlugin.java @@ -7,13 +7,16 @@ import com.google.inject.Inject; import com.sekwah.advancedportals.bungee.BungeeMessages; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.connection.PluginMessageEvent; +import com.velocitypowered.api.event.lifecycle.ProxyInitializeEvent; import com.velocitypowered.api.event.player.ServerPostConnectEvent; -import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; +import com.velocitypowered.api.plugin.Dependency; import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.proxy.ProxyServer; -import com.velocitypowered.api.proxy.ServerConnection; -import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; +import com.velocitypowered.api.proxy.connection.ServerConnection; +import com.velocitypowered.api.proxy.messages.PluginChannelId; +import org.checkerframework.checker.nullness.qual.Nullable; import org.slf4j.Logger; +import net.kyori.adventure.key.Key; import java.util.HashMap; import java.util.concurrent.TimeUnit; @@ -23,14 +26,20 @@ import java.util.concurrent.TimeUnit; */ @Plugin(id = "advancedportals", name = "Advanced Portals", url = "https://www.spigotmc.org/resources/advanced-portals.14356/", - version = "0.6.0") + version = "0.6.0", + description = "Customisable portal plugin", + dependencies = { + @Dependency(id = "velocity", version = "2.x.x") +}) public class AdvancedPortalsPlugin { public HashMap PlayerDestiMap = new HashMap<>(); + private static final Key ADVANCED_PORTALS = Key.key("advancedportals", "events"); + private final Logger logger; private final ProxyServer proxy; - private LegacyChannelIdentifier AP_CHANNEL; + private PluginChannelId advancedPortalsChannelId; @Inject public AdvancedPortalsPlugin(ProxyServer proxy, Logger logger) { @@ -46,17 +55,17 @@ public class AdvancedPortalsPlugin { public void onProxyInitialize(ProxyInitializeEvent event) { String[] splitChannel = BungeeMessages.CHANNEL_NAME.split(":"); - AP_CHANNEL = new LegacyChannelIdentifier(BungeeMessages.CHANNEL_NAME); + advancedPortalsChannelId = PluginChannelId.withLegacy(BungeeMessages.CHANNEL_NAME, ADVANCED_PORTALS); - proxy.getChannelRegistrar().register(AP_CHANNEL); + proxy.channelRegistrar().register(advancedPortalsChannelId); } @Subscribe public void onPluginMessage(PluginMessageEvent event) { - if(event.getIdentifier().equals(AP_CHANNEL)) { - if(event.getSource() instanceof ServerConnection) { + if(event.channel().equals(advancedPortalsChannelId)) { + if(event.source() instanceof ServerConnection) { - ByteArrayDataInput in = ByteStreams.newDataInput(event.getData()); + ByteArrayDataInput in = ByteStreams.newDataInput(event.rawMessage()); String subChannel = in.readUTF(); @@ -67,26 +76,26 @@ public class AdvancedPortalsPlugin { PlayerDestiMap.put(targetUUID, new String[]{targetServer, targetDestination, targetUUID}); - proxy.getScheduler().buildTask(this, () -> PlayerDestiMap.remove(targetUUID)) + proxy.scheduler().buildTask(this, () -> PlayerDestiMap.remove(targetUUID)) .delay(10, TimeUnit.SECONDS).schedule(); } else if (subChannel.equalsIgnoreCase(BungeeMessages.BUNGEE_COMMAND)) { String command = in.readUTF(); - ServerConnection connection = (ServerConnection) event.getSource(); - if(connection.getPlayer() != null) { - proxy.getCommandManager().executeAsync(connection.getPlayer(), command); + ServerConnection connection = (ServerConnection) event.source(); + if(connection.player() != null) { + proxy.commandManager().execute(connection.player(), command); } } } // So that client packets don't make it through to the servers, always trigger on this channel. - event.setResult(PluginMessageEvent.ForwardResult.handled()); + event.setHandled(true); } } @Subscribe public void postJoinEvent(ServerPostConnectEvent event) { - String uuid = event.getPlayer().getUniqueId().toString(); + String uuid = event.player().id().toString(); String[] val = PlayerDestiMap.get(uuid); @@ -94,9 +103,9 @@ public class AdvancedPortalsPlugin { // key: UUID (string) // value: [0] targetServer, [1] targetDestination, [2] onlineUUID - event.getPlayer().getCurrentServer().ifPresent(serverConnection -> { - - if (serverConnection.getServerInfo().getName().equalsIgnoreCase(val[0])) { + @Nullable ServerConnection serverConnection = event.player().connectedServer(); + if(serverConnection == null) { + if (serverConnection.serverInfo().name().equalsIgnoreCase(val[0])) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); @@ -104,10 +113,10 @@ public class AdvancedPortalsPlugin { out.writeUTF(val[1]); out.writeUTF(val[2]); - serverConnection.sendPluginMessage(AP_CHANNEL, out.toByteArray()); + serverConnection.sendPluginMessage(advancedPortalsChannelId, out.toByteArray()); } - }); + } } }