Skip to content

Commit fd855ed

Browse files
committed
more fixes
1 parent 2aa0edf commit fd855ed

39 files changed

Lines changed: 647 additions & 349 deletions

File tree

src/main/java/net/dmulloy2/protocol/wrappers/configuration/clientbound/WrappedClientboundCustomReportDetailsPacket.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.comphenix.protocol.PacketType;
44
import com.comphenix.protocol.events.PacketContainer;
5+
import com.comphenix.protocol.injector.EquivalentConstructor;
56
import com.comphenix.protocol.wrappers.Converters;
67
import java.util.Map;
78
import net.dmulloy2.protocol.AbstractPacket;
@@ -18,13 +19,15 @@ public class WrappedClientboundCustomReportDetailsPacket extends AbstractPacket
1819

1920
public static final PacketType TYPE = PacketType.Configuration.Server.REPORT_DETAILS;
2021

22+
private static final EquivalentConstructor CONSTRUCTOR = new EquivalentConstructor(TYPE)
23+
.withParam(Map.class);
24+
2125
public WrappedClientboundCustomReportDetailsPacket() {
2226
super(new PacketContainer(TYPE), TYPE);
2327
}
2428

2529
public WrappedClientboundCustomReportDetailsPacket(Map<String, String> details) {
26-
this();
27-
setDetails(details);
30+
this(new PacketContainer(TYPE, CONSTRUCTOR.create(details)));
2831
}
2932

3033
public WrappedClientboundCustomReportDetailsPacket(PacketContainer packet) {
@@ -34,12 +37,12 @@ public WrappedClientboundCustomReportDetailsPacket(PacketContainer packet) {
3437
public Map<String, String> getDetails() {
3538
return handle.getMaps(
3639
Converters.passthrough(String.class),
37-
Converters.passthrough(String.class)).read(0);
40+
Converters.passthrough(String.class)).readSafely(0);
3841
}
3942

4043
public void setDetails(Map<String, String> details) {
4144
handle.getMaps(
4245
Converters.passthrough(String.class),
43-
Converters.passthrough(String.class)).write(0, details);
46+
Converters.passthrough(String.class)).writeSafely(0, details);
4447
}
4548
}

src/main/java/net/dmulloy2/protocol/wrappers/configuration/clientbound/WrappedClientboundResourcePackPopPacket.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.comphenix.protocol.PacketType;
44
import com.comphenix.protocol.events.PacketContainer;
5+
import com.comphenix.protocol.injector.EquivalentConstructor;
56
import com.comphenix.protocol.wrappers.Converters;
67
import java.util.Optional;
78
import java.util.UUID;
@@ -19,24 +20,26 @@ public class WrappedClientboundResourcePackPopPacket extends AbstractPacket {
1920

2021
public static final PacketType TYPE = PacketType.Configuration.Server.REMOVE_RESOURCE_PACK;
2122

23+
private static final EquivalentConstructor CONSTRUCTOR = new EquivalentConstructor(TYPE)
24+
.withParam(Optional.class);
25+
2226
public WrappedClientboundResourcePackPopPacket() {
2327
super(new PacketContainer(TYPE), TYPE);
2428
}
2529

2630
public WrappedClientboundResourcePackPopPacket(Optional<UUID> id) {
27-
this();
28-
setId(id);
31+
this(new PacketContainer(TYPE, CONSTRUCTOR.create(id)));
2932
}
3033

3134
public WrappedClientboundResourcePackPopPacket(PacketContainer packet) {
3235
super(packet, TYPE);
3336
}
3437

3538
public Optional<UUID> getId() {
36-
return handle.getOptionals(Converters.passthrough(UUID.class)).read(0);
39+
return handle.getOptionals(Converters.passthrough(UUID.class)).readSafely(0);
3740
}
3841

3942
public void setId(Optional<UUID> id) {
40-
handle.getOptionals(Converters.passthrough(UUID.class)).write(0, id);
43+
handle.getOptionals(Converters.passthrough(UUID.class)).writeSafely(0, id);
4144
}
4245
}

src/main/java/net/dmulloy2/protocol/wrappers/configuration/clientbound/WrappedClientboundUpdateEnabledFeaturesPacket.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.comphenix.protocol.PacketType;
44
import com.comphenix.protocol.events.PacketContainer;
5+
import com.comphenix.protocol.injector.EquivalentConstructor;
6+
import com.comphenix.protocol.wrappers.BukkitConverters;
57
import com.comphenix.protocol.wrappers.MinecraftKey;
68
import java.util.Set;
79
import net.dmulloy2.protocol.AbstractPacket;
@@ -18,24 +20,26 @@ public class WrappedClientboundUpdateEnabledFeaturesPacket extends AbstractPacke
1820

