Update paper plugin to MC 1.20.6

- Convert Brigadier command to use the new Brigadier/Paper API
- EquipmentSlot now has BODY value for horses and wolves armor
- ItemMeta’ canPlaceOn and canDestroy does not work anymore. Removed the related methods from ItemStackBuilder
- Enchantment DURABILITY now has the proper vanilla name UNBREAKING
- Pandalib-chat now uses Adventure’s TranslationArgument
This commit is contained in:
2024-06-07 00:05:07 +02:00
parent d411618e63
commit e7b528718c
8 changed files with 118 additions and 420 deletions

View File

@@ -1,6 +1,5 @@
package fr.pandacube.lib.paper.util;
import com.destroystokyo.paper.Namespaced;
import com.google.common.collect.Streams;
import fr.pandacube.lib.chat.Chat;
import net.kyori.adventure.text.Component;
@@ -13,10 +12,8 @@ import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import static fr.pandacube.lib.chat.ChatStatic.chatComponent;
@@ -183,7 +180,7 @@ public class ItemStackBuilder {
public ItemStackBuilder fakeEnchant(boolean apply) {
if (apply) {
enchant(Enchantment.DURABILITY, 1);
enchant(Enchantment.UNBREAKING, 1);
return hideEnchants();
}
return this;
@@ -196,22 +193,6 @@ public class ItemStackBuilder {
public ItemStackBuilder unbreakable(boolean unbreakable) {
return meta(m -> m.setUnbreakable(unbreakable));
}
public ItemStackBuilder canDestroy(Set<Material> destroyable) {
return canDestroy(destroyable.stream().map(m -> (Namespaced) m.getKey()).toList());
}
public ItemStackBuilder canPlaceOn(Set<Material> placeOn) {
return canPlaceOn(placeOn.stream().map(m -> (Namespaced) m.getKey()).toList());
}
public ItemStackBuilder canDestroy(Collection<Namespaced> destroyable) {
return meta(m -> m.setDestroyableKeys(destroyable));
}
public ItemStackBuilder canPlaceOn(Collection<Namespaced> placeOn) {
return meta(m -> m.setPlaceableKeys(placeOn));
}
public ItemStackBuilder damage(int d) {
return meta(m -> m.setDamage(d), Damageable.class);

View File

@@ -18,6 +18,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.TreeMap;
import java.util.function.IntUnaryOperator;
@@ -98,7 +99,7 @@ public record PlayerDataWrapper(CompoundTag data) {
Inventory inv = Bukkit.createInventory(null, bukkitType);
if (stacks.isEmpty())
return inv;
for (Map.Entry<Integer, ItemStack> is : stacks.entrySet()) {
for (Entry<Integer, ItemStack> is : stacks.entrySet()) {
inv.setItem(nbtToBukkitSlotConverter.applyAsInt(is.getKey()), is.getValue());
}
return inv;
@@ -142,7 +143,7 @@ public record PlayerDataWrapper(CompoundTag data) {
private void setRawInventoryContent(String key, Map<Integer, ItemStack> stacks) {
ListTag list = new ListTag();
for (Map.Entry<Integer, ItemStack> is : stacks.entrySet()) {
for (Entry<Integer, ItemStack> is : stacks.entrySet()) {
ItemStack stack = filterStack(is.getValue());
if (stack == null)
continue;
@@ -312,6 +313,7 @@ public record PlayerDataWrapper(CompoundTag data) {
case LEGS -> Objects.requireNonNullElseGet(this.getLeggings(), () -> new ItemStack(Material.AIR));
case CHEST -> Objects.requireNonNullElseGet(this.getChestplate(), () -> new ItemStack(Material.AIR));
case HEAD -> Objects.requireNonNullElseGet(this.getHelmet(), () -> new ItemStack(Material.AIR));
case BODY -> new ItemStack(Material.AIR); // for horses/wolves armor
};
}