forked from Upstream/Velocitab
Update about menu, minor code cleanup
This commit is contained in:
parent
02dca8ba3f
commit
c1682aeda9
@ -43,10 +43,11 @@ public final class VelocitabCommand {
|
|||||||
.credits("Author",
|
.credits("Author",
|
||||||
AboutMenu.Credit.of("William278").description("Click to visit website").url("https://william278.net"))
|
AboutMenu.Credit.of("William278").description("Click to visit website").url("https://william278.net"))
|
||||||
.credits("Contributors",
|
.credits("Contributors",
|
||||||
AboutMenu.Credit.of("Ironboundred").description("Coding"),
|
AboutMenu.Credit.of("AlexDev03").description("Code"),
|
||||||
AboutMenu.Credit.of("Emibergo02").description("Coding"),
|
AboutMenu.Credit.of("Ironboundred").description("Code"),
|
||||||
AboutMenu.Credit.of("FreeMonoid").description("Coding"),
|
AboutMenu.Credit.of("Emibergo02").description("Code"),
|
||||||
AboutMenu.Credit.of("4drian3d").description("Coding"))
|
AboutMenu.Credit.of("FreeMonoid").description("Code"),
|
||||||
|
AboutMenu.Credit.of("4drian3d").description("Code"))
|
||||||
.buttons(
|
.buttons(
|
||||||
AboutMenu.Link.of("https://william278.net/docs/velocitab").text("Docs").icon("⛏"),
|
AboutMenu.Link.of("https://william278.net/docs/velocitab").text("Docs").icon("⛏"),
|
||||||
AboutMenu.Link.of("https://discord.gg/tVYhJfyDWG").text("Discord").icon("⭐").color(TextColor.color(0x6773f5)),
|
AboutMenu.Link.of("https://discord.gg/tVYhJfyDWG").text("Discord").icon("⭐").color(TextColor.color(0x6773f5)),
|
||||||
|
@ -25,13 +25,11 @@ import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
|||||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||||
import io.netty.util.collection.IntObjectMap;
|
import io.netty.util.collection.IntObjectMap;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||||
import net.william278.velocitab.Velocitab;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.lang.invoke.MethodType;
|
import java.lang.invoke.MethodType;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -23,11 +23,15 @@ package net.william278.velocitab.packet;
|
|||||||
import com.velocitypowered.api.network.ProtocolVersion;
|
import com.velocitypowered.api.network.ProtocolVersion;
|
||||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adapter for handling the UpdateTeamsPacket for Minecraft 1.12.2
|
||||||
|
*/
|
||||||
@SuppressWarnings("DuplicatedCode")
|
@SuppressWarnings("DuplicatedCode")
|
||||||
public class Protocol340Adapter extends TeamsPacketAdapter {
|
public class Protocol340Adapter extends TeamsPacketAdapter {
|
||||||
|
|
||||||
@ -36,20 +40,20 @@ public class Protocol340Adapter extends TeamsPacketAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(ByteBuf byteBuf, UpdateTeamsPacket updateTeamsPacket) {
|
public void decode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet) {
|
||||||
updateTeamsPacket.teamName(ProtocolUtils.readString(byteBuf));
|
packet.teamName(ProtocolUtils.readString(byteBuf));
|
||||||
UpdateTeamsPacket.UpdateMode mode = UpdateTeamsPacket.UpdateMode.byId(byteBuf.readByte());
|
UpdateTeamsPacket.UpdateMode mode = UpdateTeamsPacket.UpdateMode.byId(byteBuf.readByte());
|
||||||
if (mode == UpdateTeamsPacket.UpdateMode.REMOVE_TEAM) {
|
if (mode == UpdateTeamsPacket.UpdateMode.REMOVE_TEAM) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) {
|
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) {
|
||||||
updateTeamsPacket.displayName(ProtocolUtils.readString(byteBuf));
|
packet.displayName(ProtocolUtils.readString(byteBuf));
|
||||||
updateTeamsPacket.prefix(ProtocolUtils.readString(byteBuf));
|
packet.prefix(ProtocolUtils.readString(byteBuf));
|
||||||
updateTeamsPacket.suffix(ProtocolUtils.readString(byteBuf));
|
packet.suffix(ProtocolUtils.readString(byteBuf));
|
||||||
updateTeamsPacket.friendlyFlags(UpdateTeamsPacket.FriendlyFlag.fromBitMask(byteBuf.readByte()));
|
packet.friendlyFlags(UpdateTeamsPacket.FriendlyFlag.fromBitMask(byteBuf.readByte()));
|
||||||
updateTeamsPacket.nameTagVisibility(UpdateTeamsPacket.NameTagVisibility.byId(ProtocolUtils.readString(byteBuf)));
|
packet.nameTagVisibility(UpdateTeamsPacket.NameTagVisibility.byId(ProtocolUtils.readString(byteBuf)));
|
||||||
updateTeamsPacket.collisionRule(UpdateTeamsPacket.CollisionRule.byId(ProtocolUtils.readString(byteBuf)));
|
packet.collisionRule(UpdateTeamsPacket.CollisionRule.byId(ProtocolUtils.readString(byteBuf)));
|
||||||
updateTeamsPacket.color(byteBuf.readByte());
|
packet.color(byteBuf.readByte());
|
||||||
}
|
}
|
||||||
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) {
|
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) {
|
||||||
int entityCount = ProtocolUtils.readVarInt(byteBuf);
|
int entityCount = ProtocolUtils.readVarInt(byteBuf);
|
||||||
@ -57,29 +61,29 @@ public class Protocol340Adapter extends TeamsPacketAdapter {
|
|||||||
for (int j = 0; j < entityCount; j++) {
|
for (int j = 0; j < entityCount; j++) {
|
||||||
entities.add(ProtocolUtils.readString(byteBuf));
|
entities.add(ProtocolUtils.readString(byteBuf));
|
||||||
}
|
}
|
||||||
updateTeamsPacket.entities(entities);
|
packet.entities(entities);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void encode(ByteBuf byteBuf, UpdateTeamsPacket updateTeamsPacket) {
|
public void encode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet) {
|
||||||
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.teamName().substring(0, Math.min(updateTeamsPacket.teamName().length(), 16)));
|
ProtocolUtils.writeString(byteBuf, packet.teamName().substring(0, Math.min(packet.teamName().length(), 16)));
|
||||||
UpdateTeamsPacket.UpdateMode mode = updateTeamsPacket.mode();
|
UpdateTeamsPacket.UpdateMode mode = packet.mode();
|
||||||
byteBuf.writeByte(mode.id());
|
byteBuf.writeByte(mode.id());
|
||||||
if (mode == UpdateTeamsPacket.UpdateMode.REMOVE_TEAM) {
|
if (mode == UpdateTeamsPacket.UpdateMode.REMOVE_TEAM) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) {
|
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) {
|
||||||
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.displayName());
|
ProtocolUtils.writeString(byteBuf, packet.displayName());
|
||||||
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.prefix());
|
ProtocolUtils.writeString(byteBuf, packet.prefix());
|
||||||
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.suffix());
|
ProtocolUtils.writeString(byteBuf, packet.suffix());
|
||||||
byteBuf.writeByte(UpdateTeamsPacket.FriendlyFlag.toBitMask(updateTeamsPacket.friendlyFlags()));
|
byteBuf.writeByte(UpdateTeamsPacket.FriendlyFlag.toBitMask(packet.friendlyFlags()));
|
||||||
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.nameTagVisibility().id());
|
ProtocolUtils.writeString(byteBuf, packet.nameTagVisibility().id());
|
||||||
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.collisionRule().id());
|
ProtocolUtils.writeString(byteBuf, packet.collisionRule().id());
|
||||||
byteBuf.writeByte(updateTeamsPacket.color());
|
byteBuf.writeByte(packet.color());
|
||||||
}
|
}
|
||||||
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) {
|
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) {
|
||||||
List<String> entities = updateTeamsPacket.entities();
|
List<String> entities = packet.entities();
|
||||||
ProtocolUtils.writeVarInt(byteBuf, entities != null ? entities.size() : 0);
|
ProtocolUtils.writeVarInt(byteBuf, entities != null ? entities.size() : 0);
|
||||||
for (String entity : entities != null ? entities : new ArrayList<String>()) {
|
for (String entity : entities != null ? entities : new ArrayList<String>()) {
|
||||||
ProtocolUtils.writeString(byteBuf, entity);
|
ProtocolUtils.writeString(byteBuf, entity);
|
||||||
|
@ -23,11 +23,15 @@ package net.william278.velocitab.packet;
|
|||||||
import com.velocitypowered.api.network.ProtocolVersion;
|
import com.velocitypowered.api.network.ProtocolVersion;
|
||||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adapter for handling the UpdateTeamsPacket for Minecraft 1.13+
|
||||||
|
*/
|
||||||
@SuppressWarnings("DuplicatedCode")
|
@SuppressWarnings("DuplicatedCode")
|
||||||
public class Protocol403Adapter extends TeamsPacketAdapter {
|
public class Protocol403Adapter extends TeamsPacketAdapter {
|
||||||
|
|
||||||
@ -44,20 +48,20 @@ public class Protocol403Adapter extends TeamsPacketAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(ByteBuf byteBuf, UpdateTeamsPacket updateTeamsPacket) {
|
public void decode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet) {
|
||||||
updateTeamsPacket.teamName(ProtocolUtils.readString(byteBuf));
|
packet.teamName(ProtocolUtils.readString(byteBuf));
|
||||||
UpdateTeamsPacket.UpdateMode mode = UpdateTeamsPacket.UpdateMode.byId(byteBuf.readByte());
|
UpdateTeamsPacket.UpdateMode mode = UpdateTeamsPacket.UpdateMode.byId(byteBuf.readByte());
|
||||||
if (mode == UpdateTeamsPacket.UpdateMode.REMOVE_TEAM) {
|
if (mode == UpdateTeamsPacket.UpdateMode.REMOVE_TEAM) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) {
|
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) {
|
||||||
updateTeamsPacket.displayName(ProtocolUtils.readString(byteBuf));
|
packet.displayName(ProtocolUtils.readString(byteBuf));
|
||||||
updateTeamsPacket.friendlyFlags(UpdateTeamsPacket.FriendlyFlag.fromBitMask(byteBuf.readByte()));
|
packet.friendlyFlags(UpdateTeamsPacket.FriendlyFlag.fromBitMask(byteBuf.readByte()));
|
||||||
updateTeamsPacket.nameTagVisibility(UpdateTeamsPacket.NameTagVisibility.byId(ProtocolUtils.readString(byteBuf)));
|
packet.nameTagVisibility(UpdateTeamsPacket.NameTagVisibility.byId(ProtocolUtils.readString(byteBuf)));
|
||||||
updateTeamsPacket.collisionRule(UpdateTeamsPacket.CollisionRule.byId(ProtocolUtils.readString(byteBuf)));
|
packet.collisionRule(UpdateTeamsPacket.CollisionRule.byId(ProtocolUtils.readString(byteBuf)));
|
||||||
updateTeamsPacket.color(byteBuf.readByte());
|
packet.color(byteBuf.readByte());
|
||||||
updateTeamsPacket.prefix(ProtocolUtils.readString(byteBuf));
|
packet.prefix(ProtocolUtils.readString(byteBuf));
|
||||||
updateTeamsPacket.suffix(ProtocolUtils.readString(byteBuf));
|
packet.suffix(ProtocolUtils.readString(byteBuf));
|
||||||
}
|
}
|
||||||
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) {
|
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) {
|
||||||
int entityCount = ProtocolUtils.readVarInt(byteBuf);
|
int entityCount = ProtocolUtils.readVarInt(byteBuf);
|
||||||
@ -65,29 +69,29 @@ public class Protocol403Adapter extends TeamsPacketAdapter {
|
|||||||
for (int j = 0; j < entityCount; j++) {
|
for (int j = 0; j < entityCount; j++) {
|
||||||
entities.add(ProtocolUtils.readString(byteBuf));
|
entities.add(ProtocolUtils.readString(byteBuf));
|
||||||
}
|
}
|
||||||
updateTeamsPacket.entities(entities);
|
packet.entities(entities);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void encode(ByteBuf byteBuf, UpdateTeamsPacket updateTeamsPacket) {
|
public void encode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet) {
|
||||||
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.teamName());
|
ProtocolUtils.writeString(byteBuf, packet.teamName());
|
||||||
UpdateTeamsPacket.UpdateMode mode = updateTeamsPacket.mode();
|
UpdateTeamsPacket.UpdateMode mode = packet.mode();
|
||||||
byteBuf.writeByte(mode.id());
|
byteBuf.writeByte(mode.id());
|
||||||
if (mode == UpdateTeamsPacket.UpdateMode.REMOVE_TEAM) {
|
if (mode == UpdateTeamsPacket.UpdateMode.REMOVE_TEAM) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) {
|
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) {
|
||||||
ProtocolUtils.writeString(byteBuf, getChatString(updateTeamsPacket.displayName()));
|
ProtocolUtils.writeString(byteBuf, getChatString(packet.displayName()));
|
||||||
byteBuf.writeByte(UpdateTeamsPacket.FriendlyFlag.toBitMask(updateTeamsPacket.friendlyFlags()));
|
byteBuf.writeByte(UpdateTeamsPacket.FriendlyFlag.toBitMask(packet.friendlyFlags()));
|
||||||
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.nameTagVisibility().id());
|
ProtocolUtils.writeString(byteBuf, packet.nameTagVisibility().id());
|
||||||
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.collisionRule().id());
|
ProtocolUtils.writeString(byteBuf, packet.collisionRule().id());
|
||||||
byteBuf.writeByte(updateTeamsPacket.color());
|
byteBuf.writeByte(packet.color());
|
||||||
ProtocolUtils.writeString(byteBuf, getChatString(updateTeamsPacket.prefix()));
|
ProtocolUtils.writeString(byteBuf, getChatString(packet.prefix()));
|
||||||
ProtocolUtils.writeString(byteBuf, getChatString(updateTeamsPacket.suffix()));
|
ProtocolUtils.writeString(byteBuf, getChatString(packet.suffix()));
|
||||||
}
|
}
|
||||||
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) {
|
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) {
|
||||||
List<String> entities = updateTeamsPacket.entities();
|
List<String> entities = packet.entities();
|
||||||
ProtocolUtils.writeVarInt(byteBuf, entities != null ? entities.size() : 0);
|
ProtocolUtils.writeVarInt(byteBuf, entities != null ? entities.size() : 0);
|
||||||
for (String entity : entities != null ? entities : new ArrayList<String>()) {
|
for (String entity : entities != null ? entities : new ArrayList<String>()) {
|
||||||
ProtocolUtils.writeString(byteBuf, entity);
|
ProtocolUtils.writeString(byteBuf, entity);
|
||||||
|
@ -23,11 +23,15 @@ package net.william278.velocitab.packet;
|
|||||||
import com.velocitypowered.api.network.ProtocolVersion;
|
import com.velocitypowered.api.network.ProtocolVersion;
|
||||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adapter for handling the UpdateTeamsPacket for Minecraft 1.8.x
|
||||||
|
*/
|
||||||
@SuppressWarnings("DuplicatedCode")
|
@SuppressWarnings("DuplicatedCode")
|
||||||
public class Protocol48Adapter extends TeamsPacketAdapter {
|
public class Protocol48Adapter extends TeamsPacketAdapter {
|
||||||
|
|
||||||
@ -36,19 +40,19 @@ public class Protocol48Adapter extends TeamsPacketAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(ByteBuf byteBuf, UpdateTeamsPacket updateTeamsPacket) {
|
public void decode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet) {
|
||||||
updateTeamsPacket.teamName(ProtocolUtils.readString(byteBuf));
|
packet.teamName(ProtocolUtils.readString(byteBuf));
|
||||||
UpdateTeamsPacket.UpdateMode mode = UpdateTeamsPacket.UpdateMode.byId(byteBuf.readByte());
|
UpdateTeamsPacket.UpdateMode mode = UpdateTeamsPacket.UpdateMode.byId(byteBuf.readByte());
|
||||||
if (mode == UpdateTeamsPacket.UpdateMode.REMOVE_TEAM) {
|
if (mode == UpdateTeamsPacket.UpdateMode.REMOVE_TEAM) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) {
|
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) {
|
||||||
updateTeamsPacket.displayName(ProtocolUtils.readString(byteBuf));
|
packet.displayName(ProtocolUtils.readString(byteBuf));
|
||||||
updateTeamsPacket.prefix(ProtocolUtils.readString(byteBuf));
|
packet.prefix(ProtocolUtils.readString(byteBuf));
|
||||||
updateTeamsPacket.suffix(ProtocolUtils.readString(byteBuf));
|
packet.suffix(ProtocolUtils.readString(byteBuf));
|
||||||
updateTeamsPacket.friendlyFlags(UpdateTeamsPacket.FriendlyFlag.fromBitMask(byteBuf.readByte()));
|
packet.friendlyFlags(UpdateTeamsPacket.FriendlyFlag.fromBitMask(byteBuf.readByte()));
|
||||||
updateTeamsPacket.nameTagVisibility(UpdateTeamsPacket.NameTagVisibility.byId(ProtocolUtils.readString(byteBuf)));
|
packet.nameTagVisibility(UpdateTeamsPacket.NameTagVisibility.byId(ProtocolUtils.readString(byteBuf)));
|
||||||
updateTeamsPacket.color(byteBuf.readByte());
|
packet.color(byteBuf.readByte());
|
||||||
}
|
}
|
||||||
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) {
|
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) {
|
||||||
int entityCount = ProtocolUtils.readVarInt(byteBuf);
|
int entityCount = ProtocolUtils.readVarInt(byteBuf);
|
||||||
@ -56,28 +60,28 @@ public class Protocol48Adapter extends TeamsPacketAdapter {
|
|||||||
for (int j = 0; j < entityCount; j++) {
|
for (int j = 0; j < entityCount; j++) {
|
||||||
entities.add(ProtocolUtils.readString(byteBuf));
|
entities.add(ProtocolUtils.readString(byteBuf));
|
||||||
}
|
}
|
||||||
updateTeamsPacket.entities(entities);
|
packet.entities(entities);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void encode(ByteBuf byteBuf, UpdateTeamsPacket updateTeamsPacket) {
|
public void encode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet) {
|
||||||
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.teamName().substring(0, Math.min(updateTeamsPacket.teamName().length(), 16)));
|
ProtocolUtils.writeString(byteBuf, packet.teamName().substring(0, Math.min(packet.teamName().length(), 16)));
|
||||||
UpdateTeamsPacket.UpdateMode mode = updateTeamsPacket.mode();
|
UpdateTeamsPacket.UpdateMode mode = packet.mode();
|
||||||
byteBuf.writeByte(mode.id());
|
byteBuf.writeByte(mode.id());
|
||||||
if (mode == UpdateTeamsPacket.UpdateMode.REMOVE_TEAM) {
|
if (mode == UpdateTeamsPacket.UpdateMode.REMOVE_TEAM) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) {
|
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) {
|
||||||
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.displayName());
|
ProtocolUtils.writeString(byteBuf, packet.displayName());
|
||||||
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.prefix());
|
ProtocolUtils.writeString(byteBuf, packet.prefix());
|
||||||
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.suffix());
|
ProtocolUtils.writeString(byteBuf, packet.suffix());
|
||||||
byteBuf.writeByte(UpdateTeamsPacket.FriendlyFlag.toBitMask(updateTeamsPacket.friendlyFlags()));
|
byteBuf.writeByte(UpdateTeamsPacket.FriendlyFlag.toBitMask(packet.friendlyFlags()));
|
||||||
ProtocolUtils.writeString(byteBuf, updateTeamsPacket.nameTagVisibility().id());
|
ProtocolUtils.writeString(byteBuf, packet.nameTagVisibility().id());
|
||||||
byteBuf.writeByte(updateTeamsPacket.color());
|
byteBuf.writeByte(packet.color());
|
||||||
}
|
}
|
||||||
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) {
|
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) {
|
||||||
List<String> entities = updateTeamsPacket.entities();
|
List<String> entities = packet.entities();
|
||||||
ProtocolUtils.writeVarInt(byteBuf, entities != null ? entities.size() : 0);
|
ProtocolUtils.writeVarInt(byteBuf, entities != null ? entities.size() : 0);
|
||||||
for (String entity : entities != null ? entities : new ArrayList<String>()) {
|
for (String entity : entities != null ? entities : new ArrayList<String>()) {
|
||||||
ProtocolUtils.writeString(byteBuf, entity);
|
ProtocolUtils.writeString(byteBuf, entity);
|
||||||
|
@ -55,15 +55,12 @@ public class ScoreboardManager {
|
|||||||
versions.add(new Protocol48Adapter());
|
versions.add(new Protocol48Adapter());
|
||||||
}
|
}
|
||||||
|
|
||||||
public TeamsPacketAdapter getPacketAdapter(ProtocolVersion protocolVersion) {
|
@NotNull
|
||||||
|
public TeamsPacketAdapter getPacketAdapter(@NotNull ProtocolVersion version) {
|
||||||
return versions.stream()
|
return versions.stream()
|
||||||
.filter(version -> version.getProtocolVersions().contains(protocolVersion))
|
.filter(adapter -> adapter.getProtocolVersions().contains(version))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElseThrow(() -> new IllegalArgumentException("No version found for protocol version " + protocolVersion));
|
.orElseThrow(() -> new IllegalArgumentException("No adapter found for protocol version " + version));
|
||||||
}
|
|
||||||
|
|
||||||
public void sendProtocolError(String message) {
|
|
||||||
plugin.log(Level.ERROR, message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetCache(@NotNull Player player) {
|
public void resetCache(@NotNull Player player) {
|
||||||
@ -98,7 +95,10 @@ public class ScoreboardManager {
|
|||||||
.entrySet().stream()
|
.entrySet().stream()
|
||||||
.filter((entry) -> List.of(playerNames).contains(entry.getKey()))
|
.filter((entry) -> List.of(playerNames).contains(entry.getKey()))
|
||||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
|
||||||
.forEach((playerName, oldRole) -> dispatchPacket(UpdateTeamsPacket.removeFromTeam(plugin, oldRole, playerName), player));
|
.forEach((playerName, oldRole) -> dispatchPacket(
|
||||||
|
UpdateTeamsPacket.removeFromTeam(plugin, oldRole, playerName),
|
||||||
|
player
|
||||||
|
));
|
||||||
dispatchPacket(UpdateTeamsPacket.addToTeam(plugin, role, playerNames), player);
|
dispatchPacket(UpdateTeamsPacket.addToTeam(plugin, role, playerNames), player);
|
||||||
roleMappings.computeIfAbsent(player.getUniqueId(), k -> new HashMap<>()).put(player.getUsername(), role);
|
roleMappings.computeIfAbsent(player.getUniqueId(), k -> new HashMap<>()).put(player.getUsername(), role);
|
||||||
}
|
}
|
||||||
|
@ -35,9 +35,9 @@ public abstract class TeamsPacketAdapter {
|
|||||||
|
|
||||||
private final Set<ProtocolVersion> protocolVersions;
|
private final Set<ProtocolVersion> protocolVersions;
|
||||||
|
|
||||||
public abstract void decode(ByteBuf byteBuf, UpdateTeamsPacket updateTeamsPacket);
|
public abstract void decode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet);
|
||||||
|
|
||||||
public abstract void encode(ByteBuf byteBuf, UpdateTeamsPacket updateTeamsPacket);
|
public abstract void encode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected String getChatString(@NotNull String string) {
|
protected String getChatString(@NotNull String string) {
|
||||||
|
@ -29,6 +29,7 @@ import lombok.experimental.Accessors;
|
|||||||
import net.william278.velocitab.Velocitab;
|
import net.william278.velocitab.Velocitab;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.slf4j.event.Level;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -43,6 +44,8 @@ import java.util.stream.Collectors;
|
|||||||
@Accessors(fluent = true)
|
@Accessors(fluent = true)
|
||||||
public class UpdateTeamsPacket implements MinecraftPacket {
|
public class UpdateTeamsPacket implements MinecraftPacket {
|
||||||
|
|
||||||
|
private static final String PACKET_ADAPTION_ERROR = "Something went wrong while %s a UpdateTeamsPacket, if your " +
|
||||||
|
"server is on 1.8.x and you are using ViaVersion, please disable 'auto-team' in the config.yml and reload.";
|
||||||
private final Velocitab plugin;
|
private final Velocitab plugin;
|
||||||
|
|
||||||
private String teamName;
|
private String teamName;
|
||||||
@ -56,7 +59,7 @@ public class UpdateTeamsPacket implements MinecraftPacket {
|
|||||||
private String suffix;
|
private String suffix;
|
||||||
private List<String> entities;
|
private List<String> entities;
|
||||||
|
|
||||||
public UpdateTeamsPacket(Velocitab plugin) {
|
public UpdateTeamsPacket(@NotNull Velocitab plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,40 +96,28 @@ public class UpdateTeamsPacket implements MinecraftPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(ByteBuf byteBuf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
public void decode(ByteBuf byteBuf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||||
Optional<ScoreboardManager> scoreboardManagerOptional = plugin.getScoreboardManager();
|
final Optional<ScoreboardManager> optionalManager = plugin.getScoreboardManager();
|
||||||
|
if (optionalManager.isEmpty()) {
|
||||||
if (scoreboardManagerOptional.isEmpty()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScoreboardManager scoreboardManager = scoreboardManagerOptional.get();
|
|
||||||
|
|
||||||
if (mode == null) {
|
if (mode == null) {
|
||||||
scoreboardManager.sendProtocolError("Something went wrong while decoding a UpdateTeamsPacket" +
|
plugin.log(Level.ERROR, String.format(PACKET_ADAPTION_ERROR, "decoding"));
|
||||||
", if your server is on 1.8.x and you are using ViaVersion," +
|
|
||||||
", please disable 'auto-team' in the config.yml and reload it.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scoreboardManager.getPacketAdapter(protocolVersion).decode(byteBuf, this);
|
optionalManager.get().getPacketAdapter(protocolVersion).decode(byteBuf, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void encode(ByteBuf byteBuf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
public void encode(ByteBuf byteBuf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
|
||||||
Optional<ScoreboardManager> scoreboardManagerOptional = plugin.getScoreboardManager();
|
final Optional<ScoreboardManager> optionalManager = plugin.getScoreboardManager();
|
||||||
|
if (optionalManager.isEmpty()) {
|
||||||
if (scoreboardManagerOptional.isEmpty()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScoreboardManager scoreboardManager = scoreboardManagerOptional.get();
|
|
||||||
|
|
||||||
if (mode == null) {
|
if (mode == null) {
|
||||||
scoreboardManager.sendProtocolError("Something went wrong while encoding a UpdateTeamsPacket" +
|
plugin.log(Level.ERROR, String.format(PACKET_ADAPTION_ERROR, "encoding"));
|
||||||
", if your server is on 1.8.x and you are using ViaVersion," +
|
|
||||||
", please disable 'auto-team' in the config.yml and reload it.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scoreboardManager.getPacketAdapter(protocolVersion).encode(byteBuf, this);
|
optionalManager.get().getPacketAdapter(protocolVersion).encode(byteBuf, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user