Skip to content

Commit 7b8a390

Browse files
Merge branch '1.20.6+' into new-command-system-1.20.6
2 parents 684ffd6 + 93dcf9e commit 7b8a390

11 files changed

Lines changed: 322 additions & 5 deletions

File tree

core/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dependencies {
2929
implementation(project(":versions:v1_21_r1"))
3030
implementation(project(":versions:v1_21_r3"))
3131
implementation(project(":versions:v1_21_r5"))
32+
implementation(project(":versions:v1_21_r7"))
3233

3334
compileOnly("com.google.code.gson:gson:${gson}")
3435
}

core/src/main/java/com/wizardlybump17/wlib/WLib.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,18 @@ private void setupAdapters() {
184184
AttributeAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_R5.AttributeAdapter());
185185
CommandMapAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_R5.command.CommandMapAdapter());
186186
}
187-
default -> getLogger().severe("The server version (" + version + ") is not supported by WLib yet.");
187+
case "1.21.11" -> {
188+
ItemAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_r7.ItemAdapter());
189+
PlayerAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_r7.player.PlayerAdapter());
190+
AttributeAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_r7.AttributeAdapter());
191+
}
192+
default -> {
193+
getLogger().severe("The server version (" + version + ") is not supported by WLib yet. Using last known version (1.21.11), but expect stuff to break.");
194+
195+
ItemAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_r7.ItemAdapter());
196+
PlayerAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_r7.player.PlayerAdapter());
197+
AttributeAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_r7.AttributeAdapter());
198+
}
188199
}
189200
}
190201

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ include 'versions:v1_21_R3'
2929
findProject(':versions:v1_21_R3')?.name = 'v1_21_r3'
3030
include 'versions:v1_21_R5'
3131
findProject(':versions:v1_21_R5')?.name = 'v1_21_r5'
32+
include 'versions:v1_21_r7'

versions/v1_20_R4/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id("io.papermc.paperweight.userdev") version "2.0.0-SNAPSHOT"
2+
id("io.papermc.paperweight.userdev") version "2.0.0-beta.19"
33
}
44

55
apply(plugin = "io.papermc.paperweight.userdev")

versions/v1_21_R1/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id("io.papermc.paperweight.userdev") version "2.0.0-SNAPSHOT"
2+
id("io.papermc.paperweight.userdev") version "2.0.0-beta.19"
33
}
44

55
apply(plugin = "io.papermc.paperweight.userdev")

versions/v1_21_R3/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id("io.papermc.paperweight.userdev") version "2.0.0-SNAPSHOT"
2+
id("io.papermc.paperweight.userdev") version "2.0.0-beta.19"
33
}
44

55
apply(plugin = "io.papermc.paperweight.userdev")

versions/v1_21_R5/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id("io.papermc.paperweight.userdev") version "2.0.0-SNAPSHOT"
2+
id("io.papermc.paperweight.userdev") version "2.0.0-beta.19"
33
}
44

55
apply(plugin = "io.papermc.paperweight.userdev")

