Skip to content

Commit 9a0703d

Browse files
committed
Fix attribute builder in 1.17
Addresses #1224
1 parent c54a999 commit 9a0703d

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/main/java/com/comphenix/protocol/wrappers/WrappedAttribute.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
import java.lang.reflect.Constructor;
44
import java.util.*;
55
import javax.annotation.Nonnull;
6+
import javax.annotation.Nullable;
67

78
import com.comphenix.protocol.PacketType;
89
import com.comphenix.protocol.events.PacketContainer;
910
import com.comphenix.protocol.reflect.FuzzyReflection;
1011
import com.comphenix.protocol.reflect.StructureModifier;
11-
import com.comphenix.protocol.reflect.accessors.Accessors;
12-
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
13-
import com.comphenix.protocol.reflect.fuzzy.FuzzyFieldContract;
1412
import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract;
1513
import com.comphenix.protocol.utility.MinecraftReflection;
1614
import com.comphenix.protocol.utility.MinecraftVersion;
@@ -35,9 +33,6 @@ public class WrappedAttribute extends AbstractWrapper {
3533
// The one constructor
3634
private static Constructor<?> ATTRIBUTE_CONSTRUCTOR;
3735

38-
private static Object REGISTRY = null;
39-
private static MethodAccessor REGISTRY_GET = null;
40-
4136
private static final Map<String, String> REMAP;
4237

4338
static {
@@ -77,7 +72,7 @@ private WrappedAttribute(@Nonnull Object handle) {
7772

7873
// Initialize modifier
7974
if (ATTRIBUTE_MODIFIER == null) {
80-
ATTRIBUTE_MODIFIER = new StructureModifier<Object>(MinecraftReflection.getAttributeSnapshotClass());
75+
ATTRIBUTE_MODIFIER = new StructureModifier<>(MinecraftReflection.getAttributeSnapshotClass());
8176
}
8277
this.modifier = ATTRIBUTE_MODIFIER.withTarget(handle);
8378
}
@@ -170,8 +165,14 @@ public double getFinalValue() {
170165
/**
171166
* Retrieve the parent update attributes packet.
172167
* @return The parent packet.
168+
* @deprecated Removed in 1.17
173169
*/
170+
@Nullable
174171
public PacketContainer getParentPacket() {
172+
if (MinecraftVersion.CAVES_CLIFFS_1.atOrAbove()) {
173+
return null;
174+
}
175+
175176
return new PacketContainer(
176177
PacketType.Play.Server.UPDATE_ATTRIBUTES,
177178
modifier.withType(MinecraftReflection.getPacketClass()).read(0)
@@ -226,7 +227,7 @@ protected WrappedAttributeModifier toOuter(Object inner) {
226227
}
227228
};
228229

229-
attributeModifiers = new CachedSet<WrappedAttributeModifier>(converted);
230+
attributeModifiers = new CachedSet<>(converted);
230231
}
231232
return Collections.unmodifiableSet(attributeModifiers);
232233
}
@@ -249,9 +250,7 @@ public boolean equals(Object obj) {
249250

250251
if (getBaseValue() == other.getBaseValue() &&
251252
Objects.equal(getAttributeKey(), other.getAttributeKey())) {
252-
return getModifiers().stream()
253-
.filter((elem) -> !other.getModifiers().contains(elem))
254-
.count() == 0;
253+
return other.getModifiers().containsAll(getModifiers());
255254
}
256255
}
257256
return false;
@@ -414,7 +413,6 @@ private Set<Object> getUnwrappedModifiers() {
414413
* @throws RuntimeException If anything went wrong with the reflection.
415414
*/
416415
public WrappedAttribute build() {
417-
Preconditions.checkNotNull(packet, "packet cannot be NULL.");
418416
Preconditions.checkNotNull(attributeKey, "attributeKey cannot be NULL.");
419417

420418
// Remember to set the base value

src/test/java/com/comphenix/protocol/wrappers/WrappedAttributeTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ public void testAttribute() {
7474
assertTrue(attribute.hasModifier(doubleModifier.getUUID()));
7575
assertTrue(attribute.hasModifier(constantModifier.getUUID()));
7676
}
77+
78+
@Test
79+
public void testFromTemplate() {
80+
assertEquals(attribute, WrappedAttribute.newBuilder(attribute).build());
81+
}
7782

7883
/**
7984
* Retrieve the equivalent NMS attribute.

0 commit comments

Comments
 (0)