Skip to content

Commit dd7c252

Browse files
committed
chore: cleanup for now-public repo
chore: remove unnecessary mapping entries chore: update player loaded world api -> see PaperMC/Velocity#1541
1 parent 3dd5e96 commit dd7c252

File tree

13 files changed

+28
-86
lines changed

13 files changed

+28
-86
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>de.timongcraft</groupId>
88
<artifactId>VeloProtocol</artifactId>
9-
<version>1.3.2</version>
9+
<version>1.3.3</version>
1010
<packaging>jar</packaging>
1111

1212
<properties>

src/generated/java/de/timongcraft/veloprotocol/network/protocol/blockentities/VeloBlockEntityTypes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ private static int[] getProtocolIds(String name) {
151151
int[] protocolIds = new int[ProtocolMappingsCache.RESOURCE_PROTOCOL_MAPPINGS.size()];
152152

153153
for (int i = 0; i < ProtocolMappingsCache.RESOURCE_PROTOCOL_MAPPINGS.size(); i++) {
154-
Integer nameProtocolId = ProtocolMappingsCache.RESOURCE_PROTOCOL_MAPPINGS.get(i).mappings().get("minecraft:block_entity_type").getOrDefault(name, null);
155-
protocolIds[i] = nameProtocolId != null ? nameProtocolId : -1;
154+
int nameProtocolId = ProtocolMappingsCache.RESOURCE_PROTOCOL_MAPPINGS.get(i).mappings().get("minecraft:block_entity_type").getOrDefault(name, -1);
155+
protocolIds[i] = nameProtocolId;
156156
}
157157

158158
return protocolIds;

src/generated/java/de/timongcraft/veloprotocol/network/protocol/datacomponents/VeloDataComponentTypes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ private static int[] getProtocolIds(String name) {
253253
int[] protocolIds = new int[ProtocolMappingsCache.RESOURCE_PROTOCOL_MAPPINGS.size()];
254254

255255
for (int i = 0; i < ProtocolMappingsCache.RESOURCE_PROTOCOL_MAPPINGS.size(); i++) {
256-
Integer nameProtocolId = ProtocolMappingsCache.RESOURCE_PROTOCOL_MAPPINGS.get(i).mappings().get("minecraft:data_component_type").getOrDefault(name, null);
257-
protocolIds[i] = nameProtocolId != null ? nameProtocolId : -1;
256+
int nameProtocolId = ProtocolMappingsCache.RESOURCE_PROTOCOL_MAPPINGS.get(i).mappings().get("minecraft:data_component_type").getOrDefault(name, -1);
257+
protocolIds[i] = nameProtocolId;
258258
}
259259

260260
return protocolIds;

src/generated/java/de/timongcraft/veloprotocol/network/protocol/effects/VeloEntityEffects.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ private static int[] getProtocolIds(String name) {
132132
int[] protocolIds = new int[ProtocolMappingsCache.RESOURCE_PROTOCOL_MAPPINGS.size()];
133133

134134
for (int i = 0; i < ProtocolMappingsCache.RESOURCE_PROTOCOL_MAPPINGS.size(); i++) {
135-
Integer nameProtocolId = ProtocolMappingsCache.RESOURCE_PROTOCOL_MAPPINGS.get(i).mappings().get("minecraft:mob_effect").getOrDefault(name, null);
136-
protocolIds[i] = nameProtocolId != null ? nameProtocolId : -1;
135+
int nameProtocolId = ProtocolMappingsCache.RESOURCE_PROTOCOL_MAPPINGS.get(i).mappings().get("minecraft:mob_effect").getOrDefault(name, -1);
136+
protocolIds[i] = nameProtocolId;
137137
}
138138

139139
return protocolIds;

src/main/java/de/timongcraft/veloprotocol/apis/PlayerLoadedWorldApi.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
import org.jetbrains.annotations.Nullable;
1313

1414
import java.time.Duration;
15-
import java.util.Map;
15+
import java.util.Set;
1616
import java.util.UUID;
1717
import java.util.concurrent.ConcurrentHashMap;
1818

19+
@SuppressWarnings("removal")
20+
@Deprecated(since = "1.3.3", forRemoval = true) // will be removed when the pull request is merged - https://github.com/PaperMC/Velocity/pull/1541
1921
@Beta
2022
public class PlayerLoadedWorldApi {
2123

@@ -33,36 +35,32 @@ public static void register(Object pluginMainClass, ProxyServer proxyServer, @Nu
3335
private final ProxyServer proxyServer;
3436
private final Object pluginMainClass;
3537
private final Duration timeout;
36-
private final Map<UUID, PlayerClientLoadedWorldEvent.Cause> loadingPlayers;
38+
private final Set<UUID> loadingPlayers;
3739

3840
private PlayerLoadedWorldApi(Object pluginMainClass, ProxyServer proxyServer, @Nullable Duration timeout) {
3941
this.proxyServer = proxyServer;
4042
this.pluginMainClass = pluginMainClass;
4143
this.timeout = timeout != null ? timeout : NOTCHIAN_TIMEOUT;
42-
loadingPlayers = new ConcurrentHashMap<>();
44+
loadingPlayers = ConcurrentHashMap.newKeySet();
4345
}
4446

4547
@Subscribe
4648
public void onPostConnect(ServerPostConnectEvent event) {
4749
if (event.getPlayer().getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_21_4)) return;
48-
loadingPlayers.put(event.getPlayer().getUniqueId(), PlayerClientLoadedWorldEvent.Cause.SERVER_JOIN);
50+
loadingPlayers.add(event.getPlayer().getUniqueId());
4951

5052
proxyServer.getScheduler().buildTask(pluginMainClass, () -> {
51-
PlayerClientLoadedWorldEvent.Cause cause = loadingPlayers.remove(event.getPlayer().getUniqueId());
52-
if (cause == null) return;
53+
loadingPlayers.remove(event.getPlayer().getUniqueId());
5354
if (!event.getPlayer().isActive()) return;
54-
55-
proxyServer.getEventManager().fireAndForget(new PlayerClientLoadedWorldEvent(event.getPlayer(), cause, true));
55+
proxyServer.getEventManager().fireAndForget(new PlayerClientLoadedWorldEvent(event.getPlayer(), true));
5656
}).delay(timeout).schedule();
5757
}
5858

5959
@Subscribe
6060
public void onClientLoadedWorldPacket(PacketReceiveEvent event) {
6161
if (!(event.getPacket() instanceof PlayerLoadedWorldPacket)) return;
62-
PlayerClientLoadedWorldEvent.Cause cause = loadingPlayers.remove(event.getPlayer().getUniqueId());
63-
if (cause == null) return;
64-
65-
proxyServer.getEventManager().fireAndForget(new PlayerClientLoadedWorldEvent(event.getPlayer(), cause, false));
62+
loadingPlayers.remove(event.getPlayer().getUniqueId());
63+
proxyServer.getEventManager().fireAndForget(new PlayerClientLoadedWorldEvent(event.getPlayer(), false));
6664
}
6765

6866
@Subscribe

src/main/java/de/timongcraft/veloprotocol/events/PlayerClientLoadedWorldEvent.java

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,33 @@
33
import com.google.common.annotations.Beta;
44
import com.google.common.base.Preconditions;
55
import com.velocitypowered.api.proxy.Player;
6-
import org.jetbrains.annotations.ApiStatus;
7-
8-
//todo: respawn timeout event - requires decoded respawn packets
9-
//todo: normal respawn by allowing after a respawn packet
106

117
/**
12-
* Called when a player is marked as loaded.
8+
* Called when a player is marked as loaded by the client.
139
*
1410
* <p>Note: This event may be fired in the following scenarios:
1511
* <br>- If the player notifies the server after loading the world (closing the downloading terrain screen)
16-
* <br>- If the player has not notified the server within 60 ticks after joining the server / respawning (RESPAWN NOT IMPLEMENTED) - ({@link #timeout} = true)
17-
* <br>- If the player respawned (NOT IMPLEMENTED)
12+
* <br>- If the player has <u>not</u> notified the server within 1500ms after joining the server - ({@link #timeout} = true)
1813
*/
1914
@Beta
20-
public class PlayerClientLoadedWorldEvent {
15+
@Deprecated(since = "1.3.3", forRemoval = true) // will be removed when the pull request is merged - https://github.com/PaperMC/Velocity/pull/1541
16+
public final class PlayerClientLoadedWorldEvent {
2117

2218
private final Player player;
23-
private final Cause cause;
2419
private final boolean timeout;
2520

26-
@ApiStatus.Internal
27-
public PlayerClientLoadedWorldEvent(Player player, Cause cause, boolean timeout) {
21+
public PlayerClientLoadedWorldEvent(Player player, boolean timeout) {
2822
this.player = Preconditions.checkNotNull(player, "player");
29-
this.cause = Preconditions.checkNotNull(cause, "cause");
3023
this.timeout = timeout;
3124
}
3225

3326
public Player getPlayer() {
3427
return player;
3528
}
3629

37-
public Cause getCause() {
38-
return cause;
39-
}
40-
4130
/**
4231
* True if the event was triggered because the server has not been notified by the player
43-
* for 60 ticks after the player joined the server or respawned.
32+
* for 1500ms after the player joined the server.
4433
*
4534
* @return true if the event was triggered because of a timeout
4635
*/
@@ -50,30 +39,10 @@ public boolean isTimeout() {
5039

5140
@Override
5241
public String toString() {
53-
return "PlayerClientLoadedWorldEvent{" +
54-
"player=" + player +
55-
", cause=" + cause +
56-
", timeout=" + timeout +
57-
'}';
58-
}
59-
60-
/**
61-
* Represents the possible causes for the event.
62-
*/
63-
public enum Cause {
64-
65-
/**
66-
* The player joined a server and loaded the first world
67-
*/
68-
SERVER_JOIN,
69-
/**
70-
* The player respawned.
71-
*
72-
* <p>Note: This will also be triggered on dimension switches
73-
*/
74-
// TODO: implement
75-
RESPAWN
76-
42+
return "PlayerClientLoadedWorldEvent{"
43+
+ "player=" + player
44+
+ ", timeout=" + timeout
45+
+ '}';
7746
}
7847

7948
}

src/main/java/de/timongcraft/veloprotocol/network/protocol/packets/BlockEntityDataPacket.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,8 @@ public static void register(boolean encodeOnly) {
2626
.stateRegistry(StateRegistry.PLAY)
2727
.mapping(0x0A, ProtocolVersion.MINECRAFT_1_18_2, encodeOnly)
2828
.mapping(0x07, ProtocolVersion.MINECRAFT_1_19, encodeOnly)
29-
.mapping(0x07, ProtocolVersion.MINECRAFT_1_19_1, encodeOnly)
30-
.mapping(0x07, ProtocolVersion.MINECRAFT_1_19_3, encodeOnly)
3129
.mapping(0x08, ProtocolVersion.MINECRAFT_1_19_4, encodeOnly)
32-
.mapping(0x08, ProtocolVersion.MINECRAFT_1_20, encodeOnly)
3330
.mapping(0x07, ProtocolVersion.MINECRAFT_1_20_2, encodeOnly)
34-
.mapping(0x07, ProtocolVersion.MINECRAFT_1_20_3, encodeOnly)
35-
.mapping(0x07, ProtocolVersion.MINECRAFT_1_20_5, encodeOnly)
36-
.mapping(0x07, ProtocolVersion.MINECRAFT_1_21, encodeOnly)
37-
.mapping(0x07, ProtocolVersion.MINECRAFT_1_21_2, encodeOnly)
3831
.mapping(0x06, ProtocolVersion.MINECRAFT_1_21_5, encodeOnly)
3932
.register();
4033
}

src/main/java/de/timongcraft/veloprotocol/network/protocol/packets/BlockUpdatePacket.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,8 @@ public static void register(boolean encodeOnly) {
2424
.stateRegistry(StateRegistry.PLAY)
2525
.mapping(0x0C, ProtocolVersion.MINECRAFT_1_18_2, encodeOnly)
2626
.mapping(0x09, ProtocolVersion.MINECRAFT_1_19, encodeOnly)
27-
.mapping(0x09, ProtocolVersion.MINECRAFT_1_19_1, encodeOnly)
28-
.mapping(0x09, ProtocolVersion.MINECRAFT_1_19_3, encodeOnly)
2927
.mapping(0x0A, ProtocolVersion.MINECRAFT_1_19_4, encodeOnly)
30-
.mapping(0x0A, ProtocolVersion.MINECRAFT_1_20, encodeOnly)
3128
.mapping(0x09, ProtocolVersion.MINECRAFT_1_20_2, encodeOnly)
32-
.mapping(0x09, ProtocolVersion.MINECRAFT_1_20_3, encodeOnly)
33-
.mapping(0x09, ProtocolVersion.MINECRAFT_1_20_5, encodeOnly)
34-
.mapping(0x09, ProtocolVersion.MINECRAFT_1_21, encodeOnly)
35-
.mapping(0x09, ProtocolVersion.MINECRAFT_1_21_2, encodeOnly)
3629
.mapping(0x08, ProtocolVersion.MINECRAFT_1_21_5, encodeOnly)
3730
.register();
3831
}

src/main/java/de/timongcraft/veloprotocol/network/protocol/packets/EntityEffectPacket.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ public static void register(boolean encodeOnly) {
3434
.mapping(0x69, ProtocolVersion.MINECRAFT_1_19_1, encodeOnly)
3535
.mapping(0x68, ProtocolVersion.MINECRAFT_1_19_3, encodeOnly)
3636
.mapping(0x6C, ProtocolVersion.MINECRAFT_1_19_4, encodeOnly)
37-
.mapping(0x6C, ProtocolVersion.MINECRAFT_1_20, encodeOnly)
3837
.mapping(0x6E, ProtocolVersion.MINECRAFT_1_20_2, encodeOnly)
3938
.mapping(0x72, ProtocolVersion.MINECRAFT_1_20_3, encodeOnly)
4039
.mapping(0x76, ProtocolVersion.MINECRAFT_1_20_5, encodeOnly)
41-
.mapping(0x76, ProtocolVersion.MINECRAFT_1_21, encodeOnly)
4240
.mapping(0x7D, ProtocolVersion.MINECRAFT_1_21_2, encodeOnly)
4341
.register();
4442
}

src/main/java/de/timongcraft/veloprotocol/network/protocol/packets/PlayerLoadedWorldPacket.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* (latest) Resource Id: 'minecraft:player_loaded'
1515
*/
1616
@SuppressWarnings("unused")
17+
@Deprecated(since = "1.3.3", forRemoval = true) // will be removed when the pull request is merged - https://github.com/PaperMC/Velocity/pull/1541
1718
@Beta
1819
@Since(ProtocolVersion.MINECRAFT_1_21_4)
1920
public class PlayerLoadedWorldPacket extends VeloPacket {

0 commit comments

Comments
 (0)