-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5db26b7
commit 7698db5
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/net/synchthia/nebula/velocity/CustomBrand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters