diff --git a/build.gradle.kts b/build.gradle.kts index 9d8f20a..701a800 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -33,6 +33,11 @@ repositories { url = uri("https://repo.papermc.io/repository/maven-public/") } + maven { + name = "velocity-external" + url = uri("https://repo.william278.net/velocity/") + } + maven { name = "codemc" url = uri("https://repo.codemc.org/repository/maven-public/") @@ -59,6 +64,8 @@ dependencies { // Velocity compileOnly("com.velocitypowered:velocity-api:3.3.0-SNAPSHOT") + compileOnly("com.velocitypowered:velocity-proxy:3.3.0-SNAPSHOT") + annotationProcessor("com.velocitypowered:velocity-api:3.3.0-SNAPSHOT") // Adventure diff --git a/src/main/java/net/synchthia/nebula/velocity/CustomBrand.java b/src/main/java/net/synchthia/nebula/velocity/CustomBrand.java new file mode 100644 index 0000000..08aca21 --- /dev/null +++ b/src/main/java/net/synchthia/nebula/velocity/CustomBrand.java @@ -0,0 +1,53 @@ +package net.synchthia.nebula.velocity; + +import com.velocitypowered.api.network.ProtocolState; +import com.velocitypowered.api.network.ProtocolVersion; +import com.velocitypowered.api.proxy.messages.ChannelIdentifier; +import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; +import com.velocitypowered.proxy.connection.MinecraftConnection; +import com.velocitypowered.proxy.connection.client.ConnectedPlayer; +import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.protocol.StateRegistry; +import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; + +import java.util.concurrent.TimeUnit; + +public class CustomBrand { + public static final ChannelIdentifier MODERN_CHANNEL = MinecraftChannelIdentifier.forDefaultNamespace("brand"); + private final NebulaVelocityPlugin plugin; + private final boolean protocolError = false; + + public CustomBrand(NebulaVelocityPlugin plugin) { + this.plugin = plugin; + } + + public void run() { + plugin.getServer().getScheduler().buildTask(plugin, () -> plugin.getServer().getAllPlayers().forEach((player) -> { + try { + if (player.getProtocolState() != ProtocolState.PLAY) { + return; + } + final String brand = "Minecraft"; + MinecraftConnection connection = ((ConnectedPlayer) player).getConnection(); + if (connection.getState() != StateRegistry.PLAY) return; + + ProtocolVersion protocol = player.getProtocolVersion(); + if (protocol.compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) { + if (!protocolError) { + plugin.getLogger().warn("Protocol version {} is not supported", protocol); + } + return; + } + + ByteBuf buf = Unpooled.buffer(); + ProtocolUtils.writeString(buf, "Minecraft" + "§r"); + connection.write(new PluginMessagePacket(MODERN_CHANNEL.getId(), buf)); + connection.flush(); + } catch (Throwable t) { + t.printStackTrace(); + } + })).repeat(100L, TimeUnit.MILLISECONDS).schedule(); + } +} diff --git a/src/main/java/net/synchthia/nebula/velocity/NebulaVelocityPlugin.java b/src/main/java/net/synchthia/nebula/velocity/NebulaVelocityPlugin.java index 5e2056c..a4f6cb2 100755 --- a/src/main/java/net/synchthia/nebula/velocity/NebulaVelocityPlugin.java +++ b/src/main/java/net/synchthia/nebula/velocity/NebulaVelocityPlugin.java @@ -78,6 +78,10 @@ public void onProxyInitialization(ProxyInitializeEvent event) { this.server.getEventManager().register(this, new PingListener(this)); this.server.getEventManager().register(this, new PlayerListener(this)); + // Brand Sync + CustomBrand customBrand = new CustomBrand(this); + customBrand.run(); + // Disable built-in commands this.server.getCommandManager().unregister("server"); // this.server.getCommandManager().unregister("glist");