Skip to content

Commit

Permalink
Add custom brand
Browse files Browse the repository at this point in the history
  • Loading branch information
Laica-Lunasys committed Jun 16, 2024
1 parent 5db26b7 commit 7698db5
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
Expand All @@ -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
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/net/synchthia/nebula/velocity/CustomBrand.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 7698db5

Please sign in to comment.