versions/v1_21_r7/build.gradle.kts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
plugins {
2+
id("io.papermc.paperweight.userdev") version "2.0.0-beta.19"
3+
}
4+
5+
apply(plugin = "io.papermc.paperweight.userdev")
6+
7+
val paper = "1.21.11-R0.1-SNAPSHOT"
8+
val jetbrainsAnnotations = "26.0.2"
9+
10+
dependencies {
11+
paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:${paper}")
12+
13+
compileOnly("org.jetbrains:annotations:${jetbrainsAnnotations}")
14+
15+
implementation(project(":versions:adapter"))
16+
implementation(project(":utils"))
17+
implementation(project(":bukkit-utils"))
18+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.wizardlybump17.wlib.adapter.v1_21_r7;
2+
3+
import com.google.common.collect.Multimap;
4+
import com.google.common.collect.TreeMultimap;
5+
import org.bukkit.NamespacedKey;
6+
import org.bukkit.Registry;
7+
import org.bukkit.attribute.Attribute;
8+
import org.bukkit.attribute.AttributeModifier;
9+
import org.jetbrains.annotations.NotNull;
10+
11+
import java.util.*;
12+
13+
public class AttributeAdapter extends com.wizardlybump17.wlib.adapter.AttributeAdapter {
14+
15+
public static final @NotNull Map<String, Attribute> ATTRIBUTES;
16+
17+
static {
18+
Map<String, Attribute> attributes = new HashMap<>();
19+
attributes.put("GENERIC_MAX_HEALTH", Attribute.MAX_HEALTH);
20+
attributes.put("GENERIC_FOLLOW_RANGE", Attribute.FOLLOW_RANGE);
21+
attributes.put("GENERIC_KNOCKBACK_RESISTANCE", Attribute.KNOCKBACK_RESISTANCE);
22+
attributes.put("GENERIC_MOVEMENT_SPEED", Attribute.MOVEMENT_SPEED);
23+
attributes.put("GENERIC_FLYING_SPEED", Attribute.FLYING_SPEED);
24+
attributes.put("GENERIC_ATTACK_DAMAGE", Attribute.ATTACK_DAMAGE);
25+
attributes.put("GENERIC_ATTACK_KNOCKBACK", Attribute.ATTACK_KNOCKBACK);
26+
attributes.put("GENERIC_ATTACK_SPEED", Attribute.ATTACK_SPEED);
27+
attributes.put("GENERIC_ARMOR", Attribute.ARMOR);
28+
attributes.put("GENERIC_ARMOR_TOUGHNESS", Attribute.ARMOR_TOUGHNESS);
29+
attributes.put("GENERIC_FALL_DAMAGE_MULTIPLIER", Attribute.FALL_DAMAGE_MULTIPLIER);
30+
attributes.put("GENERIC_LUCK", Attribute.LUCK);
31+
attributes.put("GENERIC_MAX_ABSORPTION", Attribute.MAX_ABSORPTION);
32+
attributes.put("GENERIC_SAFE_FALL_DISTANCE", Attribute.SAFE_FALL_DISTANCE);
33+
attributes.put("GENERIC_SCALE", Attribute.SCALE);
34+
attributes.put("GENERIC_STEP_HEIGHT", Attribute.STEP_HEIGHT);
35+
attributes.put("GENERIC_GRAVITY", Attribute.GRAVITY);
36+
attributes.put("GENERIC_JUMP_STRENGTH", Attribute.JUMP_STRENGTH);
37+
attributes.put("PLAYER_BLOCK_INTERACTION_RANGE", Attribute.BLOCK_INTERACTION_RANGE);
38+
attributes.put("PLAYER_ENTITY_INTERACTION_RANGE", Attribute.ENTITY_INTERACTION_RANGE);
39+
attributes.put("PLAYER_BLOCK_BREAK_SPEED", Attribute.BLOCK_BREAK_SPEED);
40+
attributes.put("ZOMBIE_SPAWN_REINFORCEMENTS", Attribute.SPAWN_REINFORCEMENTS);
41+
ATTRIBUTES = Collections.unmodifiableMap(attributes);
42+
}
43+
44+
@Override
45+
public Attribute getAttribute(@NotNull String name) {
46+
Attribute converted = ATTRIBUTES.get(name.toUpperCase());
47+
if (converted != null)
48+
return converted;
49+
return Registry.ATTRIBUTE.get(NamespacedKey.fromString(name.toLowerCase()));
50+
}
51+
52+
@Override
53+
public @NotNull Map<String, Object> serialize(@NotNull Multimap<Attribute, AttributeModifier> attributes) {
54+
Map<String, Object> result = new TreeMap<>();
55+
for (Attribute attribute : attributes.keySet())
56+
result.put(attribute.getKey().toString(), List.copyOf(attributes.get(attribute)));
57+
return result;
58+
}
59+
60+
@SuppressWarnings("unchecked")
61+
@Override
62+
public @NotNull Multimap<Attribute, AttributeModifier> deserialize(@NotNull Map<String, ? extends Object> serialized) {
63+
Multimap<Attribute, AttributeModifier> result = TreeMultimap.create(
64+
Comparator.comparing(attribute -> attribute.getKey().toString()),
65+
Comparator.comparing(AttributeModifier::getKey)
66+
.thenComparing(AttributeModifier::getAmount)
67+
.thenComparing(AttributeModifier::getOperation)
68+
);
69+
serialized.forEach((attribute, modifiers) -> {
70+
if (modifiers != null)
71+
for (AttributeModifier modifier : ((Collection<AttributeModifier>) modifiers))
72+
result.put(getAttribute(attribute), modifier);
73+
});
74+
return result;
75+
}
76+
}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
package com.wizardlybump17.wlib.adapter.v1_21_r7;
2+
3+
import com.wizardlybump17.wlib.util.ReflectionUtil;
4+
import net.minecraft.nbt.*;
5+
import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer;
6+
import org.bukkit.inventory.meta.Damageable;
7+
import org.bukkit.inventory.meta.ItemMeta;
8+
import org.bukkit.persistence.PersistentDataContainer;
9+
import org.jetbrains.annotations.NotNull;
10+
import org.jetbrains.annotations.Nullable;
11+
12+
import java.lang.reflect.Field;
13+
import java.util.*;
14+
15+
public class ItemAdapter extends com.wizardlybump17.wlib.adapter.ItemAdapter {
16+
17+
public static final @NotNull Class<?> CRAFT_META_ITEM = ReflectionUtil.getClass("org.bukkit.craftbukkit.inventory.CraftMetaItem");
18+
public static final @NotNull Field CUSTOM_TAG = ReflectionUtil.getField("customTag", CRAFT_META_ITEM);
19+
20+
@Override
21+
public void transferPersistentData(@NotNull PersistentDataContainer from, @NotNull PersistentDataContainer to) {
22+
Map<String, Tag> tags = ((CraftPersistentDataContainer) to).getRaw();
23+
tags.clear();
24+
tags.putAll(((CraftPersistentDataContainer) from).getTagsCloned());
25+
}
26+
27+
@Override
28+
public void copyPersistentData(@NotNull PersistentDataContainer from, @NotNull PersistentDataContainer to) {
29+
((CraftPersistentDataContainer) to).getRaw().putAll(((CraftPersistentDataContainer) from).getTagsCloned());
30+
}
31+
32+
@Override
33+
public void setDamage(@NotNull ItemMeta meta, @Nullable Integer damage) {
34+
if (!(meta instanceof Damageable damageable))
35+
return;
36+
37+
if (damage == null)
38+
damageable.resetDamage();
39+
else
40+
damageable.setDamage(damage);
41+
}
42+
43+
@Override
44+
public @Nullable Integer getDamage(@NotNull ItemMeta meta) {
45+
return meta instanceof Damageable damageable && damageable.hasDamage() ? damageable.getDamage() : null;
46+
}
47+
48+
@Override
49+
public @NotNull Map<String, Object> getCustomData(@NotNull ItemMeta meta) {
50+
Map<String, Object> result = new HashMap<>();
51+
52+
CompoundTag tag = ReflectionUtil.getFieldValue(CUSTOM_TAG, meta);
53+
if (tag == null)
54+
return result;
55+
56+
for (String key : tag.keySet()) {
57+
Tag data = tag.get(key);
58+
if (data != null)
59+
result.put(key, fromNBT(data));
60+
}
61+
62+
return result;
63+
}
64+
65+
@Override
66+
public void setCustomData(@NotNull ItemMeta meta, @NotNull Map<String, Object> customData) {
67+
CompoundTag tag = new CompoundTag();
68+
for (Map.Entry<String, Object> entry : customData.entrySet()) {
69+
String key = entry.getKey();
70+
Object value = entry.getValue();
71+
tag.put(key, toNBT(value));
72+
}
73+
74+
ReflectionUtil.setFieldValue(CUSTOM_TAG, meta, tag);
75+
}
76+
77+
@Override
78+
protected @NotNull Tag toNBT(@NotNull Object java) {
79+
return switch (java) {
80+
case Byte b -> ByteTag.valueOf(b);
81+
case Short s -> ShortTag.valueOf(s);
82+
case Integer i -> IntTag.valueOf(i);
83+
case Long l -> LongTag.valueOf(l);
84+
case Float f -> FloatTag.valueOf(f);
85+
case Double d -> DoubleTag.valueOf(d);
86+
87+
case Boolean b -> ByteTag.valueOf(b);
88+
89+
case String string -> StringTag.valueOf(string);
90+
91+
case byte[] byteArray -> new ByteArrayTag(byteArray);
92+
case Byte[] byteArray -> {
93+
byte[] array = new byte[byteArray.length];
94+
for (int i = 0; i < byteArray.length; i++)
95+
array[i] = byteArray[i];
96+
yield new ByteArrayTag(array);
97+
}
98+
case int[] intArray -> new IntArrayTag(intArray);
99+
case Integer[] intArray -> {
100+
int[] array = new int[intArray.length];
101+
for (int i = 0; i < intArray.length; i++)
102+
array[i] = intArray[i];
103+
yield new IntArrayTag(array);
104+
}
105+
case long[] longArray -> new LongArrayTag(longArray);
106+
case Long[] longArray -> {
107+
long[] array = new long[longArray.length];
108+
for (int i = 0; i < longArray.length; i++)
109+
array[i] = longArray[i];
110+
yield new LongArrayTag(array);
111+
}
112+
113+
case Collection<?> collection -> {
114+
List<Tag> values = new ArrayList<>(collection.size());
115+
for (Object object : collection) {
116+
Tag tag = toNBT(object);
117+
values.add(tag);
118+
}
119+
yield new ListTag(values);
120+
}
121+
122+
case Map<?, ?> map -> {
123+
Map<String, Tag> values = new HashMap<>(map.size());
124+
map.forEach((key, value) -> values.put(String.valueOf(key), toNBT(value)));
125+
126+
CompoundTag tag = new CompoundTag();
127+
values.forEach(tag::put);
128+
yield tag;
129+
}
130+
131+
default -> throw new UnsupportedOperationException("Unsupported Java type: " + java);
132+
};
133+
}
134+
135+
@Override
136+
protected @NotNull Object fromNBT(@NotNull Object nbt) {
137+
return switch (nbt) {
138+
case ByteTag tag -> tag.byteValue();
139+
case ShortTag tag -> tag.shortValue();
140+
case IntTag tag -> tag.intValue();
141+
case LongTag tag -> tag.longValue();
142+
case FloatTag tag -> tag.floatValue();
143+
case DoubleTag tag -> tag.doubleValue();
144+
145+
case StringTag tag -> tag.value();
146+
147+
case ByteArrayTag tag -> tag.getAsByteArray();
148+
case IntArrayTag tag -> tag.getAsIntArray();
149+
case LongArrayTag tag -> tag.getAsLongArray();
150+
151+
case CollectionTag tag -> {
152+
List<Object> list = new ArrayList<>(tag.size());
153+
for (Tag value : tag)
154+
list.add(fromNBT(value));
155+
yield list;
156+
}
157+
158+
case CompoundTag tag -> {
159+
Map<String, Object> map = new HashMap<>(tag.size());
160+
for (String key : tag.keySet()) {
161+
Tag value = tag.get(key);
162+
if (value != null)
163+
map.put(key, fromNBT(value));
164+
}
165+
yield map;
166+
}
167+
168+
default -> throw new UnsupportedOperationException("Unsupported NBT type: " + nbt);
169+
};
170+
}
171+
}

0 commit comments

Comments
 (0)