forked from Upstream/Velocitab
Add support for Minecraft 1.20.2 (#99)
* Add protocol mappings for 1.20.2 * Cleanup some exception handling * ci: Mark 1.20.2 as supported * Minor code formatting tweaks
This commit is contained in:
parent
fd17560f2e
commit
1f1e69ebca
2
.github/workflows/java_ci.yml
vendored
2
.github/workflows/java_ci.yml
vendored
@ -60,7 +60,7 @@ jobs:
|
|||||||
1.17.1
|
1.17.1
|
||||||
1.18.2
|
1.18.2
|
||||||
1.19.4
|
1.19.4
|
||||||
1.20.1
|
1.20.2
|
||||||
java: 16
|
java: 16
|
||||||
- name: Upload GitHub Artifact
|
- name: Upload GitHub Artifact
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v2
|
||||||
|
@ -31,7 +31,6 @@ import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
|||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
import com.velocitypowered.api.scheduler.ScheduledTask;
|
import com.velocitypowered.api.scheduler.ScheduledTask;
|
||||||
import lombok.Getter;
|
|
||||||
import net.william278.annotaml.Annotaml;
|
import net.william278.annotaml.Annotaml;
|
||||||
import net.william278.desertwell.util.UpdateChecker;
|
import net.william278.desertwell.util.UpdateChecker;
|
||||||
import net.william278.desertwell.util.Version;
|
import net.william278.desertwell.util.Version;
|
||||||
@ -207,6 +206,7 @@ public class Velocitab {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public Optional<TabPlayer> getTabPlayer(String name) {
|
public Optional<TabPlayer> getTabPlayer(String name) {
|
||||||
return server.getPlayer(name).map(this::getTabPlayer);
|
return server.getPlayer(name).map(this::getTabPlayer);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ public abstract class Hook {
|
|||||||
try {
|
try {
|
||||||
plugin.log("Successfully hooked into LuckPerms");
|
plugin.log("Successfully hooked into LuckPerms");
|
||||||
return Optional.of(new LuckPermsHook(plugin));
|
return Optional.of(new LuckPermsHook(plugin));
|
||||||
} catch (Exception e) {
|
} catch (Throwable e) {
|
||||||
plugin.log(Level.WARN, "LuckPerms hook was not loaded: " + e.getMessage(), e);
|
plugin.log(Level.WARN, "LuckPerms hook was not loaded: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ public abstract class Hook {
|
|||||||
try {
|
try {
|
||||||
plugin.log("Successfully hooked into PAPIProxyBridge");
|
plugin.log("Successfully hooked into PAPIProxyBridge");
|
||||||
return Optional.of(new PAPIProxyBridgeHook(plugin));
|
return Optional.of(new PAPIProxyBridgeHook(plugin));
|
||||||
} catch (Exception e) {
|
} catch (Throwable e) {
|
||||||
plugin.log(Level.WARN, "PAPIProxyBridge hook was not loaded: " + e.getMessage(), e);
|
plugin.log(Level.WARN, "PAPIProxyBridge hook was not loaded: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ public abstract class Hook {
|
|||||||
try {
|
try {
|
||||||
plugin.log("Successfully hooked into MiniPlaceholders");
|
plugin.log("Successfully hooked into MiniPlaceholders");
|
||||||
return Optional.of(new MiniPlaceholdersHook(plugin));
|
return Optional.of(new MiniPlaceholdersHook(plugin));
|
||||||
} catch (Exception e) {
|
} catch (Throwable e) {
|
||||||
plugin.log(Level.WARN, "MiniPlaceholders hook was not loaded: " + e.getMessage(), e);
|
plugin.log(Level.WARN, "MiniPlaceholders hook was not loaded: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,9 +137,6 @@ public final class PacketRegistration<P extends MinecraftPacket> {
|
|||||||
private static final MethodHandle PACKET_REGISTRY$versions;
|
private static final MethodHandle PACKET_REGISTRY$versions;
|
||||||
private static final MethodHandle PACKET_MAPPING$map;
|
private static final MethodHandle PACKET_MAPPING$map;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
final MethodHandles.Lookup lookup = MethodHandles.lookup();
|
final MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||||
try {
|
try {
|
||||||
@ -164,4 +161,5 @@ public final class PacketRegistration<P extends MinecraftPacket> {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,8 @@ public class Protocol403Adapter extends TeamsPacketAdapter {
|
|||||||
ProtocolVersion.MINECRAFT_1_17_1,
|
ProtocolVersion.MINECRAFT_1_17_1,
|
||||||
ProtocolVersion.MINECRAFT_1_18_2,
|
ProtocolVersion.MINECRAFT_1_18_2,
|
||||||
ProtocolVersion.MINECRAFT_1_19_4,
|
ProtocolVersion.MINECRAFT_1_19_4,
|
||||||
ProtocolVersion.MINECRAFT_1_20
|
ProtocolVersion.MINECRAFT_1_20,
|
||||||
|
ProtocolVersion.MINECRAFT_1_20_2
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,32 +155,27 @@ public class ScoreboardManager {
|
|||||||
try {
|
try {
|
||||||
final ConnectedPlayer connectedPlayer = (ConnectedPlayer) player;
|
final ConnectedPlayer connectedPlayer = (ConnectedPlayer) player;
|
||||||
connectedPlayer.getConnection().write(packet);
|
connectedPlayer.getConnection().write(packet);
|
||||||
} catch (Exception e) {
|
} catch (Throwable e) {
|
||||||
plugin.log(Level.ERROR, "Failed to dispatch packet (is the client or server modded or using an illegal version?)", e);
|
plugin.log(Level.ERROR, "Failed to dispatch packet (is the client or server modded or using an illegal version?)", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dispatchGroupPacket(@NotNull UpdateTeamsPacket packet, @NotNull Player player) {
|
private void dispatchGroupPacket(@NotNull UpdateTeamsPacket packet, @NotNull Player player) {
|
||||||
Optional<ServerConnection> optionalServerConnection = player.getCurrentServer();
|
final Optional<ServerConnection> optionalServerConnection = player.getCurrentServer();
|
||||||
|
|
||||||
if (optionalServerConnection.isEmpty()) {
|
if (optionalServerConnection.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegisteredServer serverInfo = optionalServerConnection.get().getServer();
|
final RegisteredServer serverInfo = optionalServerConnection.get().getServer();
|
||||||
|
final List<RegisteredServer> siblings = plugin.getTabList().getGroupServers(serverInfo.getServerInfo().getName());
|
||||||
List<RegisteredServer> siblings = plugin.getTabList().getGroupServers(serverInfo.getServerInfo().getName());
|
siblings.forEach(server -> server.getPlayersConnected().forEach(connected -> {
|
||||||
|
|
||||||
siblings.forEach(s -> {
|
|
||||||
s.getPlayersConnected().forEach(p -> {
|
|
||||||
try {
|
try {
|
||||||
final ConnectedPlayer connectedPlayer = (ConnectedPlayer) p;
|
final ConnectedPlayer connectedPlayer = (ConnectedPlayer) connected;
|
||||||
connectedPlayer.getConnection().write(packet);
|
connectedPlayer.getConnection().write(packet);
|
||||||
} catch (Exception e) {
|
} catch (Throwable e) {
|
||||||
plugin.log(Level.ERROR, "Failed to dispatch packet (is the client or server modded or using an illegal version?)", e);
|
plugin.log(Level.ERROR, "Failed to dispatch packet (unsupported client or server version)", e);
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerPacket() {
|
public void registerPacket() {
|
||||||
@ -197,7 +192,8 @@ public class ScoreboardManager {
|
|||||||
.mapping(0x55, MINECRAFT_1_17, true)
|
.mapping(0x55, MINECRAFT_1_17, true)
|
||||||
.mapping(0x58, MINECRAFT_1_19_1, true)
|
.mapping(0x58, MINECRAFT_1_19_1, true)
|
||||||
.mapping(0x56, MINECRAFT_1_19_3, true)
|
.mapping(0x56, MINECRAFT_1_19_3, true)
|
||||||
.mapping(0x5A, MINECRAFT_1_19_4, true);
|
.mapping(0x5A, MINECRAFT_1_19_4, true)
|
||||||
|
.mapping(0x5C, MINECRAFT_1_20_2, true);
|
||||||
packetRegistration.register();
|
packetRegistration.register();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
plugin.log(Level.ERROR, "Failed to register UpdateTeamsPacket", e);
|
plugin.log(Level.ERROR, "Failed to register UpdateTeamsPacket", e);
|
||||||
|
@ -30,7 +30,6 @@ 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 java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -62,7 +61,9 @@ public class UpdateTeamsPacket implements MinecraftPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected static UpdateTeamsPacket create(@NotNull Velocitab plugin, @NotNull String teamName, @NotNull String displayName, @Nullable String prefix, @Nullable String suffix, @NotNull String... teamMembers) {
|
protected static UpdateTeamsPacket create(@NotNull Velocitab plugin, @NotNull String teamName,
|
||||||
|
@NotNull String displayName, @Nullable String prefix,
|
||||||
|
@Nullable String suffix, @NotNull String... teamMembers) {
|
||||||
return new UpdateTeamsPacket(plugin)
|
return new UpdateTeamsPacket(plugin)
|
||||||
.teamName(teamName.length() > 16 ? teamName.substring(0, 16) : teamName)
|
.teamName(teamName.length() > 16 ? teamName.substring(0, 16) : teamName)
|
||||||
.mode(UpdateMode.CREATE_TEAM)
|
.mode(UpdateMode.CREATE_TEAM)
|
||||||
@ -77,7 +78,8 @@ public class UpdateTeamsPacket implements MinecraftPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected static UpdateTeamsPacket changeNameTag(@NotNull Velocitab plugin, @NotNull String teamName, @Nullable String prefix, @Nullable String suffix) {
|
protected static UpdateTeamsPacket changeNameTag(@NotNull Velocitab plugin, @NotNull String teamName,
|
||||||
|
@Nullable String prefix, @Nullable String suffix) {
|
||||||
return new UpdateTeamsPacket(plugin)
|
return new UpdateTeamsPacket(plugin)
|
||||||
.teamName(teamName.length() > 16 ? teamName.substring(0, 16) : teamName)
|
.teamName(teamName.length() > 16 ? teamName.substring(0, 16) : teamName)
|
||||||
.mode(UpdateMode.UPDATE_INFO)
|
.mode(UpdateMode.UPDATE_INFO)
|
||||||
@ -91,7 +93,8 @@ public class UpdateTeamsPacket implements MinecraftPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected static UpdateTeamsPacket addToTeam(@NotNull Velocitab plugin, @NotNull String teamName, @NotNull String... teamMembers) {
|
protected static UpdateTeamsPacket addToTeam(@NotNull Velocitab plugin, @NotNull String teamName,
|
||||||
|
@NotNull String... teamMembers) {
|
||||||
return new UpdateTeamsPacket(plugin)
|
return new UpdateTeamsPacket(plugin)
|
||||||
.teamName(teamName.length() > 16 ? teamName.substring(0, 16) : teamName)
|
.teamName(teamName.length() > 16 ? teamName.substring(0, 16) : teamName)
|
||||||
.mode(UpdateMode.ADD_PLAYERS)
|
.mode(UpdateMode.ADD_PLAYERS)
|
||||||
@ -99,7 +102,8 @@ public class UpdateTeamsPacket implements MinecraftPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected static UpdateTeamsPacket removeFromTeam(@NotNull Velocitab plugin, @NotNull String teamName, @NotNull String... teamMembers) {
|
protected static UpdateTeamsPacket removeFromTeam(@NotNull Velocitab plugin, @NotNull String teamName,
|
||||||
|
@NotNull String... teamMembers) {
|
||||||
return new UpdateTeamsPacket(plugin)
|
return new UpdateTeamsPacket(plugin)
|
||||||
.teamName(teamName.length() > 16 ? teamName.substring(0, 16) : teamName)
|
.teamName(teamName.length() > 16 ? teamName.substring(0, 16) : teamName)
|
||||||
.mode(UpdateMode.REMOVE_PLAYERS)
|
.mode(UpdateMode.REMOVE_PLAYERS)
|
||||||
@ -160,7 +164,10 @@ public class UpdateTeamsPacket implements MinecraftPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int getColorId(char var) {
|
public static int getColorId(char var) {
|
||||||
return Arrays.stream(values()).filter(color -> color.colorChar == var).map(c -> c.id).findFirst().orElse(15);
|
return Arrays.stream(values())
|
||||||
|
.filter(color -> color.colorChar == var)
|
||||||
|
.map(c -> c.id).findFirst()
|
||||||
|
.orElse(15);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,6 +209,7 @@ public class UpdateTeamsPacket implements MinecraftPacket {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static UpdateMode byId(byte id) {
|
public static UpdateMode byId(byte id) {
|
||||||
return Arrays.stream(values())
|
return Arrays.stream(values())
|
||||||
.filter(mode -> mode.id == id)
|
.filter(mode -> mode.id == id)
|
||||||
|
Loading…
Reference in New Issue
Block a user