Compare commits
436
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b3cf41f35 | ||
|
|
7509ecb971 | ||
|
|
738309506d | ||
|
|
5243d9f17d | ||
|
|
bd91ef1be1 | ||
|
|
8a9338ae46 | ||
|
|
9aa27103a0 | ||
|
|
af105f4add | ||
|
|
d2d3d84cbf | ||
|
|
e9a5c9315c | ||
|
|
3a93098804 | ||
|
|
0b404d04cd | ||
|
|
f7b6fc476f | ||
|
|
0bcf58cf80 | ||
|
|
67eaa91252 | ||
|
|
1ad7cae303 | ||
|
|
b7d04384fb | ||
|
|
ea32d28d0b | ||
|
|
ad70e4b996 | ||
|
|
c320ebce86 | ||
|
|
01c81f5a0b | ||
|
|
66c722ec00 | ||
|
|
af38857d07 | ||
|
|
5a1a02d212 | ||
|
|
bc96b5cd3e | ||
|
|
c44e834c01 | ||
|
|
4273bf6587 | ||
|
|
3329a544a4 | ||
|
|
075784498c | ||
|
|
03b68a7f6f | ||
|
|
dc614c96c3 | ||
|
|
f77f705942 | ||
|
|
aa9cc58b49 | ||
|
|
9de4dcf4b1 | ||
|
|
eae3d091f8 | ||
|
|
5f499123df | ||
|
|
a6c16ab45a | ||
|
|
c060a55740 | ||
|
|
8447998ce6 | ||
|
|
99bc0ffcb6 | ||
|
|
dea5feaa1e | ||
|
|
ebea88f60f | ||
|
|
5717b6050e | ||
|
|
8eb60e9398 | ||
|
|
4db2dc0592 | ||
|
|
ba1daa4b17 | ||
|
|
69700bce2a | ||
|
|
9dc0db4eae | ||
|
|
8aeef01bd4 | ||
|
|
3fff3925b2 | ||
|
|
72c0ecbc5d | ||
|
|
785c8056f9 | ||
|
|
48ef856d02 | ||
|
|
c052ecf8c0 | ||
|
|
64ae9bfe27 | ||
|
|
7b028f61d6 | ||
|
|
5d3f2105f0 | ||
|
|
a4c57cf41c | ||
|
|
e8fa6d793f | ||
|
|
8fa6c3ad1e | ||
|
|
2044657fb6 | ||
|
|
8c216d0aa6 | ||
|
|
b80f22bf08 | ||
|
|
4b0414c61b | ||
|
|
3c43382148 | ||
|
|
00e081fcad | ||
|
|
8cc8e5f171 | ||
|
|
b449205b6f | ||
|
|
bbe88eba3d | ||
|
|
f271778905 | ||
|
|
fdefa91208 | ||
|
|
909eb7cde3 | ||
|
|
1b3598182b | ||
|
|
031d190da2 | ||
|
|
744cb05253 | ||
|
|
b1b2b10ee5 | ||
|
|
6efb6aebdf | ||
|
|
a633c2558a | ||
|
|
88cd3bea89 | ||
|
|
1ec83d1398 | ||
|
|
adf46aaeca | ||
|
|
43669d3652 | ||
|
|
bc356c6daf | ||
|
|
b090424510 | ||
|
|
3fd2b883de | ||
|
|
e3e29ed79b | ||
|
|
be4e820c0a | ||
|
|
d7e1aa2161 | ||
|
|
f214cc54c6 | ||
|
|
31157da8bb | ||
|
|
d54baa4293 | ||
|
|
e3e4ac027f | ||
|
|
c8023cd828 | ||
|
|
9770948c45 | ||
|
|
6b62e2152f | ||
|
|
88a223e2d9 | ||
|
|
74f28ad610 | ||
|
|
085b37b2ed | ||
|
|
c565d94d41 | ||
|
|
d054164a4b | ||
|
|
cd0679c3b2 | ||
|
|
1be60149f9 | ||
|
|
b48e271ced | ||
|
|
2bcb1dcb90 | ||
|
|
c8d472beb7 | ||
|
|
18689e4f00 | ||
|
|
440c73431e | ||
|
|
de634687fa | ||
|
|
6d0a753d2d | ||
|
|
c43b24c0db | ||
|
|
7df7ffcc69 | ||
|
|
cca73eabe0 | ||
|
|
db7f8d9cbd | ||
|
|
a53ff85a66 | ||
|
|
46a7f39be6 | ||
|
|
89801adc76 | ||
|
|
a405880a89 | ||
|
|
bd5c4207bc | ||
|
|
3564bc56e4 | ||
|
|
6f18f867c0 | ||
|
|
1ae1b5abf1 | ||
|
|
f8a920a2cb | ||
|
|
b497efc0c1 | ||
|
|
dfb36a48f9 | ||
|
|
0e471c665d | ||
|
|
f76b2f7c72 | ||
|
|
4915d7d4a3 | ||
|
|
16e3861b41 | ||
|
|
b57855b6ba | ||
|
|
6edd19e416 | ||
|
|
4ef61c71bf | ||
|
|
6a5f0d3e50 | ||
|
|
9b20221587 | ||
|
|
70b540e67f | ||
|
|
f76b26e5d7 | ||
|
|
19b6d3c999 | ||
|
|
49955e2dc8 | ||
|
|
cd6a4d0cd2 | ||
|
|
4f1cd6c8bc | ||
|
|
29fe12ef57 | ||
|
|
5116d62488 | ||
|
|
6387309f01 | ||
|
|
bb27307e25 | ||
|
|
0ad3baeea4 | ||
|
|
635d0f2a7c | ||
|
|
5f49f63e8f | ||
|
|
45dd54dfb3 | ||
|
|
bcf35813d8 | ||
|
|
327b514216 | ||
|
|
96f67109fe | ||
|
|
50d42f9fc9 | ||
|
|
e248a47a1f | ||
|
|
5d3e4bd0f8 | ||
|
|
3b3f0a84be | ||
|
|
9b55e982b3 | ||
|
|
712f1013f4 | ||
|
|
eb4bab70d1 | ||
|
|
d970c4e020 | ||
|
|
825157f998 | ||
|
|
c41f1797e8 | ||
|
|
f871e71823 | ||
|
|
a270b515d2 | ||
|
|
b90920e63a | ||
|
|
4def9c7ab1 | ||
|
|
79f102ecc5 | ||
|
|
1bdc56d251 | ||
|
|
d1d793f9e7 | ||
|
|
1c661f0a5d | ||
|
|
9db70222c0 | ||
|
|
42b16f1fbd | ||
|
|
34d4fac6e8 | ||
|
|
f63a290d34 | ||
|
|
68867c135d | ||
|
|
7ae55731fb | ||
|
|
cd24067ce7 | ||
|
|
3f1f65e4a3 | ||
|
|
0095487773 | ||
|
|
7d2e67b95d | ||
|
|
b0db7045f4 | ||
|
|
bfdab3a518 | ||
|
|
fc49c374bf | ||
|
|
4b776ca7bf | ||
|
|
0f58efa3cc | ||
|
|
0d3a8e5410 | ||
|
|
c6d3d72ce9 | ||
|
|
fc651c65ad | ||
|
|
9b86427884 | ||
|
|
849713eaea | ||
|
|
52db6d7b6a | ||
|
|
0434cd6bf8 | ||
|
|
dbab8591bf | ||
|
|
065649d1df | ||
|
|
2d2e0cdfeb | ||
|
|
c3e8f307b7 | ||
|
|
e03f1ef713 | ||
|
|
eb4f73b582 | ||
|
|
1609d1c2b0 | ||
|
|
3480620eca | ||
|
|
e694af304e | ||
|
|
581c04e66e | ||
|
|
2e737288ef | ||
|
|
18a1d51c19 | ||
|
|
db7ec7fe95 | ||
|
|
d619546735 | ||
|
|
b78b449895 | ||
|
|
f53198aec5 | ||
|
|
fa1728210a | ||
|
|
90674cefc4 | ||
|
|
24d4a21007 | ||
|
|
b4ad4e831d | ||
|
|
886d872241 | ||
|
|
0ef01b868e | ||
|
|
46f89771a5 | ||
|
|
055f473964 | ||
|
|
f3850dab24 | ||
|
|
86870c40a5 | ||
|
|
dbc33f9fe4 | ||
|
|
1f95fda03c | ||
|
|
1724f54b12 | ||
|
|
4b0132ed90 | ||
|
|
d219faafd0 | ||
|
|
6d19f60049 | ||
|
|
a8f1b23769 | ||
|
|
89cb93be67 | ||
|
|
bfe9aba3a8 | ||
|
|
5265ddd27c | ||
|
|
5e118f5e17 | ||
|
|
a522e8262a | ||
|
|
028bfd8ada | ||
|
|
d1ba1b8831 | ||
|
|
2a7c79235d | ||
|
|
ebaf94a5ec | ||
|
|
5c9b930737 | ||
|
|
9483582479 | ||
|
|
cd7b23a537 | ||
|
|
97609976e4 | ||
|
|
4262f1f9cd | ||
|
|
eb6237d913 | ||
|
|
fcf2edefe8 | ||
|
|
a7a9ef52f0 | ||
|
|
d8ad50fcf8 | ||
|
|
3a974ab51f | ||
|
|
9834830bda | ||
|
|
e673558179 | ||
|
|
bd17353576 | ||
|
|
4f0403d315 | ||
|
|
0232e7b212 | ||
|
|
68655dd92b | ||
|
|
28ffd08fbd | ||
|
|
4b92eb7912 | ||
|
|
6f76822785 | ||
|
|
165bc85dfa | ||
|
|
fdcb42caf2 | ||
|
|
7d5fcb22a8 | ||
|
|
c2beac9bfa | ||
|
|
49344d0f3c | ||
|
|
18b6ddca70 | ||
|
|
e901b5dd64 | ||
|
|
bf11a02d44 | ||
|
|
15f0295142 | ||
|
|
5c665053d2 | ||
|
|
cddf378b51 | ||
|
|
96bfb98c87 | ||
|
|
d0f85d69ab | ||
|
|
3374827e66 | ||
|
|
96d8fc6d21 | ||
|
|
1fd19db0f2 | ||
|
|
2ef717cd72 | ||
|
|
1868cee073 | ||
|
|
351742e88e | ||
|
|
bd67caaeb8 | ||
|
|
0f39521750 | ||
|
|
7fde4a379a | ||
|
|
5cc7e6f2bc | ||
|
|
f2f4a8d62b | ||
|
|
16f9eb32c9 | ||
|
|
3567b7d735 | ||
|
|
23a181c33a | ||
|
|
74b6bfca28 | ||
|
|
ef1074e7ba | ||
|
|
b02d7a3df2 | ||
|
|
6c3d6f25ac | ||
|
|
de4b9887b7 | ||
|
|
b7c9eabf8f | ||
|
|
ed43c51428 | ||
|
|
69bc454cc0 | ||
|
|
83b87cf9cb | ||
|
|
0f061764e6 | ||
|
|
77a6b8152e | ||
|
|
6a5e76512f | ||
|
|
24bad668bd | ||
|
|
a670961b99 | ||
|
|
f3896d3c78 | ||
|
|
04e9e57dad | ||
|
|
2bccff6ae6 | ||
|
|
3afa857965 | ||
|
|
3441da2bd5 | ||
|
|
898972d040 | ||
|
|
b0d0f18da2 | ||
|
|
1d3a828f55 | ||
|
|
310bb1ea10 | ||
|
|
7f8deb280a | ||
|
|
3204527b6f | ||
|
|
0354e2b5fc | ||
|
|
07dac7c20e | ||
|
|
bf09ad27b9 | ||
|
|
af3bbb3db8 | ||
|
|
f520af9250 | ||
|
|
df590b7083 | ||
|
|
9ec7b8d776 | ||
|
|
18580ced5a | ||
|
|
8dc6b1be29 | ||
|
|
649839c539 | ||
|
|
7401b9bbb0 | ||
|
|
068967fd74 | ||
|
|
20c07143aa | ||
|
|
fafa6e5191 | ||
|
|
327a986944 | ||
|
|
666cc8f81b | ||
|
|
7c81ae2fa4 | ||
|
|
8224019e23 | ||
|
|
b334d82e76 | ||
|
|
e28f416746 | ||
|
|
cd821c3d86 | ||
|
|
42fd096ac3 | ||
|
|
bff4a10355 | ||
|
|
bd52a7856d | ||
|
|
01fb89f378 | ||
|
|
4abe76816d | ||
|
|
e19283e387 | ||
|
|
03286746a0 | ||
|
|
e7ce4dddec | ||
|
|
cd9829bcae | ||
|
|
132f8d53a9 | ||
|
|
abb74ab2cf | ||
|
|
3d97cd1aa0 | ||
|
|
809f712e80 | ||
|
|
88877c7874 | ||
|
|
749f17efbe | ||
|
|
3ef1b424b1 | ||
|
|
bd0185f825 | ||
|
|
f86ed401b2 | ||
|
|
b9d01eb9d8 | ||
|
|
08a0d108b0 | ||
|
|
30b3c20c80 | ||
|
|
d56885c3f9 | ||
|
|
822a52b5b8 | ||
|
|
d8eb1d07f2 | ||
|
|
34956af6a2 | ||
|
|
1f15d0ba20 | ||
|
|
c4798df9dc | ||
|
|
a1fdc00a01 | ||
|
|
d85e7a2b0f | ||
|
|
c78727f15f | ||
|
|
dd1d85e3e4 | ||
|
|
e29c907188 | ||
|
|
450aec3191 | ||
|
|
c672086b8f | ||
|
|
ae3a3a795d | ||
|
|
2fa200b347 | ||
|
|
7d750a42ab | ||
|
|
f61f93a85d | ||
|
|
e0c38b59c1 | ||
|
|
198034ae67 | ||
|
|
10107a14fc | ||
|
|
0e18040bee | ||
|
|
ab92d8bdd3 | ||
|
|
6bf70f5b47 | ||
|
|
59dfa9fabb | ||
|
|
f4a48d5326 | ||
|
|
af5f0d9f85 | ||
|
|
ab6fa602cc | ||
|
|
a15b0c7cc8 | ||
|
|
86bffa503c | ||
|
|
511b331735 | ||
|
|
78d101dd80 | ||
|
|
70dc93cd09 | ||
|
|
fed8b95199 | ||
|
|
e8d8fb5af8 | ||
|
|
d98038ecf7 | ||
|
|
5ea3713a22 | ||
|
|
0d4cc8a505 | ||
|
|
9d0dc9f06d | ||
|
|
261b89792b | ||
|
|
089f0b0e18 | ||
|
|
53e7fbed0e | ||
|
|
988d118478 | ||
|
|
df7be9b51f | ||
|
|
dead95adad | ||
|
|
d69ad9ef9a | ||
|
|
b65bbb03a8 | ||
|
|
83d3ca01fe | ||
|
|
e7732b03f8 | ||
|
|
b742335ffb | ||
|
|
262a17659b | ||
|
|
191e24398a | ||
|
|
ae2a23f0aa | ||
|
|
59944eadf4 | ||
|
|
5208b090dd | ||
|
|
c14b18d24e | ||
|
|
01e2e6a19d | ||
|
|
71ca117931 | ||
|
|
bee7fef71a | ||
|
|
24b8105dcb | ||
|
|
a01e066dae | ||
|
|
e93f94f87c | ||
|
|
eb052cca32 | ||
|
|
b4c1b8c954 | ||
|
|
5d1b6a7d2a | ||
|
|
12bd685fe7 | ||
|
|
3616a18286 | ||
|
|
db6b3489de | ||
|
|
049f5f4123 | ||
|
|
b553f29b71 | ||
|
|
ea6e8ee74e | ||
|
|
6559603147 | ||
|
|
ab8839c07f | ||
|
|
2c83f6e5a5 | ||
|
|
fa4a4a0ca0 | ||
|
|
e9f0e1d7af | ||
|
|
c9cf4f8c9b | ||
|
|
89e20ef82a | ||
|
|
bab579f6f9 | ||
|
|
e26b1dac22 | ||
|
|
23d9c77305 | ||
|
|
8e49b4b400 | ||
|
|
e434e5df76 | ||
|
|
f9136dbf42 | ||
|
|
f144f66e88 | ||
|
|
ab37570e9b | ||
|
|
7a61bb6cdc | ||
|
|
5cf920c78e | ||
|
|
f1a5ca14bc | ||
|
|
e08e4645b1 | ||
|
|
1452b65879 | ||
|
|
85cb8a72ca |
No files matched your search
@@ -1,20 +1,15 @@
|
||||
# packetevents
|
||||
|
||||
[](https://github.com/retrooper/packetevents/blob/dev/LICENSE)
|
||||
[](https://jitpack.io/#retrooper/packetevents)
|
||||
|
||||
PacketEvents is a powerful packet library. Our packet wrappers are efficient and easy to use. With our API, you can write code that runs on many platforms including Spigot, BungeeCord, Velocity, and even client-sided Fabric!
|
||||
|
||||
### Resources
|
||||
* [SpigotMC](https://www.spigotmc.org/resources/packetevents-api.80279/)
|
||||
* [JavaDocs](https://packetevents.github.io/javadocs)
|
||||
* [Discord](https://discord.me/packetevents)
|
||||
PacketEvents is a powerful packet library. Our packet wrappers are efficient and easy to use. With our API, you can write code that runs on many platforms including Spigot, BungeeCord, Velocity, and even client-sided Fabric! Switch to PacketEvents today by joining \
|
||||
our [Discord Server](https://discord.me/packetevents) for help.
|
||||
|
||||
### Links
|
||||
* [Find release builds on SpigotMC](https://www.spigotmc.org/resources/packetevents-api.80279/)
|
||||
* [View documentation on our JavaDocs Page](https://packetevents.github.io/javadocs)
|
||||
### Setup
|
||||
[Learn more](https://github.com/retrooper/packetevents/wiki/Setup)
|
||||
|
||||
### Contributing
|
||||
[Learn more](https://github.com/retrooper/packetevents/wiki/Contributing)
|
||||
[Learn more](https://github.com/retrooper/packetevents/wiki/Setup-2.0)
|
||||
|
||||
### Sponsorships
|
||||
[](https://www.ej-technologies.com/products/jprofiler/overview.html)
|
||||
@@ -23,11 +18,20 @@ PacketEvents is a powerful packet library. Our packet wrappers are efficient and
|
||||
PacketEvents optionally collects statistics using [bStats](https://bstats.org/)\
|
||||
Check out our [bStats page](https://bstats.org/plugin/bukkit/packetevents/11327)
|
||||
|
||||
### Credit to
|
||||
[wiki.vg/Protocol](https://wiki.vg/Protocol)
|
||||
[adventure](https://github.com/KyoriPowered/adventure)
|
||||
[gson](https://github.com/google/gson)
|
||||
[ViaVersion](https://github.com/ViaVersion/ViaVersion)
|
||||
[ProtocolSupport](https://github.com/ProtocolSupport/ProtocolSupport)
|
||||
This library is licensed under the GPLv3 (General Public License version 3). Here are a few sources to learn more about the license.\
|
||||
[](https://github.com/retrooper/packetevents/blob/2.0/LICENSE)
|
||||
### GPL Resources
|
||||
* https://www.gnu.org/philosophy/free-sw.html
|
||||
* https://www.gnu.org/philosophy/free-sw.html#clarifying
|
||||
* https://www.gnu.org/licenses/copyleft.en.html
|
||||
* https://www.gnu.org/licenses/quick-guide-gplv3.html
|
||||
* https://gpl-violations.org/faq/sourcecode-faq/
|
||||
|
||||
### Credit to these projects
|
||||
[wiki.vg/Protocol](https://wiki.vg/Protocol)\
|
||||
[netty](https://github.com/netty/netty)\
|
||||
[gson](https://github.com/google/gson)\
|
||||
[adventure](https://github.com/KyoriPowered/adventure)\
|
||||
[ViaVersion](https://github.com/ViaVersion/ViaVersion)\
|
||||
[ProtocolSupport](https://github.com/ProtocolSupport/ProtocolSupport)\
|
||||
[MCProtocolLib](https://github.com/GeyserMC/MCProtocolLib/)
|
||||
[netty](https://github.com/netty/netty)
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -18,12 +18,20 @@
|
||||
|
||||
package com.github.retrooper.packetevents;
|
||||
|
||||
import com.github.retrooper.packetevents.injector.ChannelInjector;
|
||||
import com.github.retrooper.packetevents.manager.player.PlayerManager;
|
||||
import com.github.retrooper.packetevents.manager.protocol.ProtocolManager;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerManager;
|
||||
import com.github.retrooper.packetevents.netty.NettyManager;
|
||||
import com.github.retrooper.packetevents.settings.PacketEventsSettings;
|
||||
import com.github.retrooper.packetevents.util.LogManager;
|
||||
|
||||
public final class PacketEvents {
|
||||
private static PacketEventsAPI<?> API;
|
||||
|
||||
//Put these variable names anywhere else, they are really only for the injectors
|
||||
public static String IDENTIFIER, ENCODER_NAME, DECODER_NAME, CONNECTION_HANDLER_NAME, SERVER_CHANNEL_HANDLER_NAME,
|
||||
TIMEOUT_HANDLER_NAME;
|
||||
TIMEOUT_HANDLER_NAME;
|
||||
|
||||
public static PacketEventsAPI<?> getAPI() {
|
||||
return API;
|
||||
@@ -32,4 +40,87 @@ public final class PacketEvents {
|
||||
public static void setAPI(PacketEventsAPI<?> api) {
|
||||
API = api;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public abstract static class Context<T> {
|
||||
private final Object pluginInstance;
|
||||
private final ProtocolManager protocolManager;
|
||||
private final ServerManager serverManager;
|
||||
private final PlayerManager playerManager;
|
||||
private final NettyManager nettyManager;
|
||||
private final ChannelInjector injector;
|
||||
private final LogManager logManager;
|
||||
protected boolean lateBind = false;
|
||||
|
||||
public Context(Object pluginInstance, ProtocolManager protocolManager, ServerManager serverManager, PlayerManager playerManager,
|
||||
NettyManager nettyManager, ChannelInjector injector, LogManager logManager) {
|
||||
this.pluginInstance = pluginInstance;
|
||||
this.protocolManager = protocolManager;
|
||||
this.serverManager = serverManager;
|
||||
this.playerManager = playerManager;
|
||||
this.nettyManager = nettyManager;
|
||||
this.injector = injector;
|
||||
this.logManager = logManager;
|
||||
}
|
||||
|
||||
protected abstract PacketEventsAPI<T> build();
|
||||
|
||||
public Object getPluginInstance() {
|
||||
return pluginInstance;
|
||||
}
|
||||
|
||||
public ProtocolManager getProtocolManager() {
|
||||
return protocolManager;
|
||||
}
|
||||
|
||||
public ServerManager getServerManager() {
|
||||
return serverManager;
|
||||
}
|
||||
|
||||
public PlayerManager getPlayerManager() {
|
||||
return playerManager;
|
||||
}
|
||||
|
||||
public NettyManager getNettyManager() {
|
||||
return nettyManager;
|
||||
}
|
||||
|
||||
public ChannelInjector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
public LogManager getLogManager() {
|
||||
return logManager;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private Context<?> context = null;
|
||||
private PacketEventsSettings settings = new PacketEventsSettings();
|
||||
public Builder context(Context<?> context) {
|
||||
this.context = context;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder settings(PacketEventsSettings settings) {
|
||||
this.settings = settings;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PacketEventsAPI<?> build() {
|
||||
if (context == null) {
|
||||
throw new IllegalStateException("Failed to build a PacketEvents instance. Please specify a PacketEvents context in the PacketEvents builder to allow PacketEvents to load the correct implementation.");
|
||||
}
|
||||
PacketEventsAPI<?> api = context.build();
|
||||
api.setSettings(settings);
|
||||
//The implementation may have already set the API.
|
||||
if (getAPI() == null) {
|
||||
setAPI(api);
|
||||
}
|
||||
return api;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -33,10 +33,11 @@ import java.util.logging.Logger;
|
||||
|
||||
public abstract class PacketEventsAPI<T> {
|
||||
private static final EventManager EVENT_MANAGER = new EventManager();
|
||||
private static final PacketEventsSettings SETTINGS = new PacketEventsSettings();
|
||||
private static final UpdateChecker UPDATE_CHECKER = new UpdateChecker();
|
||||
private final Logger LOGGER = Logger.getLogger(PacketEventsAPI.class.getName());
|
||||
private static final LogManager LOG_MANAGER = new LogManager();
|
||||
private final Logger LOGGER = Logger.getLogger(PacketEventsAPI.class.getName());
|
||||
private PacketEventsSettings settings = new PacketEventsSettings();
|
||||
//TODO UPDATE
|
||||
private static final PEVersion VERSION = new PEVersion(2, 0, 0);
|
||||
|
||||
public EventManager getEventManager() {
|
||||
@@ -44,7 +45,11 @@ public abstract class PacketEventsAPI<T> {
|
||||
}
|
||||
|
||||
public PacketEventsSettings getSettings() {
|
||||
return SETTINGS;
|
||||
return settings;
|
||||
}
|
||||
|
||||
public void setSettings(PacketEventsSettings settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public UpdateChecker getUpdateChecker() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -22,6 +22,7 @@ import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.exception.PacketProcessException;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
|
||||
import com.github.retrooper.packetevents.netty.buffer.UnpooledByteBufAllocationHelper;
|
||||
import com.github.retrooper.packetevents.netty.channel.ChannelHelper;
|
||||
import com.github.retrooper.packetevents.protocol.ConnectionState;
|
||||
import com.github.retrooper.packetevents.protocol.PacketSide;
|
||||
@@ -59,8 +60,7 @@ public abstract class ProtocolPacketEvent<T> extends PacketEvent implements Play
|
||||
this.player = player;
|
||||
if (autoProtocolTranslation || user.getClientVersion() == null) {
|
||||
this.serverVersion = PacketEvents.getAPI().getServerManager().getVersion();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
//TODO Optimize
|
||||
this.serverVersion = user.getClientVersion().toServerVersion();
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public abstract class ProtocolPacketEvent<T> extends PacketEvent implements Play
|
||||
this.packetType = PacketType.getById(packetSide, user.getConnectionState(),
|
||||
version, packetID);
|
||||
if (this.packetType == null) {
|
||||
throw new PacketProcessException("Failed to map the Packet ID " + packetID + " to a PacketType constant. Bound: " + packetSide.getOpposite() + ", Connection state: " + user.getConnectionState() + ", Server version: " + serverVersion.getReleaseName());
|
||||
throw new PacketProcessException("Failed to map the Packet ID " + packetID + " to a PacketType constant. Bound: " + packetSide.getOpposite() + ", Connection state: " + user.getConnectionState() + ", Server version: " + serverVersion.getReleaseName());
|
||||
}
|
||||
this.connectionState = user.getConnectionState();
|
||||
}
|
||||
@@ -206,4 +206,12 @@ public abstract class ProtocolPacketEvent<T> extends PacketEvent implements Play
|
||||
ByteBufHelper.release(byteBuf);
|
||||
}
|
||||
}
|
||||
|
||||
public Object getFullBufferClone() {
|
||||
byte[] data = ByteBufHelper.copyBytes(getByteBuf());
|
||||
Object buffer = UnpooledByteBufAllocationHelper.buffer();
|
||||
ByteBufHelper.writeVarInt(buffer, getPacketId());
|
||||
ByteBufHelper.writeBytes(buffer, data);
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.github.retrooper.packetevents.event.simple;
|
||||
|
||||
import com.github.retrooper.packetevents.event.PacketSendEvent;
|
||||
import com.github.retrooper.packetevents.exception.PacketProcessException;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
|
||||
public class PacketHandshakeSendEvent extends PacketSendEvent {
|
||||
public PacketHandshakeSendEvent(Object channel, User user,
|
||||
Object player, Object rawByteBuf,
|
||||
boolean autoProtocolTranslation) throws PacketProcessException {
|
||||
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
|
||||
}
|
||||
|
||||
protected PacketHandshakeSendEvent(int packetId, PacketTypeCommon packetType,
|
||||
ServerVersion serverVersion,
|
||||
Object channel,
|
||||
User user, Object player, Object byteBuf) throws PacketProcessException {
|
||||
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketHandshakeSendEvent clone() {
|
||||
try {
|
||||
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
|
||||
return new PacketHandshakeSendEvent(getPacketId(), getPacketType(), getServerVersion(),
|
||||
getChannel(), getUser(), getPlayer(), clonedBuffer);
|
||||
} catch (PacketProcessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PacketType.Handshaking.Client getPacketType() {
|
||||
return (PacketType.Handshaking.Client) super.getPacketType();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+20
-20
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -61,10 +61,15 @@ public class InternalPacketListener extends PacketListenerAbstract {
|
||||
//Update user profile
|
||||
user.getProfile().setUUID(profile.getUUID());
|
||||
user.getProfile().setName(profile.getName());
|
||||
//Texture properties are passed in login success on 1.19
|
||||
user.getProfile().setTextureProperties(profile.getTextureProperties());
|
||||
|
||||
//Map username with channel
|
||||
ProtocolManager.CHANNELS.put(profile.getName(), channel);
|
||||
PacketEvents.getAPI().getLogManager().debug("Mapped player username with their channel.");
|
||||
synchronized (channel) {
|
||||
ProtocolManager.CHANNELS.put(profile.getUUID(), channel);
|
||||
}
|
||||
|
||||
PacketEvents.getAPI().getLogManager().debug("Mapped player UUID with their channel.");
|
||||
|
||||
//Update connection state(injectors might do some adjustments when we transition into PLAY state)
|
||||
//This also updates it for the user instance
|
||||
@@ -76,32 +81,32 @@ public class InternalPacketListener extends PacketListenerAbstract {
|
||||
|
||||
// Join game can be used to update world height, and sets dimension data
|
||||
|
||||
if (event.getPacketType() == PacketType.Play.Server.JOIN_GAME) {
|
||||
else if (event.getPacketType() == PacketType.Play.Server.JOIN_GAME) {
|
||||
WrapperPlayServerJoinGame joinGame = new WrapperPlayServerJoinGame(event);
|
||||
user.setEntityId(joinGame.getEntityId());
|
||||
if (event.getServerVersion().isOlderThanOrEquals(ServerVersion.V_1_16_5)) {
|
||||
return; // Fixed world height, no tags are sent to the client
|
||||
}
|
||||
|
||||
// Store world height
|
||||
NBTList<NBTCompound> list = joinGame.getDimensionCodec()
|
||||
.getCompoundTagOrNull("minecraft:dimension_type").getCompoundListTagOrNull("value");
|
||||
NBTList<NBTCompound> list = joinGame.getDimensionCodec().getCompoundTagOrNull("minecraft:dimension_type").getCompoundListTagOrNull("value");
|
||||
user.setWorldNBT(list);
|
||||
|
||||
// Update world height
|
||||
NBTCompound worldNBT = user.getWorldNBT(joinGame.getDimension().getType().getName()).getCompoundTagOrNull("element");
|
||||
NBTCompound worldNBT = user.getWorldNBT(joinGame.getDimension().getDimensionName()).getCompoundTagOrNull("element");
|
||||
user.setMinWorldHeight(worldNBT.getNumberTagOrNull("min_y").getAsInt());
|
||||
user.setTotalWorldHeight(worldNBT.getNumberTagOrNull("height").getAsInt());
|
||||
}
|
||||
|
||||
// Respawn is used to switch dimensions
|
||||
if (event.getPacketType() == PacketType.Play.Server.RESPAWN) {
|
||||
if (event.getServerVersion()
|
||||
.isOlderThanOrEquals(ServerVersion.V_1_16_5)) {
|
||||
else if (event.getPacketType() == PacketType.Play.Server.RESPAWN) {
|
||||
if (event.getServerVersion().isOlderThanOrEquals(ServerVersion.V_1_16_5)) {
|
||||
return; // Fixed world height, no tags are sent to the client
|
||||
}
|
||||
|
||||
WrapperPlayServerRespawn respawn = new WrapperPlayServerRespawn(event);
|
||||
|
||||
NBTCompound worldNBT = user.getWorldNBT(respawn.getDimension().getType().getName()).getCompoundTagOrNull("element"); // This is 1.17+, it always sends the world name
|
||||
NBTCompound worldNBT = user.getWorldNBT(respawn.getDimension().getDimensionName()).getCompoundTagOrNull("element"); // This is 1.17+, it always sends the world name
|
||||
user.setMinWorldHeight(worldNBT.getNumberTagOrNull("min_y").getAsInt());
|
||||
user.setTotalWorldHeight(worldNBT.getNumberTagOrNull("height").getAsInt());
|
||||
}
|
||||
@@ -113,17 +118,12 @@ public class InternalPacketListener extends PacketListenerAbstract {
|
||||
if (event.getPacketType() == PacketType.Handshaking.Client.HANDSHAKE) {
|
||||
Object channel = event.getChannel();
|
||||
InetSocketAddress address = event.getSocketAddress();
|
||||
WrapperHandshakingClientHandshake handshake;
|
||||
try {
|
||||
handshake = new WrapperHandshakingClientHandshake(event);
|
||||
} catch (ArrayIndexOutOfBoundsException exception) {
|
||||
user.closeConnection();
|
||||
PacketEvents.getAPI().getLogManager().debug("Disconnected " + address.getHostString() + ":" + address.getPort() + " for sending an invalid handshaking packet. They might be on an outdated client.");
|
||||
return;
|
||||
}
|
||||
WrapperHandshakingClientHandshake handshake = new WrapperHandshakingClientHandshake(event);
|
||||
ConnectionState nextState = handshake.getNextConnectionState();
|
||||
ClientVersion clientVersion = handshake.getClientVersion();
|
||||
|
||||
if (clientVersion == ClientVersion.UNKNOWN) {
|
||||
return;
|
||||
}
|
||||
//Update client version for this event call(and user)
|
||||
user.setClientVersion(clientVersion);
|
||||
PacketEvents.getAPI().getLogManager().debug("Processed " + address.getHostString() + ":" + address.getPort() + "'s client version. Client Version: " + clientVersion.getReleaseName());
|
||||
|
||||
+2
-51
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -32,7 +32,7 @@ public interface PlayerManager {
|
||||
|
||||
Object getChannel(@NotNull Object player);
|
||||
|
||||
@NotNull User getUser(@NotNull Object player);
|
||||
User getUser(@NotNull Object player);
|
||||
|
||||
default ConnectionState getConnectionState(@NotNull Object player) {
|
||||
return getUser(player).getConnectionState();
|
||||
@@ -41,96 +41,47 @@ public interface PlayerManager {
|
||||
default void sendPacket(@NotNull Object player, @NotNull Object byteBuf) {
|
||||
PacketEvents.getAPI().getProtocolManager().sendPacket(getChannel(player), byteBuf);
|
||||
}
|
||||
|
||||
default void sendPacketAsync(@NotNull Object player, @NotNull Object byteBuf) {
|
||||
PacketEvents.getAPI().getProtocolManager().sendPacketAsync(getChannel(player), byteBuf);
|
||||
}
|
||||
|
||||
default void sendPacket(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
|
||||
PacketEvents.getAPI().getProtocolManager().sendPacket(getChannel(player), wrapper);
|
||||
}
|
||||
|
||||
default void sendPacketAsync(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
|
||||
PacketEvents.getAPI().getProtocolManager().sendPacketAsync(getChannel(player), wrapper);
|
||||
}
|
||||
|
||||
default void sendPacketSilently(@NotNull Object player, @NotNull Object byteBuf) {
|
||||
PacketEvents.getAPI().getProtocolManager().sendPacketSilently(getChannel(player), byteBuf);
|
||||
}
|
||||
|
||||
default void sendPacketSilentlyAsync(@NotNull Object player, @NotNull Object byteBuf) {
|
||||
PacketEvents.getAPI().getProtocolManager().sendPacketSilentlyAsync(getChannel(player), byteBuf);
|
||||
}
|
||||
|
||||
default void sendPacketSilently(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
|
||||
PacketEvents.getAPI().getProtocolManager().sendPacketSilently(getChannel(player), wrapper);
|
||||
}
|
||||
|
||||
default void sendPacketSilentlyAsync(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
|
||||
PacketEvents.getAPI().getProtocolManager().sendPacketSilentlyAsync(getChannel(player), wrapper);
|
||||
}
|
||||
|
||||
default void writePacket(@NotNull Object player, @NotNull Object byteBuf) {
|
||||
PacketEvents.getAPI().getProtocolManager().writePacket(getChannel(player), byteBuf);
|
||||
}
|
||||
|
||||
default void writePacketAsync(@NotNull Object player, @NotNull Object byteBuf) {
|
||||
PacketEvents.getAPI().getProtocolManager().writePacketAsync(getChannel(player), byteBuf);
|
||||
}
|
||||
|
||||
default void writePacket(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
|
||||
PacketEvents.getAPI().getProtocolManager().writePacket(getChannel(player), wrapper);
|
||||
}
|
||||
|
||||
default void writePacketAsync(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
|
||||
PacketEvents.getAPI().getProtocolManager().writePacketAsync(getChannel(player), wrapper);
|
||||
}
|
||||
|
||||
default void writePacketSilently(@NotNull Object player, @NotNull Object byteBuf) {
|
||||
PacketEvents.getAPI().getProtocolManager().writePacketSilently(getChannel(player), byteBuf);
|
||||
}
|
||||
|
||||
default void writePacketSilentlyAsync(@NotNull Object player, @NotNull Object byteBuf) {
|
||||
PacketEvents.getAPI().getProtocolManager().writePacketSilentlyAsync(getChannel(player), byteBuf);
|
||||
}
|
||||
|
||||
default void writePacketSilently(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
|
||||
PacketEvents.getAPI().getProtocolManager().writePacketSilently(getChannel(player), wrapper);
|
||||
}
|
||||
|
||||
default void writePacketSilentlyAsync(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
|
||||
PacketEvents.getAPI().getProtocolManager().writePacketSilentlyAsync(getChannel(player), wrapper);
|
||||
}
|
||||
|
||||
default void receivePacket(Object player, Object byteBuf) {
|
||||
PacketEvents.getAPI().getProtocolManager().receivePacket(getChannel(player), byteBuf);
|
||||
}
|
||||
|
||||
default void receivePacketAsync(Object player, Object byteBuf) {
|
||||
PacketEvents.getAPI().getProtocolManager().receivePacketAsync(getChannel(player), byteBuf);
|
||||
}
|
||||
|
||||
default void receivePacket(Object player, PacketWrapper<?> wrapper) {
|
||||
PacketEvents.getAPI().getProtocolManager().receivePacket(getChannel(player), wrapper);
|
||||
}
|
||||
|
||||
default void receivePacketAsync(Object player, PacketWrapper<?> wrapper) {
|
||||
PacketEvents.getAPI().getProtocolManager().receivePacketAsync(getChannel(player), wrapper);
|
||||
}
|
||||
|
||||
default void receivePacketSilently(Object player, Object byteBuf) {
|
||||
PacketEvents.getAPI().getProtocolManager().receivePacketSilently(getChannel(player), byteBuf);
|
||||
}
|
||||
|
||||
default void receivePacketSilentlyAsync(Object player, Object byteBuf) {
|
||||
PacketEvents.getAPI().getProtocolManager().receivePacketSilentlyAsync(getChannel(player), byteBuf);
|
||||
}
|
||||
|
||||
default void receivePacketSilently(Object player, PacketWrapper<?> wrapper) {
|
||||
PacketEvents.getAPI().getProtocolManager().receivePacketSilently(getChannel(player), wrapper);
|
||||
}
|
||||
|
||||
default void receivePacketSilentlyAsync(Object player, PacketWrapper<?> wrapper) {
|
||||
PacketEvents.getAPI().getProtocolManager().receivePacketSilentlyAsync(getChannel(player), wrapper);
|
||||
}
|
||||
}
|
||||
+60
-107
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -26,15 +26,14 @@ import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
import com.github.retrooper.packetevents.util.PacketTransformationUtil;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public interface ProtocolManager {
|
||||
Map<String, Object> CHANNELS = new ConcurrentHashMap<>();
|
||||
Map<UUID, Object> CHANNELS = new ConcurrentHashMap<>();
|
||||
Map<Object, User> USERS = new ConcurrentHashMap<>();
|
||||
|
||||
default Collection<User> getUsers() {
|
||||
@@ -47,55 +46,49 @@ public interface ProtocolManager {
|
||||
|
||||
//Methods to implement
|
||||
ProtocolVersion getPlatformVersion();
|
||||
|
||||
void sendPacket(Object channel, Object packet);
|
||||
|
||||
void sendPacketSilently(Object channel, Object packet);
|
||||
|
||||
void writePacket(Object channel, Object packet);
|
||||
|
||||
void writePacketSilently(Object channel, Object packet);
|
||||
|
||||
void receivePacket(Object channel, Object packet);
|
||||
|
||||
void receivePacketSilently(Object channel, Object packet);
|
||||
|
||||
void sendPacket(Object channel, Object byteBuf);
|
||||
void sendPacketSilently(Object channel, Object byteBuf);
|
||||
void writePacket(Object channel, Object byteBuf);
|
||||
void writePacketSilently(Object channel, Object byteBuf);
|
||||
void receivePacket(Object channel, Object byteBuf);
|
||||
void receivePacketSilently(Object channel, Object byteBuf);
|
||||
ClientVersion getClientVersion(Object channel);
|
||||
//TODO Define method that accepts an array of channels/set/list of channels.
|
||||
|
||||
default void sendPacketAsync(Object channel, Object byteBuf) {
|
||||
ChannelHelper.runInEventLoop(channel, () -> {
|
||||
sendPacket(channel, byteBuf);
|
||||
});
|
||||
default void sendPackets(Object channel, Object... byteBuf) {
|
||||
for (Object buf : byteBuf) {
|
||||
sendPacket(channel, buf);
|
||||
}
|
||||
}
|
||||
|
||||
default void sendPacketSilentlyAsync(Object channel, Object byteBuf) {
|
||||
ChannelHelper.runInEventLoop(channel, () -> {
|
||||
sendPacketSilently(channel, byteBuf);
|
||||
});
|
||||
default void sendPacketsSilently(Object channel, Object... byteBuf) {
|
||||
for (Object buf : byteBuf) {
|
||||
sendPacketSilently(channel, buf);
|
||||
}
|
||||
}
|
||||
|
||||
default void writePacketAsync(Object channel, Object byteBuf) {
|
||||
ChannelHelper.runInEventLoop(channel, () -> {
|
||||
writePacket(channel, byteBuf);
|
||||
});
|
||||
default void writePackets(Object channel, Object... byteBuf) {
|
||||
for (Object buf : byteBuf) {
|
||||
writePacket(channel, buf);
|
||||
}
|
||||
}
|
||||
|
||||
default void writePacketSilentlyAsync(Object channel, Object byteBuf) {
|
||||
ChannelHelper.runInEventLoop(channel, () -> {
|
||||
writePacketSilently(channel, byteBuf);
|
||||
});
|
||||
default void writePacketsSilently(Object channel, Object... byteBuf) {
|
||||
for (Object buf : byteBuf) {
|
||||
writePacketSilently(channel, buf);
|
||||
}
|
||||
}
|
||||
|
||||
default void receivePacketAsync(Object channel, Object byteBuf) {
|
||||
ChannelHelper.runInEventLoop(channel, () -> {
|
||||
receivePacket(channel, byteBuf);
|
||||
});
|
||||
default void receivePackets(Object channel, Object... byteBuf) {
|
||||
for (Object buf : byteBuf) {
|
||||
receivePacket(channel, buf);
|
||||
}
|
||||
}
|
||||
|
||||
default void receivePacketSilentlyAsync(Object channel, Object byteBuf) {
|
||||
ChannelHelper.runInEventLoop(channel, () -> {
|
||||
receivePacketSilently(channel, byteBuf);
|
||||
});
|
||||
default void receivePacketsSilently(Object channel, Object... byteBuf) {
|
||||
for (Object buf : byteBuf) {
|
||||
receivePacketSilently(channel, buf);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO Make it clear that this only updates the connection state in our user.
|
||||
@@ -110,88 +103,46 @@ public interface ProtocolManager {
|
||||
getUser(channel).setClientVersion(version);
|
||||
}
|
||||
|
||||
default void sendPacket(Object channel, PacketWrapper<?> wrapper) {
|
||||
default Object[] transformWrappers(PacketWrapper<?> wrapper) {
|
||||
//It is possible that our packet transformer util decides to transform one wrapper into multiple packets.
|
||||
//(Correcting some mistakes on your end)
|
||||
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
|
||||
for (PacketWrapper<?> packet : wrappers) {
|
||||
packet.prepareForSend();
|
||||
sendPacket(channel, packet.buffer);
|
||||
Object[] buffers = new Object[wrappers.length];
|
||||
for (int i = 0; i < wrappers.length; i++) {
|
||||
wrappers[i].prepareForSend();
|
||||
buffers[i] = wrappers[i].buffer;
|
||||
}
|
||||
return buffers;
|
||||
}
|
||||
|
||||
default void sendPacketAsync(Object channel, PacketWrapper<?> wrapper) {
|
||||
ChannelHelper.runInEventLoop(channel, () -> {
|
||||
sendPacket(channel, wrapper);
|
||||
});
|
||||
default void sendPacket(Object channel, PacketWrapper<?> wrapper) {
|
||||
Object[] transformed = transformWrappers(wrapper);
|
||||
sendPackets(channel, transformed);
|
||||
}
|
||||
|
||||
default void sendPacketSilently(Object channel, PacketWrapper<?> wrapper) {
|
||||
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
|
||||
for (PacketWrapper<?> packet : wrappers) {
|
||||
packet.prepareForSend();
|
||||
sendPacketSilently(channel, packet.buffer);
|
||||
}
|
||||
}
|
||||
|
||||
default void sendPacketSilentlyAsync(Object channel, PacketWrapper<?> wrapper) {
|
||||
ChannelHelper.runInEventLoop(channel, () -> {
|
||||
sendPacketSilently(channel, wrapper);
|
||||
});
|
||||
Object[] transformed = transformWrappers(wrapper);
|
||||
sendPacketsSilently(channel, transformed);
|
||||
}
|
||||
|
||||
default void writePacket(Object channel, PacketWrapper<?> wrapper) {
|
||||
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
|
||||
for (PacketWrapper<?> packet : wrappers) {
|
||||
packet.prepareForSend();
|
||||
writePacket(channel, packet.buffer);
|
||||
}
|
||||
}
|
||||
|
||||
default void writePacketAsync(Object channel, PacketWrapper<?> wrapper) {
|
||||
ChannelHelper.runInEventLoop(channel, () -> {
|
||||
writePacket(channel, wrapper);
|
||||
});
|
||||
Object[] transformed = transformWrappers(wrapper);
|
||||
writePackets(channel, transformed);
|
||||
}
|
||||
|
||||
default void writePacketSilently(Object channel, PacketWrapper<?> wrapper) {
|
||||
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
|
||||
for (PacketWrapper<?> packet : wrappers) {
|
||||
packet.prepareForSend();
|
||||
writePacketSilently(channel, packet.buffer);
|
||||
}
|
||||
}
|
||||
|
||||
default void writePacketSilentlyAsync(Object channel, PacketWrapper<?> wrapper) {
|
||||
ChannelHelper.runInEventLoop(channel, () -> {
|
||||
writePacketSilently(channel, wrapper);
|
||||
});
|
||||
Object[] transformed = transformWrappers(wrapper);
|
||||
writePacketsSilently(channel, transformed);
|
||||
}
|
||||
|
||||
default void receivePacket(Object channel, PacketWrapper<?> wrapper) {
|
||||
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
|
||||
for (PacketWrapper<?> packet : wrappers) {
|
||||
packet.prepareForSend();
|
||||
receivePacket(channel, packet.buffer);
|
||||
}
|
||||
}
|
||||
|
||||
default void receivePacketAsync(Object channel, PacketWrapper<?> wrapper) {
|
||||
ChannelHelper.runInEventLoop(channel, () -> {
|
||||
receivePacket(channel, wrapper);
|
||||
});
|
||||
Object[] transformed = transformWrappers(wrapper);
|
||||
receivePackets(channel, transformed);
|
||||
}
|
||||
|
||||
default void receivePacketSilently(Object channel, PacketWrapper<?> wrapper) {
|
||||
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
|
||||
for (PacketWrapper<?> packet : wrappers) {
|
||||
packet.prepareForSend();
|
||||
receivePacketSilently(channel, packet.buffer);
|
||||
}
|
||||
}
|
||||
|
||||
default void receivePacketSilentlyAsync(Object channel, PacketWrapper<?> wrapper) {
|
||||
ChannelHelper.runInEventLoop(channel, () -> {
|
||||
receivePacketSilently(channel, wrapper);
|
||||
});
|
||||
Object[] transformed = transformWrappers(wrapper);
|
||||
receivePacketsSilently(channel, transformed);
|
||||
}
|
||||
|
||||
default User getUser(Object channel) {
|
||||
@@ -199,11 +150,13 @@ public interface ProtocolManager {
|
||||
}
|
||||
|
||||
default void setUser(Object channel, User user) {
|
||||
USERS.put(channel, user);
|
||||
synchronized (channel) {
|
||||
USERS.put(channel, user);
|
||||
}
|
||||
PacketEvents.getAPI().getInjector().updateUser(channel, user);
|
||||
}
|
||||
|
||||
default Object getChannel(String username) {
|
||||
return CHANNELS.get(username);
|
||||
default Object getChannel(UUID uuid) {
|
||||
return CHANNELS.get(uuid);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+48
-55
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -19,6 +19,7 @@
|
||||
package com.github.retrooper.packetevents.manager.server;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Server Version.
|
||||
@@ -30,7 +31,7 @@ import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
* @since 1.6.9
|
||||
*/
|
||||
public enum ServerVersion {
|
||||
//TODO Rename to PlatformVersion or LocalVersion or Version?
|
||||
//TODO Rename to MinecraftVersion?
|
||||
V_1_7_10(5),
|
||||
V_1_8(47), V_1_8_3(47), V_1_8_8(47),
|
||||
V_1_9(107), V_1_9_2(109), V_1_9_4(110),
|
||||
@@ -44,6 +45,8 @@ public enum ServerVersion {
|
||||
V_1_16(735), V_1_16_1(736), V_1_16_2(751), V_1_16_3(753), V_1_16_4(754), V_1_16_5(754),
|
||||
V_1_17(755), V_1_17_1(756),
|
||||
V_1_18(757), V_1_18_1(757), V_1_18_2(758),
|
||||
//1.19.1 and 1.19.2 have the same protocol version
|
||||
V_1_19(759), V_1_19_1(760), V_1_19_2(760),
|
||||
//TODO UPDATE Add server version constant
|
||||
ERROR(-1, true);
|
||||
|
||||
@@ -64,6 +67,7 @@ public enum ServerVersion {
|
||||
|
||||
private final int protocolVersion;
|
||||
private final String name;
|
||||
private ClientVersion toClientVersion;
|
||||
|
||||
ServerVersion(int protocolVersion) {
|
||||
this.protocolVersion = protocolVersion;
|
||||
@@ -84,17 +88,17 @@ public enum ServerVersion {
|
||||
}
|
||||
|
||||
public static ServerVersion getLatest() {
|
||||
return reversedValues()[1];
|
||||
return REVERSED_VALUES[1];
|
||||
}
|
||||
|
||||
public static ServerVersion getOldest() {
|
||||
return values()[0];
|
||||
return VALUES[0];
|
||||
}
|
||||
|
||||
//TODO Optimize
|
||||
@Deprecated
|
||||
public static ServerVersion getById(int protocolVersion) {
|
||||
for (ServerVersion version : values()) {
|
||||
for (ServerVersion version : VALUES) {
|
||||
if (version.protocolVersion == protocolVersion) {
|
||||
return version;
|
||||
}
|
||||
@@ -103,12 +107,16 @@ public enum ServerVersion {
|
||||
}
|
||||
|
||||
public ClientVersion toClientVersion() {
|
||||
return ClientVersion.getById(this.protocolVersion);
|
||||
if (toClientVersion == null) {
|
||||
toClientVersion = ClientVersion.getById(protocolVersion);
|
||||
}
|
||||
return toClientVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the release name of this server version.
|
||||
* For example, for the V_1_18 enum constant, it would return "1.18".
|
||||
*
|
||||
* @return Release name
|
||||
*/
|
||||
public String getReleaseName() {
|
||||
@@ -133,31 +141,7 @@ public enum ServerVersion {
|
||||
* @return Is this server version newer than the compared server version.
|
||||
*/
|
||||
public boolean isNewerThan(ServerVersion target) {
|
||||
/*
|
||||
* Some server versions have the same protocol version in the minecraft protocol.
|
||||
* We still need this method to work in such cases.
|
||||
* We first check if this is the case, if the protocol versions aren't the same, we can just use the protocol versions
|
||||
* to compare the server versions.
|
||||
*/
|
||||
if (target.protocolVersion != protocolVersion || this == target) {
|
||||
return protocolVersion > target.protocolVersion;
|
||||
}
|
||||
|
||||
/*
|
||||
* The server versions unfortunately have the same protocol version.
|
||||
* We need to look at this "reversedValues" variable.
|
||||
* The reversed values variable is an array containing all enum constants in this enum but in a reversed order.
|
||||
* I already made this variable a while ago for a different usage, you can check that out.
|
||||
* The first one we find in the array is the newer version.
|
||||
*/
|
||||
for (ServerVersion version : reversedValues()) {
|
||||
if (version == target) {
|
||||
return false;
|
||||
}
|
||||
if (version == this) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return this.ordinal() > target.ordinal();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,28 +153,7 @@ public enum ServerVersion {
|
||||
* @return Is this server version older than the compared server version.
|
||||
*/
|
||||
public boolean isOlderThan(ServerVersion target) {
|
||||
/*
|
||||
* Some server versions have the same protocol version in the minecraft protocol.
|
||||
* We still need this method to work in such cases.
|
||||
* We first check if this is the case, if the protocol versions aren't the same, we can just use the protocol versions
|
||||
* to compare the server versions.
|
||||
*/
|
||||
if (target.protocolVersion != protocolVersion || this == target) {
|
||||
return protocolVersion < target.protocolVersion;
|
||||
}
|
||||
/*
|
||||
* The server versions unfortunately have the same protocol version.
|
||||
* We look at all enum constants in the ServerVersion enum in the order they have been defined in.
|
||||
* The first one we find in the array is the newer version.
|
||||
*/
|
||||
for (ServerVersion version : VALUES) {
|
||||
if (version == this) {
|
||||
return true;
|
||||
} else if (version == target) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return this.ordinal() < target.ordinal();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,7 +165,7 @@ public enum ServerVersion {
|
||||
* @return Is this server version newer than or equal to the compared server version.
|
||||
*/
|
||||
public boolean isNewerThanOrEquals(ServerVersion target) {
|
||||
return this == target || isNewerThan(target);
|
||||
return this.ordinal() >= target.ordinal();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -214,6 +177,36 @@ public enum ServerVersion {
|
||||
* @return Is this server version older than or equal to the compared server version.
|
||||
*/
|
||||
public boolean isOlderThanOrEquals(ServerVersion target) {
|
||||
return this == target || isOlderThan(target);
|
||||
return this.ordinal() <= target.ordinal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this server version newer than, older than or equal to the compared server version?
|
||||
* This method simply checks if this server version's protocol version is greater than, less than or equal to
|
||||
* the compared server version's protocol version.
|
||||
*
|
||||
* @param comparison Comparison type.
|
||||
* @param targetVersion Compared server version.
|
||||
* @return true or false, based on the comparison type.
|
||||
* @see #isNewerThan(ServerVersion)
|
||||
* @see #isNewerThanOrEquals(ServerVersion)
|
||||
* @see #isOlderThan(ServerVersion)
|
||||
* @see #isOlderThanOrEquals(ServerVersion)
|
||||
*/
|
||||
public boolean is(@NotNull VersionComparison comparison, @NotNull ServerVersion targetVersion) {
|
||||
switch (comparison) {
|
||||
case EQUALS:
|
||||
return protocolVersion == targetVersion.protocolVersion;
|
||||
case NEWER_THAN:
|
||||
return isNewerThan(targetVersion);
|
||||
case NEWER_THAN_OR_EQUALS:
|
||||
return isNewerThanOrEquals(targetVersion);
|
||||
case OLDER_THAN:
|
||||
return isOlderThan(targetVersion);
|
||||
case OLDER_THAN_OR_EQUALS:
|
||||
return isOlderThanOrEquals(targetVersion);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.manager.server;
|
||||
|
||||
/**
|
||||
* This enum contains all possible comparison types for server versions.
|
||||
*/
|
||||
public enum VersionComparison {
|
||||
/*
|
||||
The server version equals the compared server version.
|
||||
*/
|
||||
EQUALS,
|
||||
/*
|
||||
The server version is newer than the compared server version.
|
||||
*/
|
||||
NEWER_THAN,
|
||||
/*
|
||||
The server version is newer than or equal to the compared server version.
|
||||
*/
|
||||
NEWER_THAN_OR_EQUALS,
|
||||
/*
|
||||
The server version is older than the compared server version.
|
||||
*/
|
||||
OLDER_THAN,
|
||||
/*
|
||||
The server version is older than or equal to the compared server version.
|
||||
*/
|
||||
OLDER_THAN_OR_EQUALS;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -23,6 +23,14 @@ import com.github.retrooper.packetevents.PacketEvents;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public class ByteBufHelper {
|
||||
public static int capacity(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().capacity(buffer);
|
||||
}
|
||||
|
||||
public static Object capacity(Object buffer, int capacity) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().capacity(buffer, capacity);
|
||||
}
|
||||
|
||||
public static int readerIndex(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readerIndex(buffer);
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+3
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -21,6 +21,8 @@ package com.github.retrooper.packetevents.netty.buffer;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public interface ByteBufOperator {
|
||||
int capacity(Object buffer);
|
||||
Object capacity(Object buffer, int capacity);
|
||||
int readerIndex(Object buffer);
|
||||
Object readerIndex(Object buffer, int readerIndex);
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -26,6 +26,9 @@ public enum ConnectionState {
|
||||
HANDSHAKING, STATUS, LOGIN, PLAY;
|
||||
|
||||
public static ConnectionState getById(int id) {
|
||||
if (id >= values().length || id < 0) {
|
||||
return null;
|
||||
}
|
||||
return values()[id];
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
public enum ChatCompletionAction {
|
||||
ADD,
|
||||
REMOVE,
|
||||
SET;
|
||||
|
||||
private static final ChatCompletionAction[] VALUES = values();
|
||||
|
||||
public static ChatCompletionAction fromId(int id) {
|
||||
return VALUES[id];
|
||||
}
|
||||
}
|
||||
+4
-12
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -18,16 +18,8 @@
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
public enum ChatPosition {
|
||||
CHAT,
|
||||
SYSTEM,
|
||||
GAME_INFO;
|
||||
|
||||
public int getId() {
|
||||
return ordinal();
|
||||
}
|
||||
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
|
||||
|
||||
public interface ChatType extends MappedEntity {
|
||||
|
||||
public static ChatPosition getById(int id) {
|
||||
return values()[id];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.TypesBuilder;
|
||||
import com.github.retrooper.packetevents.util.TypesBuilderData;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChatTypes {
|
||||
private static final Map<String, ChatType> CHAT_TYPE_MAP = new HashMap<>();
|
||||
//Key - mappings version, value - map with chat type ids and chat types
|
||||
private static final Map<Byte, Map<Integer, ChatType>> CHAT_TYPE_ID_MAP = new HashMap<>();
|
||||
private static final TypesBuilder TYPES_BUILDER = new TypesBuilder("chat/chat_type_mappings",
|
||||
ClientVersion.V_1_18_2,
|
||||
ClientVersion.V_1_19,
|
||||
ClientVersion.V_1_19_1);
|
||||
|
||||
static {
|
||||
TYPES_BUILDER.unloadFileMappings();
|
||||
}
|
||||
|
||||
public static ChatType define(String key) {
|
||||
TypesBuilderData data = TYPES_BUILDER.define(key);
|
||||
ChatType chatType = new ChatType() {
|
||||
private final int[] ids = data.getData();
|
||||
|
||||
@Override
|
||||
public ResourceLocation getName() {
|
||||
return data.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId(ClientVersion version) {
|
||||
int index = TYPES_BUILDER.getDataIndex(version);
|
||||
return ids[index];
|
||||
}
|
||||
};
|
||||
CHAT_TYPE_MAP.put(chatType.getName().toString(), chatType);
|
||||
for (ClientVersion version : TYPES_BUILDER.getVersions()) {
|
||||
int index = TYPES_BUILDER.getDataIndex(version);
|
||||
Map<Integer, ChatType> typeIdMap = CHAT_TYPE_ID_MAP.computeIfAbsent((byte) index, k -> new HashMap<>());
|
||||
typeIdMap.put(chatType.getId(version), chatType);
|
||||
}
|
||||
return chatType;
|
||||
}
|
||||
|
||||
//with minecraft:key
|
||||
public static ChatType getByName(String name) {
|
||||
return CHAT_TYPE_MAP.get(name);
|
||||
}
|
||||
|
||||
public static ChatType getById(ClientVersion version, int id) {
|
||||
int index = TYPES_BUILDER.getDataIndex(version);
|
||||
return CHAT_TYPE_ID_MAP.get((byte) index).get(id);
|
||||
}
|
||||
|
||||
public static final ChatType CHAT = define("chat");
|
||||
public static final ChatType SAY_COMMAND = define("say_command");
|
||||
public static final ChatType MSG_COMMAND_INCOMING = define("msg_command_incoming");
|
||||
public static final ChatType MSG_COMMAND_OUTGOING = define("msg_command_outgoing");
|
||||
public static final ChatType TEAM_MSG_COMMAND_INCOMING = define("team_msg_command_incoming");
|
||||
public static final ChatType TEAM_MSG_COMMAND_OUTGOING = define("team_msg_command_outgoing");
|
||||
public static final ChatType EMOTE_COMMAND = define("emote_command");
|
||||
public static final ChatType RAW = define("raw");
|
||||
|
||||
@Deprecated
|
||||
public static final ChatType SYSTEM = define("system");
|
||||
@Deprecated
|
||||
public static final ChatType GAME_INFO = define("game_info");
|
||||
@Deprecated
|
||||
public static final ChatType MSG_COMMAND = define("msg_command");
|
||||
@Deprecated
|
||||
public static final ChatType TEAM_MSG_COMMAND = define("team_msg_command");
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LastSeenMessages {
|
||||
public static final LastSeenMessages EMPTY = new LastSeenMessages(new ArrayList<>());
|
||||
|
||||
private final List<Entry> entries;
|
||||
|
||||
public LastSeenMessages(List<Entry> entries) {
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
public void updateHash(DataOutput output) throws IOException {
|
||||
for (Entry entry : this.entries) {
|
||||
UUID uuid = entry.getUUID();
|
||||
byte[] lastVerifier = entry.getLastVerifier();
|
||||
output.writeByte(70);
|
||||
output.writeLong(uuid.getMostSignificantBits());
|
||||
output.writeLong(uuid.getLeastSignificantBits());
|
||||
output.write(lastVerifier);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Entry> getEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
public static class Entry {
|
||||
private final UUID uuid;
|
||||
private final byte[] signature;
|
||||
|
||||
public Entry(UUID uuid, byte[] lastVerifier) {
|
||||
this.uuid = uuid;
|
||||
this.signature = lastVerifier;
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public byte[] getLastVerifier() {
|
||||
return signature;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Update {
|
||||
private final LastSeenMessages lastSeenMessages;
|
||||
private final @Nullable Entry lastReceived;
|
||||
|
||||
public Update(LastSeenMessages lastSeenMessages, @Nullable Entry lastReceived) {
|
||||
this.lastSeenMessages = lastSeenMessages;
|
||||
this.lastReceived = lastReceived;
|
||||
}
|
||||
|
||||
public LastSeenMessages getLastSeenMessages() {
|
||||
return lastSeenMessages;
|
||||
}
|
||||
|
||||
public @Nullable Entry getLastReceived() {
|
||||
return lastReceived;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class MessageSender {
|
||||
private @NotNull UUID uuid;
|
||||
private @Nullable Component displayName;
|
||||
private @Nullable Component teamName;
|
||||
|
||||
public MessageSender(@NotNull UUID uuid, @Nullable Component displayName, @Nullable Component teamName) {
|
||||
this.uuid = uuid;
|
||||
this.displayName = displayName;
|
||||
this.teamName = teamName;
|
||||
}
|
||||
|
||||
public MessageSender(@Nullable Component displayName, @Nullable Component teamName) {
|
||||
this(new UUID(0L, 0L), displayName, teamName);
|
||||
}
|
||||
|
||||
public MessageSender() {
|
||||
this(null, null);
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUUID(@NotNull UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public @Nullable Component getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public void setDisplayName(@Nullable Component displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public @Nullable Component getTeamName() {
|
||||
return teamName;
|
||||
}
|
||||
|
||||
public void setTeamName(@Nullable Component teamName) {
|
||||
this.teamName = teamName;
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat.filter;
|
||||
|
||||
import java.util.BitSet;
|
||||
|
||||
public class FilterMask {
|
||||
public static final FilterMask FULLY_FILTERED;
|
||||
public static final FilterMask PASS_THROUGH;
|
||||
|
||||
static {
|
||||
FULLY_FILTERED = new FilterMask(new BitSet(0), FilterMaskType.FULLY_FILTERED);
|
||||
PASS_THROUGH = new FilterMask(new BitSet(0), FilterMaskType.PASS_THROUGH);
|
||||
}
|
||||
|
||||
private final BitSet mask;
|
||||
private final FilterMaskType type;
|
||||
|
||||
private FilterMask(BitSet mask, FilterMaskType type) {
|
||||
this.type = type;
|
||||
this.mask = mask;
|
||||
}
|
||||
|
||||
public FilterMask(BitSet mask) {
|
||||
this.type = FilterMaskType.PARTIALLY_FILTERED;
|
||||
this.mask = mask;
|
||||
}
|
||||
|
||||
public BitSet getMask() {
|
||||
return mask;
|
||||
}
|
||||
|
||||
public FilterMaskType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
+13
-11
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -16,18 +16,20 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.util.google;
|
||||
package com.github.retrooper.packetevents.protocol.chat.filter;
|
||||
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
public enum FilterMaskType {
|
||||
PASS_THROUGH,
|
||||
FULLY_FILTERED,
|
||||
PARTIALLY_FILTERED;
|
||||
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
public static final FilterMaskType[] VALUES = values();
|
||||
|
||||
public class GuavaUtil {
|
||||
public static <T, K> ConcurrentMap<T, K> makeMap(ServerVersion serverVersion) {
|
||||
if (serverVersion.isNewerThan(ServerVersion.V_1_7_10)) {
|
||||
return GuavaUtils_8.makeMap();
|
||||
} else {
|
||||
return GuavaUtils_7.makeMap();
|
||||
}
|
||||
public int getId() {
|
||||
return ordinal();
|
||||
}
|
||||
|
||||
public static FilterMaskType getById(int id) {
|
||||
return VALUES[id];
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat.message;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.chat.ChatType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class ChatMessage {
|
||||
private Component chatContent;
|
||||
private ChatType type;
|
||||
|
||||
protected ChatMessage(Component chatContent, ChatType type) {
|
||||
this.chatContent = chatContent;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Component getChatContent() {
|
||||
return chatContent;
|
||||
}
|
||||
|
||||
public ChatType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setChatContent(Component chatContent) {
|
||||
this.chatContent = chatContent;
|
||||
}
|
||||
|
||||
public void setType(ChatType type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat.message;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.chat.ChatType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class ChatMessageLegacy extends ChatMessage {
|
||||
public ChatMessageLegacy(Component chatContent, ChatType type) {
|
||||
super(chatContent, type);
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat.message;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.chat.ChatType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatMessage_v1_16 extends ChatMessage {
|
||||
private UUID senderUUID;
|
||||
|
||||
public ChatMessage_v1_16(Component chatContent, ChatType type, UUID senderUUID) {
|
||||
super(chatContent, type);
|
||||
this.senderUUID = senderUUID;
|
||||
}
|
||||
|
||||
public UUID getSenderUUID() {
|
||||
return senderUUID;
|
||||
}
|
||||
|
||||
public void setSenderUUID(UUID senderUUID) {
|
||||
this.senderUUID = senderUUID;
|
||||
}
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat.message;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.chat.ChatType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatMessage_v1_19 extends ChatMessage {
|
||||
private @Nullable Component unsignedChatContent;
|
||||
private UUID senderUUID;
|
||||
private Component senderDisplayName;
|
||||
private @Nullable Component teamName;
|
||||
private Instant timestamp;
|
||||
private long salt;
|
||||
private byte[] signature;
|
||||
|
||||
public ChatMessage_v1_19(Component chatContent, @Nullable Component unsignedChatContent, ChatType type,
|
||||
UUID senderUUID, Component senderDisplayName, @Nullable Component teamName, Instant timestamp,
|
||||
long salt, byte[] signature) {
|
||||
super(chatContent, type);
|
||||
this.unsignedChatContent = unsignedChatContent;
|
||||
this.senderUUID = senderUUID;
|
||||
this.senderDisplayName = senderDisplayName;
|
||||
this.teamName = teamName;
|
||||
this.timestamp = timestamp;
|
||||
this.salt = salt;
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public @Nullable Component getUnsignedChatContent() {
|
||||
return unsignedChatContent;
|
||||
}
|
||||
|
||||
public UUID getSenderUUID() {
|
||||
return senderUUID;
|
||||
}
|
||||
|
||||
public Component getSenderDisplayName() {
|
||||
return senderDisplayName;
|
||||
}
|
||||
|
||||
public @Nullable Component getTeamName() {
|
||||
return teamName;
|
||||
}
|
||||
|
||||
public Instant getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public long getSalt() {
|
||||
return salt;
|
||||
}
|
||||
|
||||
public byte[] getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public void setUnsignedChatContent(@Nullable Component unsignedChatContent) {
|
||||
this.unsignedChatContent = unsignedChatContent;
|
||||
}
|
||||
|
||||
public void setSenderUUID(UUID senderUUID) {
|
||||
this.senderUUID = senderUUID;
|
||||
}
|
||||
|
||||
public void setSenderDisplayName(Component senderDisplayName) {
|
||||
this.senderDisplayName = senderDisplayName;
|
||||
}
|
||||
|
||||
public void setTeamName(@Nullable Component teamName) {
|
||||
this.teamName = teamName;
|
||||
}
|
||||
|
||||
public void setTimestamp(Instant timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public void setSalt(long salt) {
|
||||
this.salt = salt;
|
||||
}
|
||||
|
||||
public void setSignature(byte[] signature) {
|
||||
this.signature = signature;
|
||||
}
|
||||
}
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat.message;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.chat.ChatType;
|
||||
import com.github.retrooper.packetevents.protocol.chat.LastSeenMessages;
|
||||
import com.github.retrooper.packetevents.protocol.chat.filter.FilterMask;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatMessage_v1_19_1 extends ChatMessage {
|
||||
private String plainContent;
|
||||
private @Nullable Component unsignedChatContent;
|
||||
private UUID senderUUID;
|
||||
private ChatTypeBoundNetwork chatType;
|
||||
private byte @Nullable [] previousSignature;
|
||||
private byte[] signature;
|
||||
private Instant timestamp;
|
||||
private long salt;
|
||||
private LastSeenMessages lastSeenMessages;
|
||||
private FilterMask filterMask;
|
||||
|
||||
public ChatMessage_v1_19_1(String plainContent, Component decoratedChatContent,
|
||||
@Nullable Component unsignedChatContent,
|
||||
UUID senderUUID, ChatTypeBoundNetwork chatType,
|
||||
byte @Nullable [] previousSignature, byte[] signature,
|
||||
Instant timestamp, long salt,
|
||||
LastSeenMessages lastSeenMessages,
|
||||
FilterMask filterMask) {
|
||||
super(decoratedChatContent, chatType.getType());
|
||||
this.plainContent = plainContent;
|
||||
this.unsignedChatContent = unsignedChatContent;
|
||||
this.senderUUID = senderUUID;
|
||||
this.chatType = chatType;
|
||||
this.previousSignature = previousSignature;
|
||||
this.signature = signature;
|
||||
this.timestamp = timestamp;
|
||||
this.salt = salt;
|
||||
this.lastSeenMessages = lastSeenMessages;
|
||||
this.filterMask = filterMask;
|
||||
}
|
||||
|
||||
public String getPlainContent() {
|
||||
return plainContent;
|
||||
}
|
||||
|
||||
public void setPlainContent(String plainContent) {
|
||||
this.plainContent = plainContent;
|
||||
}
|
||||
|
||||
public boolean isChatContentDecorated() {
|
||||
return !getChatContent().equals(Component.text(plainContent));
|
||||
}
|
||||
|
||||
public @Nullable Component getUnsignedChatContent() {
|
||||
return unsignedChatContent;
|
||||
}
|
||||
|
||||
public void setUnsignedChatContent(@Nullable Component unsignedChatContent) {
|
||||
this.unsignedChatContent = unsignedChatContent;
|
||||
}
|
||||
|
||||
public UUID getSenderUUID() {
|
||||
return senderUUID;
|
||||
}
|
||||
|
||||
public void setSenderUUID(UUID senderUUID) {
|
||||
this.senderUUID = senderUUID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatType getType() {
|
||||
return chatType.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setType(ChatType type) {
|
||||
chatType.setType(type);
|
||||
}
|
||||
|
||||
public ChatTypeBoundNetwork getChatType() {
|
||||
return chatType;
|
||||
}
|
||||
|
||||
public void setChatType(ChatTypeBoundNetwork type) {
|
||||
this.chatType = type;
|
||||
}
|
||||
|
||||
public byte @Nullable [] getPreviousSignature() {
|
||||
return previousSignature;
|
||||
}
|
||||
|
||||
public void setPreviousSignature(byte @Nullable [] previousSignature) {
|
||||
this.previousSignature = previousSignature;
|
||||
}
|
||||
|
||||
public byte[] getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public void setSignature(byte[] signature) {
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public Instant getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(Instant timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public long getSalt() {
|
||||
return salt;
|
||||
}
|
||||
|
||||
public void setSalt(long salt) {
|
||||
this.salt = salt;
|
||||
}
|
||||
|
||||
public LastSeenMessages getLastSeenMessages() {
|
||||
return lastSeenMessages;
|
||||
}
|
||||
|
||||
public void setLastSeenMessages(LastSeenMessages lastSeenMessages) {
|
||||
this.lastSeenMessages = lastSeenMessages;
|
||||
}
|
||||
|
||||
public FilterMask getFilterMask() {
|
||||
return filterMask;
|
||||
}
|
||||
|
||||
public void setFilterMask(FilterMask filterMask) {
|
||||
this.filterMask = filterMask;
|
||||
}
|
||||
|
||||
public static class ChatTypeBoundNetwork {
|
||||
private ChatType type;
|
||||
private Component name;
|
||||
private @Nullable Component targetName;
|
||||
|
||||
public ChatTypeBoundNetwork(ChatType type, Component name, @Nullable Component targetName) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.targetName = targetName;
|
||||
}
|
||||
|
||||
public ChatType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(ChatType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Component getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(Component name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public @Nullable Component getTargetName() {
|
||||
return targetName;
|
||||
}
|
||||
|
||||
public void setTargetName(@Nullable Component targetName) {
|
||||
this.targetName = targetName;
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat.message.reader;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface ChatMessageProcessor {
|
||||
ChatMessage readChatMessage(@NotNull PacketWrapper<?> wrapper);
|
||||
|
||||
void writeChatMessage(@NotNull PacketWrapper<?> wrapper, @NotNull ChatMessage data);
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat.message.reader.impl;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.chat.ChatType;
|
||||
import com.github.retrooper.packetevents.protocol.chat.ChatTypes;
|
||||
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage;
|
||||
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessageLegacy;
|
||||
import com.github.retrooper.packetevents.protocol.chat.message.reader.ChatMessageProcessor;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ChatMessageProcessorLegacy implements ChatMessageProcessor {
|
||||
@Override
|
||||
public ChatMessage readChatMessage(@NotNull PacketWrapper<?> wrapper) {
|
||||
Component chatContent = wrapper.readComponent();
|
||||
int id = wrapper.readByte();
|
||||
ChatType type = ChatTypes.getById(wrapper.getServerVersion().toClientVersion(), id);
|
||||
return new ChatMessageLegacy(chatContent, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeChatMessage(@NotNull PacketWrapper<?> wrapper, @NotNull ChatMessage data) {
|
||||
wrapper.writeComponent(data.getChatContent());
|
||||
wrapper.writeByte(data.getType().getId(wrapper.getServerVersion().toClientVersion()));
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat.message.reader.impl;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.chat.ChatType;
|
||||
import com.github.retrooper.packetevents.protocol.chat.ChatTypes;
|
||||
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage;
|
||||
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage_v1_16;
|
||||
import com.github.retrooper.packetevents.protocol.chat.message.reader.ChatMessageProcessor;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatMessageProcessor_v1_16 implements ChatMessageProcessor {
|
||||
@Override
|
||||
public ChatMessage readChatMessage(@NotNull PacketWrapper<?> wrapper) {
|
||||
Component chatContent = wrapper.readComponent();
|
||||
int id = wrapper.readByte();
|
||||
ChatType type = ChatTypes.getById(wrapper.getServerVersion().toClientVersion(), id);
|
||||
UUID senderUUID = wrapper.readUUID();
|
||||
return new ChatMessage_v1_16(chatContent, type, senderUUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeChatMessage(@NotNull PacketWrapper<?> wrapper, @NotNull ChatMessage data) {
|
||||
wrapper.writeComponent(data.getChatContent());
|
||||
wrapper.writeByte(data.getType().getId(wrapper.getServerVersion().toClientVersion()));
|
||||
wrapper.writeUUID(((ChatMessage_v1_16) data).getSenderUUID());
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat.message.reader.impl;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.chat.ChatType;
|
||||
import com.github.retrooper.packetevents.protocol.chat.ChatTypes;
|
||||
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage;
|
||||
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage_v1_19;
|
||||
import com.github.retrooper.packetevents.protocol.chat.message.reader.ChatMessageProcessor;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatMessageProcessor_v1_19 implements ChatMessageProcessor {
|
||||
@Override
|
||||
public ChatMessage readChatMessage(@NotNull PacketWrapper<?> wrapper) {
|
||||
Component chatContent = wrapper.readComponent();
|
||||
Component unsignedChatContent = wrapper.readOptional(PacketWrapper::readComponent);
|
||||
int id = wrapper.readVarInt();
|
||||
ChatType type = ChatTypes.getById(wrapper.getServerVersion().toClientVersion(), id);
|
||||
UUID senderUUID = wrapper.readUUID();
|
||||
Component senderDisplayName = wrapper.readComponent();
|
||||
@Nullable Component teamName = wrapper.readOptional(PacketWrapper::readComponent);
|
||||
Instant timestamp = wrapper.readTimestamp();
|
||||
long salt = wrapper.readLong();
|
||||
byte[] signature = wrapper.readByteArray();
|
||||
return new ChatMessage_v1_19(chatContent, unsignedChatContent, type, senderUUID, senderDisplayName, teamName,
|
||||
timestamp, salt, signature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeChatMessage(@NotNull PacketWrapper<?> wrapper, @NotNull ChatMessage data) {
|
||||
ChatMessage_v1_19 newData = (ChatMessage_v1_19) data;
|
||||
wrapper.writeComponent(newData.getChatContent());
|
||||
wrapper.writeOptional(newData.getUnsignedChatContent(), PacketWrapper::writeComponent);
|
||||
wrapper.writeVarInt(newData.getType().getId(wrapper.getServerVersion().toClientVersion()));
|
||||
wrapper.writeUUID(newData.getSenderUUID());
|
||||
wrapper.writeComponent(newData.getSenderDisplayName());
|
||||
wrapper.writeOptional(newData.getTeamName(), PacketWrapper::writeComponent);
|
||||
wrapper.writeTimestamp(newData.getTimestamp());
|
||||
wrapper.writeLong(newData.getSalt());
|
||||
wrapper.writeByteArray(newData.getSignature());
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat.message.reader.impl;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.chat.ChatType;
|
||||
import com.github.retrooper.packetevents.protocol.chat.ChatTypes;
|
||||
import com.github.retrooper.packetevents.protocol.chat.LastSeenMessages;
|
||||
import com.github.retrooper.packetevents.protocol.chat.filter.FilterMask;
|
||||
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage;
|
||||
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage_v1_19_1;
|
||||
import com.github.retrooper.packetevents.protocol.chat.message.reader.ChatMessageProcessor;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatMessageProcessor_v1_19_1 implements ChatMessageProcessor {
|
||||
@Override
|
||||
public ChatMessage readChatMessage(@NotNull PacketWrapper<?> wrapper) {
|
||||
byte[] previousSignature = wrapper.readOptional(PacketWrapper::readByteArray);
|
||||
UUID senderUUID = wrapper.readUUID();
|
||||
byte[] signature = wrapper.readByteArray();
|
||||
String plainContent = wrapper.readString(256);
|
||||
Component chatContent = wrapper.readOptional(PacketWrapper::readComponent);
|
||||
if (chatContent == null) {
|
||||
chatContent = Component.text(plainContent);
|
||||
}
|
||||
Instant timestamp = wrapper.readTimestamp();
|
||||
long salt = wrapper.readLong();
|
||||
LastSeenMessages lastSeenMessages = wrapper.readLastSeenMessages();
|
||||
Component unsignedChatContent = wrapper.readOptional(PacketWrapper::readComponent);
|
||||
FilterMask filterMask = wrapper.readFilterMask();
|
||||
|
||||
int id = wrapper.readVarInt();
|
||||
ChatType type = ChatTypes.getById(wrapper.getServerVersion().toClientVersion(), id);
|
||||
Component name = wrapper.readComponent();
|
||||
Component targetName = wrapper.readOptional(PacketWrapper::readComponent);
|
||||
ChatMessage_v1_19_1.ChatTypeBoundNetwork chatType = new ChatMessage_v1_19_1.ChatTypeBoundNetwork(type, name, targetName);
|
||||
|
||||
return new ChatMessage_v1_19_1(plainContent, chatContent, unsignedChatContent, senderUUID, chatType,
|
||||
previousSignature, signature, timestamp, salt, lastSeenMessages, filterMask);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeChatMessage(@NotNull PacketWrapper<?> wrapper, @NotNull ChatMessage data) {
|
||||
ChatMessage_v1_19_1 newData = (ChatMessage_v1_19_1) data;
|
||||
wrapper.writeOptional(newData.getPreviousSignature(), PacketWrapper::writeByteArray);
|
||||
wrapper.writeUUID(newData.getSenderUUID());
|
||||
wrapper.writeByteArray(newData.getSignature());
|
||||
wrapper.writeString(newData.getPlainContent(), 256);
|
||||
wrapper.writeOptional(newData.getChatContent(), PacketWrapper::writeComponent);
|
||||
wrapper.writeTimestamp(newData.getTimestamp());
|
||||
wrapper.writeLong(newData.getSalt());
|
||||
wrapper.writeLastSeenMessages(newData.getLastSeenMessages());
|
||||
wrapper.writeOptional(newData.getUnsignedChatContent(), PacketWrapper::writeComponent);
|
||||
wrapper.writeFilterMask(newData.getFilterMask());
|
||||
wrapper.writeVarInt(newData.getChatType().getType().getId(wrapper.getServerVersion().toClientVersion()));
|
||||
wrapper.writeComponent(newData.getChatType().getName());
|
||||
wrapper.writeOptional(newData.getChatType().getTargetName(), PacketWrapper::writeComponent);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+98
-58
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -23,16 +23,25 @@ import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose;
|
||||
import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData;
|
||||
import com.github.retrooper.packetevents.protocol.item.ItemStack;
|
||||
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentType;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.particle.Particle;
|
||||
import com.github.retrooper.packetevents.protocol.particle.type.ParticleType;
|
||||
import com.github.retrooper.packetevents.protocol.particle.type.ParticleTypes;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.protocol.world.BlockFace;
|
||||
import com.github.retrooper.packetevents.util.*;
|
||||
import com.github.retrooper.packetevents.protocol.world.WorldBlockPosition;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.TypesBuilder;
|
||||
import com.github.retrooper.packetevents.util.TypesBuilderData;
|
||||
import com.github.retrooper.packetevents.util.Vector3f;
|
||||
import com.github.retrooper.packetevents.util.Vector3i;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -48,19 +57,44 @@ public class EntityDataTypes {
|
||||
ClientVersion.V_1_8,
|
||||
ClientVersion.V_1_9,
|
||||
ClientVersion.V_1_11,
|
||||
ClientVersion.V_1_13, //Fix? Why did we not acknoledge 1.13
|
||||
ClientVersion.V_1_16);
|
||||
ClientVersion.V_1_13,
|
||||
ClientVersion.V_1_14,
|
||||
ClientVersion.V_1_19);
|
||||
|
||||
public static final EntityDataType<Byte> BYTE = define("byte", PacketWrapper::readByte, PacketWrapper::writeByte);
|
||||
public static final EntityDataType<Integer> INT = define("int", readIntDeserializer(), writeIntSerializer());
|
||||
|
||||
public static final EntityDataType<Short> SHORT = define("short", PacketWrapper::readShort, PacketWrapper::writeShort);
|
||||
|
||||
public static final EntityDataType<Integer> INT = define("int", wrapper -> {
|
||||
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
|
||||
return wrapper.readVarInt();
|
||||
} else {
|
||||
return wrapper.readInt();
|
||||
}
|
||||
}, (wrapper, value) -> {
|
||||
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
|
||||
wrapper.writeVarInt(value);
|
||||
} else {
|
||||
wrapper.writeInt(value);
|
||||
}
|
||||
});
|
||||
|
||||
public static final EntityDataType<Float> FLOAT = define("float", PacketWrapper::readFloat, PacketWrapper::writeFloat);
|
||||
|
||||
public static final EntityDataType<String> STRING = define("string", PacketWrapper::readString, PacketWrapper::writeString);
|
||||
|
||||
public static final EntityDataType<Component> COMPONENT = define("component", PacketWrapper::readComponent, PacketWrapper::writeComponent);
|
||||
|
||||
public static final EntityDataType<Optional<Component>> OPTIONAL_COMPONENT = define("optional_component", readOptionalComponentDeserializer(), writeOptionalComponentSerializer());
|
||||
|
||||
public static final EntityDataType<ItemStack> ITEMSTACK = define("itemstack", PacketWrapper::readItemStack, PacketWrapper::writeItemStack);
|
||||
public static final EntityDataType<Optional<Object>> OPTIONAL_BLOCK_STATE = define("optional_block_state", readIntDeserializer(), writeIntSerializer());
|
||||
|
||||
public static final EntityDataType<Optional<ItemStack>> OPTIONAL_ITEMSTACK = define("optional_itemstack",
|
||||
(PacketWrapper<?> wrapper) -> Optional.of(wrapper.readItemStack()),
|
||||
(PacketWrapper<?> wrapper, Optional<ItemStack> value) -> wrapper.writeItemStack(value.orElse(null)));
|
||||
|
||||
public static final EntityDataType<Boolean> BOOLEAN = define("boolean", PacketWrapper::readBoolean, PacketWrapper::writeBoolean);
|
||||
public static final EntityDataType<Integer> PARTICLE = define("particle", PacketWrapper::readVarInt, PacketWrapper::writeVarInt);
|
||||
|
||||
public static final EntityDataType<Vector3f> ROTATION = define("rotation",
|
||||
(PacketWrapper<?> wrapper) -> new Vector3f(wrapper.readFloat(), wrapper.readFloat(), wrapper.readFloat()),
|
||||
(PacketWrapper<?> wrapper, Vector3f value) -> {
|
||||
@@ -68,32 +102,55 @@ public class EntityDataTypes {
|
||||
wrapper.writeFloat(value.y);
|
||||
wrapper.writeFloat(value.z);
|
||||
});
|
||||
public static final EntityDataType<Vector3i> BLOCK_POSITION = define("block_position", readBlockPositionDeserializer(), writeBlockPositionSerializer());
|
||||
public static final EntityDataType<Optional<Vector3i>> OPTIONAL_BLOCK_POSITION = define("optional_block_position", readOptionalBlockPositionDeserializer(), writeOptionalBlockPositionSerializer());
|
||||
|
||||
public static final EntityDataType<Vector3i> BLOCK_POSITION = define("block_position", (PacketWrapper<?> wrapper) -> {
|
||||
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
|
||||
return wrapper.readBlockPosition();
|
||||
} else {
|
||||
int x = wrapper.readInt();
|
||||
int y = wrapper.readInt();
|
||||
int z = wrapper.readInt();
|
||||
return new Vector3i(x, y, z);
|
||||
}
|
||||
}, (wrapper, blockPosition) -> {
|
||||
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
|
||||
wrapper.writeBlockPosition(blockPosition);
|
||||
} else {
|
||||
wrapper.writeInt(blockPosition.getX());
|
||||
wrapper.writeInt(blockPosition.getY());
|
||||
wrapper.writeInt(blockPosition.getZ());
|
||||
}
|
||||
});
|
||||
|
||||
public static final EntityDataType<Optional<Vector3i>> OPTIONAL_BLOCK_POSITION = define("optional_block_position",
|
||||
readOptionalBlockPositionDeserializer(), writeOptionalBlockPositionSerializer());
|
||||
|
||||
public static final EntityDataType<BlockFace> BLOCK_FACE = define("block_face", (PacketWrapper<?> wrapper) -> {
|
||||
int id = wrapper.readVarInt();
|
||||
return BlockFace.getBlockFaceByValue(id);
|
||||
},
|
||||
(PacketWrapper<?> wrapper, BlockFace value) -> wrapper.writeVarInt(value.getFaceValue()));
|
||||
|
||||
public static final EntityDataType<Optional<UUID>> OPTIONAL_UUID = define("optional_uuid", (PacketWrapper<?> wrapper) -> {
|
||||
if (wrapper.readBoolean()) {
|
||||
return Optional.of(wrapper.readUUID());
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
},
|
||||
(PacketWrapper<?> wrapper, Optional<UUID> value) -> {
|
||||
if (value.isPresent()) {
|
||||
wrapper.writeBoolean(true);
|
||||
wrapper.writeUUID(value.get());
|
||||
} else {
|
||||
wrapper.writeBoolean(false);
|
||||
}
|
||||
});
|
||||
public static final EntityDataType<Optional<UUID>> OPTIONAL_UUID = define("optional_uuid",
|
||||
(PacketWrapper<?> wrapper) -> Optional.ofNullable(wrapper.readOptional(PacketWrapper::readUUID)),
|
||||
(PacketWrapper<?> wrapper, Optional<UUID> value) ->
|
||||
wrapper.writeOptional(value.orElse(null), PacketWrapper::writeUUID));
|
||||
|
||||
public static final EntityDataType<Integer> OPTIONAL_BLOCK_STATE = define("optional_block_state", readIntDeserializer(), writeIntSerializer());
|
||||
|
||||
public static final EntityDataType<NBTCompound> NBT = define("nbt", PacketWrapper::readNBT, PacketWrapper::writeNBT);
|
||||
|
||||
public static final EntityDataType<Particle> PARTICLE = define("particle", wrapper -> {
|
||||
int id = wrapper.readVarInt();
|
||||
ParticleType type = ParticleTypes.getById(PacketEvents.getAPI().getServerManager().getVersion().toClientVersion(), id);
|
||||
return new Particle(type, type.readDataFunction().apply(wrapper));
|
||||
}, (wrapper, particle) -> {
|
||||
wrapper.writeVarInt(particle.getType().getId(PacketEvents.getAPI().getServerManager().getVersion().toClientVersion()));
|
||||
particle.getType().writeDataFunction().accept(wrapper, particle.getData());
|
||||
});
|
||||
|
||||
public static final EntityDataType<VillagerData> VILLAGER_DATA = define("villager_data", PacketWrapper::readVillagerData, PacketWrapper::writeVillagerData);
|
||||
|
||||
public static final EntityDataType<Optional<Integer>> OPTIONAL_INT = define("optional_int", (PacketWrapper<?> wrapper) -> {
|
||||
int i = wrapper.readVarInt();
|
||||
return i == 0 ? Optional.empty() : Optional.of(i - 1);
|
||||
@@ -106,12 +163,22 @@ public class EntityDataTypes {
|
||||
return EntityPose.getById(wrapper.getServerVersion().toClientVersion(), id);
|
||||
}, (PacketWrapper<?> wrapper, EntityPose value) -> wrapper.writeVarInt(value.getId(wrapper.getServerVersion().toClientVersion())));
|
||||
|
||||
@Deprecated
|
||||
public static final EntityDataType<Short> SHORT = define("short", PacketWrapper::readShort, PacketWrapper::writeShort);
|
||||
public static final EntityDataType<Integer> CAT_VARIANT = define("cat_variant_type", readIntDeserializer(), writeIntSerializer());
|
||||
|
||||
public static final EntityDataType<Integer> FROG_VARIANT = define("frog_variant_type", readIntDeserializer(), writeIntSerializer());
|
||||
|
||||
public static final EntityDataType<Optional<WorldBlockPosition>> OPTIONAL_GLOBAL_POSITION = define("optional_global_position",
|
||||
(PacketWrapper<?> wrapper) -> Optional.ofNullable(wrapper.readOptional(w -> new WorldBlockPosition(new ResourceLocation(w.readString(32767)), w.readBlockPosition()))),
|
||||
(PacketWrapper<?> wrapper, Optional<WorldBlockPosition> value) -> wrapper.writeOptional(value.orElse(null), (w, globalPos) -> {
|
||||
w.writeString(globalPos.getWorld().toString());
|
||||
w.writeBlockPosition(globalPos.getBlockPosition());
|
||||
}));
|
||||
|
||||
public static final EntityDataType<Integer> PAINTING_VARIANT_TYPE = define("painting_variant_type", readIntDeserializer(), writeIntSerializer());
|
||||
|
||||
public static EntityDataType<?> getById(ClientVersion version, int id) {
|
||||
int index = TYPES_BUILDER.getDataIndex(version);
|
||||
Map<Integer, EntityDataType<?>> typeIdMap = ENTITY_DATA_TYPE_ID_MAP.get((byte)index);
|
||||
Map<Integer, EntityDataType<?>> typeIdMap = ENTITY_DATA_TYPE_ID_MAP.get((byte) index);
|
||||
return typeIdMap.get(id);
|
||||
}
|
||||
|
||||
@@ -188,34 +255,6 @@ public class EntityDataTypes {
|
||||
};
|
||||
}
|
||||
|
||||
private static <T> Function<PacketWrapper<?>, T> readBlockPositionDeserializer() {
|
||||
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
|
||||
return (PacketWrapper<?> wrapper) -> (T) wrapper.readBlockPosition();
|
||||
} else {
|
||||
return (PacketWrapper<?> wrapper) -> {
|
||||
int x = wrapper.readInt();
|
||||
int y = wrapper.readInt();
|
||||
int z = wrapper.readInt();
|
||||
return (T) new Vector3i(x, y, z);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> BiConsumer<PacketWrapper<?>, T> writeBlockPositionSerializer() {
|
||||
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
|
||||
return (PacketWrapper<?> wrapper, T value) -> {
|
||||
wrapper.writeBlockPosition((Vector3i) value);
|
||||
};
|
||||
} else {
|
||||
return (PacketWrapper<?> wrapper, T value) -> {
|
||||
Vector3i position = (Vector3i) value;
|
||||
wrapper.writeInt(position.getX());
|
||||
wrapper.writeInt(position.getY());
|
||||
wrapper.writeInt(position.getZ());
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> Function<PacketWrapper<?>, T> readOptionalBlockPositionDeserializer() {
|
||||
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) {
|
||||
return (PacketWrapper<?> wrapper) -> {
|
||||
@@ -273,4 +312,5 @@ public class EntityDataTypes {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+5
-6
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -25,12 +25,11 @@ import com.github.retrooper.packetevents.protocol.player.HumanoidArm;
|
||||
import com.github.retrooper.packetevents.protocol.player.SkinSection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class PlayerDataProvider extends LivingEntityDataProvider {
|
||||
private float additionalHealth;
|
||||
private int score;
|
||||
private byte skinPartsMask = SkinSection.getMaskBySections(SkinSection.getAllSections());
|
||||
private byte skinPartsMask = SkinSection.ALL.getMask();
|
||||
private HumanoidArm mainArm = HumanoidArm.RIGHT;
|
||||
private NBTCompound leftShoulderNBT = new NBTCompound();
|
||||
private NBTCompound rightShoulderNBT = new NBTCompound();
|
||||
@@ -114,7 +113,7 @@ public class PlayerDataProvider extends LivingEntityDataProvider {
|
||||
skinPartsMask = (byte) entityData.getValue();
|
||||
break;
|
||||
case 18:
|
||||
mainArm = HumanoidArm.values()[(byte) entityData.getValue()];
|
||||
mainArm = HumanoidArm.VALUES[(byte) entityData.getValue()];
|
||||
break;
|
||||
case 19:
|
||||
leftShoulderNBT = (NBTCompound) entityData.getValue();
|
||||
@@ -146,8 +145,8 @@ public class PlayerDataProvider extends LivingEntityDataProvider {
|
||||
return (T)this;
|
||||
}
|
||||
|
||||
public T skinParts(Set<SkinSection> skinSections) {
|
||||
((PlayerDataProvider)provider).setSkinPartsMask(SkinSection.getMaskBySections(skinSections));
|
||||
public T skinParts(SkinSection skinSections) {
|
||||
((PlayerDataProvider)provider).setSkinPartsMask(skinSections.getMask());
|
||||
return (T)this;
|
||||
}
|
||||
|
||||
|
||||
+8
-2
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -28,7 +28,13 @@ public enum EntityPose {
|
||||
SPIN_ATTACK,
|
||||
CROUCHING,
|
||||
LONG_JUMPING,
|
||||
DYING;
|
||||
DYING,
|
||||
CROAKING,
|
||||
USING_TONGUE,
|
||||
ROARING,
|
||||
SNIFFING,
|
||||
EMERGING,
|
||||
DIGGING;
|
||||
|
||||
public int getId(ClientVersion version) {
|
||||
if (this == DYING && version.isOlderThan(ClientVersion.V_1_17)) {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+14
-2
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -42,7 +42,8 @@ public class EntityTypes {
|
||||
ClientVersion.V_1_15,
|
||||
ClientVersion.V_1_16,
|
||||
ClientVersion.V_1_16_2,
|
||||
ClientVersion.V_1_17);
|
||||
ClientVersion.V_1_17,
|
||||
ClientVersion.V_1_19);
|
||||
private static final TypesBuilder LEGACY_TYPES_BUILDER = new TypesBuilder("entity/legacy_entity_type_mappings",
|
||||
ClientVersion.V_1_8,
|
||||
ClientVersion.V_1_9,
|
||||
@@ -51,6 +52,12 @@ public class EntityTypes {
|
||||
ClientVersion.V_1_12,
|
||||
ClientVersion.V_1_13);
|
||||
|
||||
|
||||
static {
|
||||
TYPES_BUILDER.unloadFileMappings();
|
||||
LEGACY_TYPES_BUILDER.unloadFileMappings();
|
||||
}
|
||||
|
||||
public static EntityType define(String key, @Nullable EntityType parent) {
|
||||
TypesBuilderData data = TYPES_BUILDER.define(key);
|
||||
TypesBuilderData legacyData = LEGACY_TYPES_BUILDER.define(key);
|
||||
@@ -162,12 +169,14 @@ public class EntityTypes {
|
||||
public static final EntityType CHESTED_MINECART_ABSTRACT = define("chested_minecart_abstract", MINECART_ABSTRACT);
|
||||
public static final EntityType AREA_EFFECT_CLOUD = define("area_effect_cloud", ENTITY);
|
||||
public static final EntityType ARMOR_STAND = define("armor_stand", LIVINGENTITY);
|
||||
public static final EntityType ALLAY = define("allay", ABSTRACT_CREATURE);
|
||||
public static final EntityType ARROW = define("arrow", ABSTRACT_ARROW);
|
||||
public static final EntityType AXOLOTL = define("axolotl", ABSTRACT_ANIMAL);
|
||||
public static final EntityType BAT = define("bat", ABSTRACT_AMBIENT);
|
||||
public static final EntityType BEE = define("bee", ABSTRACT_INSENTIENT);
|
||||
public static final EntityType BLAZE = define("blaze", ABSTRACT_MONSTER);
|
||||
public static final EntityType BOAT = define("boat", ENTITY);
|
||||
public static final EntityType CHEST_BOAT = define("chest_boat", BOAT);
|
||||
public static final EntityType CAT = define("cat", ABSTRACT_TAMEABLE_ANIMAL);
|
||||
public static final EntityType SPIDER = define("spider", ABSTRACT_MONSTER);
|
||||
public static final EntityType CAVE_SPIDER = define("cave_spider", SPIDER);
|
||||
@@ -193,6 +202,7 @@ public class EntityTypes {
|
||||
public static final EntityType FALLING_BLOCK = define("falling_block", ENTITY);
|
||||
public static final EntityType FIREWORK_ROCKET = define("firework_rocket", ENTITY);
|
||||
public static final EntityType FOX = define("fox", ABSTRACT_ANIMAL);
|
||||
public static final EntityType FROG = define("frog", ABSTRACT_ANIMAL);
|
||||
public static final EntityType GHAST = define("ghast", ABSTRACT_FLYING);
|
||||
public static final EntityType GIANT = define("giant", ABSTRACT_MONSTER);
|
||||
public static final EntityType ITEM_FRAME = define("item_frame", ABSTRACT_HANGING);
|
||||
@@ -254,6 +264,7 @@ public class EntityTypes {
|
||||
public static final EntityType ENDER_PEARL = define("ender_pearl", PROJECTILE_ABSTRACT);
|
||||
public static final EntityType EXPERIENCE_BOTTLE = define("experience_bottle", PROJECTILE_ABSTRACT);
|
||||
public static final EntityType POTION = define("potion", PROJECTILE_ABSTRACT);
|
||||
public static final EntityType TADPOLE = define("tadpole", ABSTRACT_FISHES);
|
||||
@Deprecated // Exists only in 1.9 and 1.10
|
||||
public static final EntityType TIPPED_ARROW = define("tipped_arrow", ARROW);
|
||||
public static final EntityType TRIDENT = define("trident", ABSTRACT_ARROW);
|
||||
@@ -264,6 +275,7 @@ public class EntityTypes {
|
||||
public static final EntityType VILLAGER = define("villager", ABSTRACT_AGEABLE);
|
||||
public static final EntityType VINDICATOR = define("vindicator", ABSTRACT_ILLAGER_BASE);
|
||||
public static final EntityType WANDERING_TRADER = define("wandering_trader", ABSTRACT_AGEABLE);
|
||||
public static final EntityType WARDEN = define("warden", ABSTRACT_MONSTER);
|
||||
public static final EntityType WITCH = define("witch", ABSTRACT_MONSTER);
|
||||
public static final EntityType WITHER = define("wither", ABSTRACT_MONSTER);
|
||||
public static final EntityType WITHER_SKELETON = define("wither_skeleton", ABSTRACT_SKELETON);
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -24,6 +24,7 @@ import com.github.retrooper.packetevents.protocol.item.enchantment.type.Enchantm
|
||||
import com.github.retrooper.packetevents.protocol.item.type.ItemType;
|
||||
import com.github.retrooper.packetevents.protocol.item.type.ItemTypes;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.*;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -60,9 +61,8 @@ public class ItemStack {
|
||||
if (!this.cachedIsEmpty && this.getType().getMaxDurability() > 0) {
|
||||
NBTCompound tag = this.getNBT();
|
||||
return tag == null || !tag.getBoolean("Unbreakable");
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isDamaged() {
|
||||
@@ -145,29 +145,30 @@ public class ItemStack {
|
||||
this.legacyData = legacyData;
|
||||
}
|
||||
|
||||
public boolean isEnchantable() {
|
||||
public boolean isEnchantable(ClientVersion version) {
|
||||
if (getType() == ItemTypes.BOOK) return getAmount() == 1;
|
||||
if (getType() == ItemTypes.ENCHANTED_BOOK) return false;
|
||||
return getMaxStackSize() == 1 && canBeDepleted() && !isEnchanted();
|
||||
return getMaxStackSize() == 1 && canBeDepleted() && !isEnchanted(version);
|
||||
}
|
||||
|
||||
public boolean isEnchanted() {
|
||||
if (!isEmpty() && this.nbt != null && this.nbt.getCompoundListTagOrNull("Enchantments") != null) {
|
||||
return !this.nbt.getCompoundListTagOrNull("Enchantments").isEmpty();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
public boolean isEnchanted(ClientVersion version) {
|
||||
String tagName = getEnchantmentsTagName(version);
|
||||
return !isEmpty() && this.nbt != null && this.nbt.getCompoundListTagOrNull(tagName) != null && !this.nbt.getCompoundListTagOrNull(tagName).getTags().isEmpty();
|
||||
}
|
||||
|
||||
private static List<Enchantment> getEnchantments(@Nullable NBTCompound nbt) {
|
||||
if (nbt == null || nbt.getCompoundListTagOrNull("Enchantments") == null)
|
||||
private List<Enchantment> getEnchantments(@Nullable NBTCompound nbt, ClientVersion version) {
|
||||
String tagName = getEnchantmentsTagName(version);
|
||||
|
||||
if (nbt == null || nbt.getCompoundListTagOrNull(tagName) == null)
|
||||
return new ArrayList<>(0);
|
||||
NBTList<NBTCompound> nbtList = nbt.getCompoundListTagOrNull("Enchantments");
|
||||
|
||||
NBTList<NBTCompound> nbtList = nbt.getCompoundListTagOrNull(tagName);
|
||||
List<NBTCompound> compounds = nbtList.getTags();
|
||||
List<Enchantment> enchantments = new ArrayList<>(compounds.size());
|
||||
|
||||
for (NBTCompound compound : compounds) {
|
||||
String id = compound.getStringTagValueOrNull("id");
|
||||
EnchantmentType type = EnchantmentTypes.getByName(id);
|
||||
EnchantmentType type = getEnchantmentTypeFromTag(compound, version);
|
||||
|
||||
if (type != null) {
|
||||
NBTShort levelTag = compound.getTagOfTypeOrNull("lvl", NBTShort.class);
|
||||
int level = levelTag.getAsInt();
|
||||
@@ -175,21 +176,22 @@ public class ItemStack {
|
||||
enchantments.add(enchantment);
|
||||
}
|
||||
}
|
||||
|
||||
return enchantments;
|
||||
}
|
||||
|
||||
public List<Enchantment> getEnchantments() {
|
||||
return getEnchantments(this.nbt);
|
||||
public List<Enchantment> getEnchantments(ClientVersion version) {
|
||||
return getEnchantments(this.nbt, version);
|
||||
}
|
||||
|
||||
// TODO: Test on outdated versions
|
||||
public int getEnchantmentLevel(EnchantmentType enchantment) {
|
||||
if (isEnchanted()) {
|
||||
public int getEnchantmentLevel(EnchantmentType enchantment, ClientVersion version) {
|
||||
if (isEnchanted(version)) {
|
||||
// isEnchanted() is true, so we can assume that nbt is not null
|
||||
assert nbt != null;
|
||||
for (NBTCompound base : nbt.getCompoundListTagOrNull("Enchantments").getTags()) {
|
||||
NBTString string = base.getTagOfTypeOrNull("id", NBTString.class);
|
||||
if (string != null && enchantment == EnchantmentTypes.getByName(string.getValue())) {
|
||||
String tagName = getEnchantmentsTagName(version);
|
||||
for (NBTCompound base : nbt.getCompoundListTagOrNull(tagName).getTags()) {
|
||||
EnchantmentType type = getEnchantmentTypeFromTag(base, version);
|
||||
if (enchantment == type) {
|
||||
return base.getTagOfTypeOrNull("lvl", NBTShort.class).getAsInt();
|
||||
}
|
||||
}
|
||||
@@ -198,27 +200,51 @@ public class ItemStack {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setEnchantments(List<Enchantment> enchantments) {
|
||||
@Nullable
|
||||
private static EnchantmentType getEnchantmentTypeFromTag(NBTCompound tag, ClientVersion version) {
|
||||
if (version.isNewerThanOrEquals(ClientVersion.V_1_13)) {
|
||||
String id = tag.getStringTagValueOrNull("id");
|
||||
return EnchantmentTypes.getByName(id);
|
||||
} else {
|
||||
NBTShort idTag = tag.getTagOfTypeOrNull("id", NBTShort.class);
|
||||
return EnchantmentTypes.getById(version, idTag.getAsInt());
|
||||
}
|
||||
}
|
||||
|
||||
public void setEnchantments(List<Enchantment> enchantments, ClientVersion version) {
|
||||
nbt = getOrCreateTag(); // Create tag if null
|
||||
String tagName = getEnchantmentsTagName(version);
|
||||
if (enchantments.isEmpty()) {
|
||||
//Let us clear the enchantments
|
||||
if (nbt.getTagOrNull("Enchantments") != null) {
|
||||
nbt.removeTag("Enchantments");
|
||||
if (nbt.getTagOrNull(tagName) != null) {
|
||||
nbt.removeTag(tagName);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
List<NBTCompound> list = new ArrayList<>();
|
||||
for (Enchantment enchantment : enchantments) {
|
||||
NBTCompound compound = new NBTCompound();
|
||||
compound.setTag("id", new NBTString(enchantment.getType().getName().toString()));
|
||||
if (version.isNewerThanOrEquals(ClientVersion.V_1_13)) {
|
||||
compound.setTag("id", new NBTString(enchantment.getType().getName().toString()));
|
||||
} else {
|
||||
compound.setTag("id", new NBTShort((short) enchantment.getType().getId(version)));
|
||||
}
|
||||
|
||||
compound.setTag("lvl", new NBTShort((short) enchantment.getLevel()));
|
||||
list.add(compound);
|
||||
}
|
||||
assert nbt != null; // NBT was created in getOrCreateTag()
|
||||
nbt.setTag("Enchantments", new NBTList<>(NBTType.COMPOUND, list));
|
||||
nbt.setTag(tagName, new NBTList<>(NBTType.COMPOUND, list));
|
||||
}
|
||||
}
|
||||
|
||||
public String getEnchantmentsTagName(ClientVersion version) {
|
||||
String tagName = version.isNewerThanOrEquals(ClientVersion.V_1_13) ? "Enchantments" : "ench";
|
||||
if (type == ItemTypes.ENCHANTED_BOOK) {
|
||||
tagName = "StoredEnchantments";
|
||||
}
|
||||
return tagName;
|
||||
}
|
||||
|
||||
public boolean canBeDepleted() {
|
||||
return this.getType().getMaxDurability() > 0;
|
||||
}
|
||||
@@ -274,7 +300,6 @@ public class ItemStack {
|
||||
private int amount = 1;
|
||||
private NBTCompound nbt = null;
|
||||
private int legacyData = -1;
|
||||
private List<Enchantment> enchantments = null;
|
||||
|
||||
public Builder type(ItemType type) {
|
||||
this.type = type;
|
||||
@@ -288,13 +313,6 @@ public class ItemStack {
|
||||
|
||||
public Builder nbt(NBTCompound nbt) {
|
||||
this.nbt = nbt;
|
||||
|
||||
List<Enchantment> nbtEnchantments = getEnchantments(nbt);
|
||||
// This assumes logically, if already set enchants before NBT, then they would still want the enchants
|
||||
if (!nbtEnchantments.isEmpty()) {
|
||||
this.enchantments = nbtEnchantments;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -303,32 +321,8 @@ public class ItemStack {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Side effect: This will cause NBT to be created if it is null
|
||||
* This may affect some client sided inventory operations and may cause a desync
|
||||
*
|
||||
* @param enchantments The enchantments to set
|
||||
* @return This builder
|
||||
*/
|
||||
public Builder enchantments(List<Enchantment> enchantments) {
|
||||
this.enchantments = enchantments;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addEnchantment(Enchantment enchantment) {
|
||||
if (enchantments == null) {
|
||||
enchantments = new ArrayList<>();
|
||||
}
|
||||
this.enchantments.add(enchantment);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStack build() {
|
||||
ItemStack stack = new ItemStack(type, amount, nbt, legacyData);
|
||||
if (enchantments != null) {
|
||||
stack.setEnchantments(enchantments);
|
||||
}
|
||||
return stack;
|
||||
return new ItemStack(type, amount, nbt, legacyData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.github.retrooper.packetevents.protocol.item.book;
|
||||
|
||||
public enum BookType {
|
||||
CRAFTING,
|
||||
FURNACE,
|
||||
BLAST_FURNACE,
|
||||
SMOKER;
|
||||
|
||||
public int getId() {
|
||||
return ordinal();
|
||||
}
|
||||
|
||||
public static BookType getById(int id) {
|
||||
return VALUES[id];
|
||||
}
|
||||
|
||||
private static final BookType[] VALUES = values();
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+8
-2
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -34,7 +34,8 @@ public class EnchantmentTypes {
|
||||
ClientVersion.V_1_12,
|
||||
ClientVersion.V_1_13,
|
||||
ClientVersion.V_1_14,
|
||||
ClientVersion.V_1_16);
|
||||
ClientVersion.V_1_16,
|
||||
ClientVersion.V_1_19);
|
||||
|
||||
public static EnchantmentType define(String key) {
|
||||
TypesBuilderData data = TYPES_BUILDER.define(key);
|
||||
@@ -94,6 +95,7 @@ public class EnchantmentTypes {
|
||||
public static final EnchantmentType FROST_WALKER = define("frost_walker");
|
||||
public static final EnchantmentType BINDING_CURSE = define("binding_curse");
|
||||
public static final EnchantmentType SOUL_SPEED = define("soul_speed");
|
||||
public static final EnchantmentType SWIFT_SNEAK = define("swift_sneak");
|
||||
public static final EnchantmentType SHARPNESS = define("sharpness");
|
||||
public static final EnchantmentType SMITE = define("smite");
|
||||
public static final EnchantmentType BANE_OF_ARTHROPODS = define("bane_of_arthropods");
|
||||
@@ -120,4 +122,8 @@ public class EnchantmentTypes {
|
||||
public static final EnchantmentType PIERCING = define("piercing");
|
||||
public static final EnchantmentType MENDING = define("mending");
|
||||
public static final EnchantmentType VANISHING_CURSE = define("vanishing_curse");
|
||||
|
||||
static {
|
||||
TYPES_BUILDER.unloadFileMappings();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+60
-5
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -43,7 +43,8 @@ public class ItemTypes {
|
||||
ClientVersion.V_1_16,
|
||||
ClientVersion.V_1_16_2,
|
||||
ClientVersion.V_1_17,
|
||||
ClientVersion.V_1_18);
|
||||
ClientVersion.V_1_18,
|
||||
ClientVersion.V_1_19);
|
||||
|
||||
public static final ItemType GILDED_BLACKSTONE = builder("gilded_blackstone").setMaxAmount(64).setPlacedType(StateTypes.GILDED_BLACKSTONE).build();
|
||||
public static final ItemType NETHER_BRICK_SLAB = builder("nether_brick_slab").setMaxAmount(64).setPlacedType(StateTypes.NETHER_BRICK_SLAB).build();
|
||||
@@ -767,7 +768,7 @@ public class ItemTypes {
|
||||
public static final ItemType MAGENTA_STAINED_GLASS = builder("magenta_stained_glass").setMaxAmount(64).setPlacedType(StateTypes.MAGENTA_STAINED_GLASS).build();
|
||||
public static final ItemType LAPIS_LAZULI = builder("lapis_lazuli").setMaxAmount(64).build();
|
||||
public static final ItemType MUSIC_DISC_WAIT = builder("music_disc_wait").setMaxAmount(1).setAttributes(ItemAttribute.MUSIC_DISC).build();
|
||||
public static final ItemType NETHERITE_PICKAXE = builder("netherite_pickaxe").setMaxAmount(1).setAttributes(ItemAttribute.FIRE_RESISTANT, ItemAttribute.NETHERITE_TIER).setMaxDurability(2031).build();
|
||||
public static final ItemType NETHERITE_PICKAXE = builder("netherite_pickaxe").setMaxAmount(1).setAttributes(ItemAttribute.FIRE_RESISTANT, ItemAttribute.NETHERITE_TIER, ItemAttribute.PICKAXE).setMaxDurability(2031).build();
|
||||
public static final ItemType BUNDLE = builder("bundle").setMaxAmount(1).build();
|
||||
public static final ItemType MOOSHROOM_SPAWN_EGG = builder("mooshroom_spawn_egg").setMaxAmount(64).build();
|
||||
public static final ItemType MAP = builder("map").setMaxAmount(64).build();
|
||||
@@ -1146,6 +1147,57 @@ public class ItemTypes {
|
||||
public static final ItemType PINK_CONCRETE = builder("pink_concrete").setMaxAmount(64).setPlacedType(StateTypes.PINK_CONCRETE).build();
|
||||
public static final ItemType CARROT = builder("carrot").setMaxAmount(64).setAttributes(ItemAttribute.EDIBLE).setPlacedType(StateTypes.CARROTS).build();
|
||||
public static final ItemType MUSIC_DISC_OTHERSIDE = builder("music_disc_otherside").setMaxAmount(1).setAttributes(ItemAttribute.MUSIC_DISC).build();
|
||||
// 1.19 items
|
||||
public static final ItemType MUD = builder("mud").setMaxAmount(64).setPlacedType(StateTypes.MUD).build();
|
||||
public static final ItemType MANGROVE_PLANKS = builder("mangrove_planks").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_PLANKS).build();
|
||||
public static final ItemType MANGROVE_PROPAGULE = builder("mangrove_propagule").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_PROPAGULE).build();
|
||||
public static final ItemType MANGROVE_LOG = builder("mangrove_log").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_LOG).build();
|
||||
public static final ItemType MANGROVE_ROOTS = builder("mangrove_roots").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_ROOTS).build();
|
||||
public static final ItemType MUDDY_MANGROVE_ROOTS = builder("muddy_mangrove_roots").setMaxAmount(64).setPlacedType(StateTypes.MUDDY_MANGROVE_ROOTS).build();
|
||||
public static final ItemType STRIPPED_MANGROVE_LOG = builder("stripped_mangrove_log").setMaxAmount(64).setPlacedType(StateTypes.STRIPPED_MANGROVE_LOG).build();
|
||||
public static final ItemType STRIPPED_MANGROVE_WOOD = builder("stripped_mangrove_wood").setMaxAmount(64).setPlacedType(StateTypes.STRIPPED_MANGROVE_WOOD).build();
|
||||
public static final ItemType MANGROVE_WOOD = builder("mangrove_wood").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_WOOD).build();
|
||||
public static final ItemType MANGROVE_LEAVES = builder("mangrove_leaves").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_LEAVES).build();
|
||||
public static final ItemType MANGROVE_SLAB = builder("mangrove_slab").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_SLAB).build();
|
||||
public static final ItemType MUD_BRICK_SLAB = builder("mud_brick_slab").setMaxAmount(64).setPlacedType(StateTypes.MUD_BRICK_SLAB).build();
|
||||
public static final ItemType MANGROVE_FENCE = builder("mangrove_fence").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_FENCE).build();
|
||||
public static final ItemType PACKED_MUD = builder("packed_mud").setMaxAmount(64).setPlacedType(StateTypes.PACKED_MUD).build();
|
||||
public static final ItemType MUD_BRICKS = builder("mud_bricks").setMaxAmount(64).setPlacedType(StateTypes.MUD_BRICKS).build();
|
||||
public static final ItemType REINFORCED_DEEPSLATE = builder("reinforced_deepslate").setMaxAmount(64).setPlacedType(StateTypes.REINFORCED_DEEPSLATE).build();
|
||||
public static final ItemType MUD_BRICK_STAIRS = builder("mud_brick_stairs").setMaxAmount(64).setPlacedType(StateTypes.MUD_BRICK_STAIRS).build();
|
||||
public static final ItemType SCULK = builder("sculk").setMaxAmount(64).setPlacedType(StateTypes.SCULK).build();
|
||||
public static final ItemType SCULK_VEIN = builder("sculk_vein").setMaxAmount(64).setPlacedType(StateTypes.SCULK_VEIN).build();
|
||||
public static final ItemType SCULK_CATALYST = builder("sculk_catalyst").setMaxAmount(64).setPlacedType(StateTypes.SCULK_CATALYST).build();
|
||||
public static final ItemType SCULK_SHRIEKER = builder("sculk_shrieker").setMaxAmount(64).setPlacedType(StateTypes.SCULK_SHRIEKER).build();
|
||||
public static final ItemType MUD_BRICK_WALL = builder("mud_brick_wall").setMaxAmount(64).setPlacedType(StateTypes.MUD_BRICK_WALL).build();
|
||||
public static final ItemType MANGROVE_BUTTON = builder("mangrove_button").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_BUTTON).build();
|
||||
public static final ItemType MANGROVE_PRESSURE_PLATE = builder("mangrove_pressure_plate").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_PRESSURE_PLATE).build();
|
||||
public static final ItemType MANGROVE_DOOR = builder("mangrove_door").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_DOOR).build();
|
||||
public static final ItemType MANGROVE_TRAPDOOR = builder("mangrove_trapdoor").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_TRAPDOOR).build();
|
||||
public static final ItemType MANGROVE_FENCE_GATE = builder("mangrove_fence_gate").setMaxAmount(64).setPlacedType(StateTypes.MANGROVE_FENCE_GATE).build();
|
||||
public static final ItemType MANGROVE_SIGN = builder("mangrove_sign").setMaxAmount(16).setPlacedType(StateTypes.MANGROVE_SIGN).build();
|
||||
public static final ItemType TADPOLE_BUCKET = builder("tadpole_bucket").setMaxAmount(1).build();
|
||||
public static final ItemType RECOVERY_COMPASS = builder("recovery_compass").setMaxAmount(64).build();
|
||||
public static final ItemType ALLAY_SPAWN_EGG = builder("allay_spawn_egg").setMaxAmount(64).build();
|
||||
public static final ItemType FROG_SPAWN_EGG = builder("frog_spawn_egg").setMaxAmount(64).build();
|
||||
public static final ItemType TADPOLE_SPAWN_EGG = builder("tadpole_spawn_egg").setMaxAmount(64).build();
|
||||
public static final ItemType WARDEN_SPAWN_EGG = builder("warden_spawn_egg").setMaxAmount(64).build();
|
||||
public static final ItemType MUSIC_DISC_5 = builder("music_disc_5").setMaxAmount(1).build();
|
||||
public static final ItemType DISC_FRAGMENT_5 = builder("disc_fragment_5").setMaxAmount(64).build();
|
||||
public static final ItemType OCHRE_FROGLIGHT = builder("ochre_froglight").setMaxAmount(64).setPlacedType(StateTypes.OCHRE_FROGLIGHT).build();
|
||||
public static final ItemType VERDANT_FROGLIGHT = builder("verdant_froglight").setMaxAmount(64).setPlacedType(StateTypes.VERDANT_FROGLIGHT).build();
|
||||
public static final ItemType PEARLESCENT_FROGLIGHT = builder("pearlescent_froglight").setMaxAmount(64).setPlacedType(StateTypes.PEARLESCENT_FROGLIGHT).build();
|
||||
public static final ItemType FROGSPAWN = builder("frogspawn").setMaxAmount(64).setPlacedType(StateTypes.FROGSPAWN).build();
|
||||
public static final ItemType ECHO_SHARD = builder("echo_shard").setMaxAmount(64).build();
|
||||
public static final ItemType GOAT_HORN = builder("goat_horn").setMaxAmount(1).build();
|
||||
public static final ItemType OAK_CHEST_BOAT = builder("oak_chest_boat").setMaxAmount(1).build();
|
||||
public static final ItemType SPRUCE_CHEST_BOAT = builder("spruce_chest_boat").setMaxAmount(1).build();
|
||||
public static final ItemType BIRCH_CHEST_BOAT = builder("birch_chest_boat").setMaxAmount(1).build();
|
||||
public static final ItemType JUNGLE_CHEST_BOAT = builder("jungle_chest_boat").setMaxAmount(1).build();
|
||||
public static final ItemType ACACIA_CHEST_BOAT = builder("acacia_chest_boat").setMaxAmount(1).build();
|
||||
public static final ItemType DARK_OAK_CHEST_BOAT = builder("dark_oak_chest_boat").setMaxAmount(1).build();
|
||||
public static final ItemType MANGROVE_BOAT = builder("mangrove_boat").setMaxAmount(1).build();
|
||||
public static final ItemType MANGROVE_CHEST_BOAT = builder("mangrove_chest_boat").setMaxAmount(1).build();
|
||||
/**
|
||||
* @deprecated Burning furnace shows up as a missing texture, removed in 1.9
|
||||
*/
|
||||
@@ -1178,7 +1230,6 @@ public class ItemTypes {
|
||||
Collections.unmodifiableSet(new HashSet<>(attributesArr));
|
||||
|
||||
TypesBuilderData data = TYPES_BUILDER.define(key);
|
||||
boolean musicDisc = attributes.contains(ItemAttribute.MUSIC_DISC);
|
||||
|
||||
ItemType type = new ItemType() {
|
||||
private final int[] ids = data.getData();
|
||||
@@ -1206,7 +1257,7 @@ public class ItemTypes {
|
||||
|
||||
@Override
|
||||
public boolean isMusicDisc() {
|
||||
return musicDisc;
|
||||
return getAttributes().contains(ItemAttribute.MUSIC_DISC);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1313,4 +1364,8 @@ public class ItemTypes {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
TYPES_BUILDER.unloadFileMappings();
|
||||
}
|
||||
}
|
||||
+18
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.mapper;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -20,7 +20,7 @@ package com.github.retrooper.packetevents.protocol.mapper;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
|
||||
public interface StaticMappedEntity extends MappedEntity{
|
||||
public interface StaticMappedEntity extends MappedEntity {
|
||||
int getId();
|
||||
|
||||
default int getId(ClientVersion version) {
|
||||
|
||||
@@ -35,6 +35,11 @@ public class NBTByte extends NBTNumber {
|
||||
return NBTType.BYTE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getAsNumber() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getAsByte() {
|
||||
return value;
|
||||
|
||||
@@ -203,8 +203,7 @@ public class NBTCompound extends NBT {
|
||||
public boolean getBoolean(String string) {
|
||||
NBTByte nbtByte = this.getTagOfTypeOrNull(string, NBTByte.class);
|
||||
// Empty byte tags are considered 0
|
||||
byte byteValue = nbtByte == null ? 0 : nbtByte.getAsByte();
|
||||
return byteValue != 0;
|
||||
return nbtByte != null && nbtByte.getAsByte() != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,6 +31,11 @@ public class NBTDouble extends NBTNumber {
|
||||
return NBTType.DOUBLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getAsNumber() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getAsByte() {
|
||||
return (byte) value;
|
||||
|
||||
@@ -31,6 +31,11 @@ public class NBTFloat extends NBTNumber {
|
||||
return NBTType.FLOAT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getAsNumber() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getAsByte() {
|
||||
return (byte) value;
|
||||
|
||||
@@ -31,6 +31,11 @@ public class NBTInt extends NBTNumber {
|
||||
return NBTType.INT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getAsNumber() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getAsByte() {
|
||||
return (byte) value;
|
||||
|
||||
@@ -87,6 +87,10 @@ public class NBTList<T extends NBT> extends NBT {
|
||||
tags.add(tag);
|
||||
}
|
||||
|
||||
public void addTagUnsafe(NBT nbt) {
|
||||
addTag((T)nbt);
|
||||
}
|
||||
|
||||
protected void validateAddTag(T tag) {
|
||||
if (type != tag.getType()) {
|
||||
throw new IllegalArgumentException(MessageFormat.format("Invalid tag type. Expected {0}, got {1}.", type.getNBTClass(), tag.getClass()));
|
||||
|
||||
@@ -31,6 +31,11 @@ public class NBTLong extends NBTNumber {
|
||||
return NBTType.LONG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getAsNumber() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getAsByte() {
|
||||
return (byte) value;
|
||||
|
||||
@@ -20,6 +20,11 @@ package com.github.retrooper.packetevents.protocol.nbt;
|
||||
|
||||
public abstract class NBTNumber extends NBT {
|
||||
|
||||
//PacketEvents start - We added this to make the nbt -> json conversion easier.
|
||||
//We also implemented it in the classes extending this class.
|
||||
public abstract Number getAsNumber();
|
||||
//PacketEvents end
|
||||
|
||||
public abstract byte getAsByte();
|
||||
|
||||
public abstract short getAsShort();
|
||||
|
||||
Loaded 100 of 535 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user