1921
public static final PacketType TYPE = PacketType.Configuration.Server.UPDATE_ENABLED_FEATURES;
2022

23+
private static final EquivalentConstructor CONSTRUCTOR = new EquivalentConstructor(TYPE)
24+
.withParam(Set.class, BukkitConverters.getSetConverter(MinecraftKey.getConverter()));
25+
2126
public WrappedClientboundUpdateEnabledFeaturesPacket() {
2227
super(new PacketContainer(TYPE), TYPE);
2328
}
2429

2530
public WrappedClientboundUpdateEnabledFeaturesPacket(Set<MinecraftKey> features) {
26-
this();
27-
setFeatures(features);
31+
this(new PacketContainer(TYPE, CONSTRUCTOR.create(features)));
2832
}
2933

3034
public WrappedClientboundUpdateEnabledFeaturesPacket(PacketContainer packet) {
3135
super(packet, TYPE);
3236
}
3337

3438
public Set<MinecraftKey> getFeatures() {
35-
return handle.getSets(MinecraftKey.getConverter()).read(0);
39+
return handle.getSets(MinecraftKey.getConverter()).readSafely(0);
3640
}
3741

3842
public void setFeatures(Set<MinecraftKey> features) {
39-
handle.getSets(MinecraftKey.getConverter()).write(0, features);
43+
handle.getSets(MinecraftKey.getConverter()).writeSafely(0, features);
4044
}
4145
}

src/main/java/net/dmulloy2/protocol/wrappers/configuration/serverbound/WrappedServerboundCookieResponsePacket.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import com.comphenix.protocol.PacketType;
44
import com.comphenix.protocol.events.PacketContainer;
5+
import com.comphenix.protocol.injector.EquivalentConstructor;
6+
import com.comphenix.protocol.utility.MinecraftReflection;
57
import com.comphenix.protocol.wrappers.MinecraftKey;
6-
import java.util.Optional;
78
import net.dmulloy2.protocol.AbstractPacket;
89

910
/**
@@ -12,40 +13,42 @@
1213
* <p>Packet structure:
1314
* <ul>
1415
* <li>{@code Identifier key} – namespaced key identifying the cookie</li>
15-
* <li>{@code Optional<byte[]> payload} – cookie bytes, or empty if the client has no value</li>
16+
* <li>{@code byte[] payload} – cookie bytes, or {@code null} if the client has no value</li>
1617
* </ul>
1718
*/
1819
public class WrappedServerboundCookieResponsePacket extends AbstractPacket {
1920

2021
public static final PacketType TYPE = PacketType.Configuration.Client.COOKIE_RESPONSE;
2122

23+
private static final EquivalentConstructor CONSTRUCTOR = new EquivalentConstructor(TYPE)
24+
.withParam(MinecraftReflection.getMinecraftKeyClass(), MinecraftKey.getConverter())
25+
.withParam(byte[].class);
26+
2227
public WrappedServerboundCookieResponsePacket() {
2328
super(new PacketContainer(TYPE), TYPE);
2429
}
2530

26-
public WrappedServerboundCookieResponsePacket(MinecraftKey key, Optional<byte[]> payload) {
27-
this();
28-
setKey(key);
29-
setPayload(payload);
31+
public WrappedServerboundCookieResponsePacket(MinecraftKey key, byte[] payload) {
32+
this(new PacketContainer(TYPE, CONSTRUCTOR.create(key, payload)));
3033
}
3134

3235
public WrappedServerboundCookieResponsePacket(PacketContainer packet) {
3336
super(packet, TYPE);
3437
}
3538

3639
public MinecraftKey getKey() {
37-
return handle.getMinecraftKeys().read(0);
40+
return handle.getMinecraftKeys().readSafely(0);
3841
}
3942

4043
public void setKey(MinecraftKey key) {
41-
handle.getMinecraftKeys().write(0, key);
44+
handle.getMinecraftKeys().writeSafely(0, key);
4245
}
4346

44-
public Optional<byte[]> getPayload() {
45-
return Optional.ofNullable(handle.getByteArrays().readSafely(0));
47+
public byte[] getPayload() {
48+
return handle.getByteArrays().readSafely(0);
4649
}
4750

48-
public void setPayload(Optional<byte[]> payload) {
49-
handle.getByteArrays().write(0, payload == null ? null : payload.orElse(null));
51+
public void setPayload(byte[] payload) {
52+
handle.getByteArrays().writeSafely(0, payload);
5053
}
5154
}

src/main/java/net/dmulloy2/protocol/wrappers/game/clientbound/WrappedClientboundCustomChatCompletionsPacket.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import com.comphenix.protocol.PacketType;
44
import com.comphenix.protocol.events.PacketContainer;
5+
import com.comphenix.protocol.injector.EquivalentConstructor;
56
import com.comphenix.protocol.wrappers.Converters;
7+
import com.comphenix.protocol.wrappers.EnumWrappers;
8+
import java.util.Arrays;
69
import java.util.List;
710
import net.dmulloy2.protocol.AbstractPacket;
811

@@ -21,14 +24,21 @@ public class WrappedClientboundCustomChatCompletionsPacket extends AbstractPacke
2124
*/
2225
public enum Action { ADD, REMOVE, SET }
2326

27+
private static final Class<?> ACTION_NMS_CLASS = Arrays.stream(TYPE.getPacketClass().getDeclaredClasses())
28+
.filter(Class::isEnum)
29+
.findFirst()
30+
.orElse(null);
31+
32+
private static final EquivalentConstructor CONSTRUCTOR = new EquivalentConstructor(TYPE)
33+
.withParam(ACTION_NMS_CLASS, new EnumWrappers.EnumConverter<>(ACTION_NMS_CLASS, Action.class))
34+
.withParam(List.class);
35+
2436
public WrappedClientboundCustomChatCompletionsPacket() {
2537
super(new PacketContainer(TYPE), TYPE);
2638
}
2739

2840
public WrappedClientboundCustomChatCompletionsPacket(Action action, List<String> entries) {
29-
this();
30-
setAction(action);
31-
setEntries(entries);
41+
this(new PacketContainer(TYPE, CONSTRUCTOR.create(action, entries)));
3242
}
3343

3444
public WrappedClientboundCustomChatCompletionsPacket(PacketContainer packet) {
@@ -37,18 +47,18 @@ public WrappedClientboundCustomChatCompletionsPacket(PacketContainer packet) {
3747

3848
/** Returns the completion action (ADD, REMOVE, or SET). Global field index 0. */
3949
public Action getAction() {
40-
return handle.getEnumModifier(Action.class, 0).read(0);
50+
return handle.getEnumModifier(Action.class, 0).readSafely(0);
4151
}
4252

4353
public void setAction(Action action) {
44-
handle.getEnumModifier(Action.class, 0).write(0, action);
54+
handle.getEnumModifier(Action.class, 0).writeSafely(0, action);
4555
}
4656

4757
public List<String> getEntries() {
48-
return handle.getLists(Converters.passthrough(String.class)).read(0);
58+
return handle.getLists(Converters.passthrough(String.class)).readSafely(0);
4959
}
5060

5161
public void setEntries(List<String> entries) {
52-
handle.getLists(Converters.passthrough(String.class)).write(0, entries);
62+
handle.getLists(Converters.passthrough(String.class)).writeSafely(0, entries);
5363
}
5464
}

src/main/java/net/dmulloy2/protocol/wrappers/game/clientbound/WrappedClientboundCustomReportDetailsPacket.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.comphenix.protocol.PacketType;
44
import com.comphenix.protocol.events.PacketContainer;
5+
import com.comphenix.protocol.injector.EquivalentConstructor;
56
import com.comphenix.protocol.wrappers.Converters;
67
import java.util.Map;
78
import net.dmulloy2.protocol.AbstractPacket;
@@ -18,13 +19,15 @@ public class WrappedClientboundCustomReportDetailsPacket extends AbstractPacket
1819

1920
public static final PacketType TYPE = PacketType.Play.Server.REPORT_DETAILS;
2021

22+
private static final EquivalentConstructor CONSTRUCTOR = new EquivalentConstructor(TYPE)
23+
.withParam(Map.class);
24+
2125
public WrappedClientboundCustomReportDetailsPacket() {
2226
super(new PacketContainer(TYPE), TYPE);
2327
}
2428

2529
public WrappedClientboundCustomReportDetailsPacket(Map<String, String> details) {
26-
this();
27-
setDetails(details);
30+
this(new PacketContainer(TYPE, CONSTRUCTOR.create(details)));
2831
}
2932

3033
public WrappedClientboundCustomReportDetailsPacket(PacketContainer packet) {
@@ -34,12 +37,12 @@ public WrappedClientboundCustomReportDetailsPacket(PacketContainer packet) {
3437
public Map<String, String> getDetails() {
3538
return handle.getMaps(
3639
Converters.passthrough(String.class),
37-
Converters.passthrough(String.class)).read(0);
40+
Converters.passthrough(String.class)).readSafely(0);
3841
}
3942

4043
public void setDetails(Map<String, String> details) {
4144
handle.getMaps(
4245
Converters.passthrough(String.class),
43-
Converters.passthrough(String.class)).write(0, details);
46+
Converters.passthrough(String.class)).writeSafely(0, details);
4447
}
4548
}

src/main/java/net/dmulloy2/protocol/wrappers/game/clientbound/WrappedClientboundDebugSamplePacket.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import com.comphenix.protocol.PacketType;
44
import com.comphenix.protocol.events.PacketContainer;
5+
import com.comphenix.protocol.injector.EquivalentConstructor;
6+
import com.comphenix.protocol.utility.MinecraftReflection;
7+
import com.comphenix.protocol.wrappers.EnumWrappers;
58
import net.dmulloy2.protocol.AbstractPacket;
69

710
/**
@@ -25,45 +28,39 @@ public enum DebugSampleType {
2528
TICK_TIME
2629
}
2730

31+
private static final Class<?> REMOTE_DEBUG_SAMPLE_TYPE_CLASS =
32+
MinecraftReflection.getMinecraftClass("util.debugchart.RemoteDebugSampleType");
33+
34+
private static final EquivalentConstructor CONSTRUCTOR = new EquivalentConstructor(TYPE)
35+
.withParam(long[].class)
36+
.withParam(REMOTE_DEBUG_SAMPLE_TYPE_CLASS,
37+
new EnumWrappers.EnumConverter<>(REMOTE_DEBUG_SAMPLE_TYPE_CLASS, DebugSampleType.class));
38+
2839
public WrappedClientboundDebugSamplePacket() {
2940
super(new PacketContainer(TYPE), TYPE);
3041
}
3142

3243
public WrappedClientboundDebugSamplePacket(long[] sample, DebugSampleType debugSampleType) {
33-
this();
34-
setSample(sample);
35-
setDebugSampleType(debugSampleType);
44+
this(new PacketContainer(TYPE, CONSTRUCTOR.create(sample, debugSampleType)));
3645
}
3746

3847
public WrappedClientboundDebugSamplePacket(PacketContainer packet) {
3948
super(packet, TYPE);
4049
}
4150

42-
/**
43-
* Returns the array of debug timing samples.
44-
*/
4551
public long[] getSample() {
46-
return handle.getSpecificModifier(long[].class).read(0);
52+
return handle.getSpecificModifier(long[].class).readSafely(0);
4753
}
4854

49-
/**
50-
* Sets the array of debug timing samples.
51-
*/
5255
public void setSample(long[] sample) {
53-
handle.getSpecificModifier(long[].class).write(0, sample);
56+
handle.getSpecificModifier(long[].class).writeSafely(0, sample);
5457
}
5558

56-
/**
57-
* Returns the debug sample type (field at global index 1 in the NMS packet).
58-
*/
5959
public DebugSampleType getDebugSampleType() {
60-
return handle.getEnumModifier(DebugSampleType.class, 1).read(0);
60+
return handle.getEnumModifier(DebugSampleType.class, 1).readSafely(0);
6161
}
6262

63-
/**
64-
* Sets the debug sample type.
65-
*/
6663
public void setDebugSampleType(DebugSampleType debugSampleType) {
67-
handle.getEnumModifier(DebugSampleType.class, 1).write(0, debugSampleType);
64+
handle.getEnumModifier(DebugSampleType.class, 1).writeSafely(0, debugSampleType);
6865
}
6966
}

src/main/java/net/dmulloy2/protocol/wrappers/game/clientbound/WrappedClientboundPlayerInfoRemovePacket.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.comphenix.protocol.PacketType;
44
import com.comphenix.protocol.events.PacketContainer;
5+
import com.comphenix.protocol.injector.EquivalentConstructor;
56
import java.util.List;
67
import java.util.UUID;
78
import net.dmulloy2.protocol.AbstractPacket;
@@ -18,24 +19,26 @@ public class WrappedClientboundPlayerInfoRemovePacket extends AbstractPacket {
1819

1920
public static final PacketType TYPE = PacketType.Play.Server.PLAYER_INFO_REMOVE;
2021

22+
private static final EquivalentConstructor CONSTRUCTOR = new EquivalentConstructor(TYPE)
23+
.withParam(List.class);
24+
2125
public WrappedClientboundPlayerInfoRemovePacket() {
2226
super(new PacketContainer(TYPE), TYPE);
2327
}
2428

2529
public WrappedClientboundPlayerInfoRemovePacket(List<UUID> profileIds) {
26-
this();
27-
setProfileIds(profileIds);
30+
this(new PacketContainer(TYPE, CONSTRUCTOR.create(profileIds)));
2831
}
2932

3033
public WrappedClientboundPlayerInfoRemovePacket(PacketContainer packet) {
3134
super(packet, TYPE);
3235
}
3336

3437
public List<UUID> getProfileIds() {
35-
return handle.getUUIDLists().read(0);
38+
return handle.getUUIDLists().readSafely(0);
3639
}
3740

3841
public void setProfileIds(List<UUID> profileIds) {
39-
handle.getUUIDLists().write(0, profileIds);
42+
handle.getUUIDLists().writeSafely(0, profileIds);
4043
}
4144
}

0 commit comments

Comments
 (0)