geforkt von Mirrors/Paper
de04cbced5
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: f29cb801 Separate checkstyle-suppressions file is not required 86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack 9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode() 994a6163 Attempt upgrade of resolver libraries CraftBukkit Changes: b3b43a6ad Add Checkstyle check for unused imports 13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names 3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API 2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor 1dbdbbed4 PR-1238: Remove unnecessary sign ticking 659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper e37e29ce0 Increase outdated build delay c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack 492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode() e11fbb9d7 Upgrade MySQL driver 9f3a0bd2a Attempt upgrade of resolver libraries 60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion Spigot Changes: 06d602e7 Rebuild patches
170 Zeilen
7.0 KiB
Diff
170 Zeilen
7.0 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
Date: Thu, 6 May 2021 19:57:58 -0700
|
|
Subject: [PATCH] More Enchantment API
|
|
|
|
== AT ==
|
|
public net.minecraft.world.item.enchantment.Enchantment slots
|
|
|
|
Co-authored-by: Luis <luisc99@icloud.com>
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
|
|
index 92922e8eef7fa4638a01f3cefc4c46a1451e40e7..4daf2c54c7127e8e091ffc49362f288594956143 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
|
|
@@ -90,7 +90,7 @@ public class CraftEnchantment extends Enchantment {
|
|
|
|
@Override
|
|
public boolean isCursed() {
|
|
- return this.handle instanceof BindingCurseEnchantment || this.handle instanceof VanishingCurseEnchantment;
|
|
+ return this.handle.isCurse(); // Paper
|
|
}
|
|
|
|
@Override
|
|
@@ -166,6 +166,55 @@ public class CraftEnchantment extends Enchantment {
|
|
public String translationKey() {
|
|
return this.handle.getDescriptionId();
|
|
}
|
|
+
|
|
+ @Override
|
|
+ public boolean isTradeable() {
|
|
+ return handle.isTradeable();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean isDiscoverable() {
|
|
+ return handle.isDiscoverable();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int getMinModifiedCost(int level) {
|
|
+ return handle.getMinCost(level);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int getMaxModifiedCost(int level) {
|
|
+ return handle.getMaxCost(level);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public io.papermc.paper.enchantments.EnchantmentRarity getRarity() {
|
|
+ return fromNMSRarity(handle.getRarity());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public float getDamageIncrease(int level, org.bukkit.entity.EntityCategory entityCategory) {
|
|
+ return handle.getDamageBonus(level, org.bukkit.craftbukkit.entity.CraftLivingEntity.fromBukkitEntityCategory(entityCategory));
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public java.util.Set<org.bukkit.inventory.EquipmentSlot> getActiveSlots() {
|
|
+ return java.util.stream.Stream.of(handle.slots).map(org.bukkit.craftbukkit.CraftEquipmentSlot::getSlot).collect(java.util.stream.Collectors.toSet());
|
|
+ }
|
|
+
|
|
+ public static io.papermc.paper.enchantments.EnchantmentRarity fromNMSRarity(net.minecraft.world.item.enchantment.Enchantment.Rarity nmsRarity) {
|
|
+ if (nmsRarity == net.minecraft.world.item.enchantment.Enchantment.Rarity.COMMON) {
|
|
+ return io.papermc.paper.enchantments.EnchantmentRarity.COMMON;
|
|
+ } else if (nmsRarity == net.minecraft.world.item.enchantment.Enchantment.Rarity.UNCOMMON) {
|
|
+ return io.papermc.paper.enchantments.EnchantmentRarity.UNCOMMON;
|
|
+ } else if (nmsRarity == net.minecraft.world.item.enchantment.Enchantment.Rarity.RARE) {
|
|
+ return io.papermc.paper.enchantments.EnchantmentRarity.RARE;
|
|
+ } else if (nmsRarity == net.minecraft.world.item.enchantment.Enchantment.Rarity.VERY_RARE) {
|
|
+ return io.papermc.paper.enchantments.EnchantmentRarity.VERY_RARE;
|
|
+ }
|
|
+
|
|
+ throw new IllegalArgumentException(String.format("Unable to convert %s to a enum value of %s.", nmsRarity, io.papermc.paper.enchantments.EnchantmentRarity.class));
|
|
+ }
|
|
// Paper end
|
|
|
|
@Override
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
|
index 762220f4e8762e8c6ec45cd22cb745fe676543ec..85e33cb959eada67f3a4ac93f979bf96fc0fb98d 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
|
@@ -953,5 +953,21 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
|
public void setHurtDirection(float hurtDirection) {
|
|
throw new UnsupportedOperationException("Cannot set the hurt direction on a non player");
|
|
}
|
|
+
|
|
+ public static MobType fromBukkitEntityCategory(EntityCategory entityCategory) {
|
|
+ switch (entityCategory) {
|
|
+ case NONE:
|
|
+ return MobType.UNDEFINED;
|
|
+ case UNDEAD:
|
|
+ return MobType.UNDEAD;
|
|
+ case ARTHROPOD:
|
|
+ return MobType.ARTHROPOD;
|
|
+ case ILLAGER:
|
|
+ return MobType.ILLAGER;
|
|
+ case WATER:
|
|
+ return MobType.WATER;
|
|
+ }
|
|
+ throw new IllegalArgumentException(entityCategory + " is an unrecognized entity category");
|
|
+ }
|
|
// Paper end
|
|
}
|
|
diff --git a/src/test/java/io/papermc/paper/enchantments/EnchantmentRarityTest.java b/src/test/java/io/papermc/paper/enchantments/EnchantmentRarityTest.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..03a53ceb0dc3aaff7b5d10ec57f74d71be90ec3a
|
|
--- /dev/null
|
|
+++ b/src/test/java/io/papermc/paper/enchantments/EnchantmentRarityTest.java
|
|
@@ -0,0 +1,18 @@
|
|
+package io.papermc.paper.enchantments;
|
|
+
|
|
+import net.minecraft.world.item.enchantment.Enchantment.Rarity;
|
|
+import org.bukkit.craftbukkit.enchantments.CraftEnchantment;
|
|
+import org.junit.jupiter.api.Test;
|
|
+
|
|
+import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
+
|
|
+public class EnchantmentRarityTest {
|
|
+
|
|
+ @Test
|
|
+ public void test() {
|
|
+ for (Rarity nmsRarity : Rarity.values()) {
|
|
+ // Will throw exception if a bukkit counterpart is not found
|
|
+ CraftEnchantment.fromNMSRarity(nmsRarity);
|
|
+ }
|
|
+ }
|
|
+}
|
|
diff --git a/src/test/java/io/papermc/paper/entity/EntityCategoryTest.java b/src/test/java/io/papermc/paper/entity/EntityCategoryTest.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..4ee48ef89f0e31a7bda4b04453fca8177874f540
|
|
--- /dev/null
|
|
+++ b/src/test/java/io/papermc/paper/entity/EntityCategoryTest.java
|
|
@@ -0,0 +1,34 @@
|
|
+package io.papermc.paper.entity;
|
|
+
|
|
+import com.google.common.base.Joiner;
|
|
+import com.google.common.collect.Maps;
|
|
+import com.google.common.collect.Sets;
|
|
+import net.minecraft.world.entity.MobType;
|
|
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
|
|
+import org.bukkit.entity.EntityCategory;
|
|
+import org.junit.jupiter.api.Test;
|
|
+
|
|
+import java.lang.reflect.Field;
|
|
+import java.util.Map;
|
|
+import java.util.Set;
|
|
+
|
|
+import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
+
|
|
+public class EntityCategoryTest {
|
|
+
|
|
+ @Test
|
|
+ public void test() throws IllegalAccessException {
|
|
+
|
|
+ Map<MobType, String> enumMonsterTypeFieldMap = Maps.newHashMap();
|
|
+ for (Field field : MobType.class.getDeclaredFields()) {
|
|
+ if (field.getType() == MobType.class) {
|
|
+ enumMonsterTypeFieldMap.put( (MobType) field.get(null), field.getName());
|
|
+ }
|
|
+ }
|
|
+
|
|
+ for (EntityCategory entityCategory : EntityCategory.values()) {
|
|
+ enumMonsterTypeFieldMap.remove(CraftLivingEntity.fromBukkitEntityCategory(entityCategory));
|
|
+ }
|
|
+ assertTrue(enumMonsterTypeFieldMap.size() == 0, MobType.class.getName() + " instance(s): " + Joiner.on(", ").join(enumMonsterTypeFieldMap.values()) + " do not have bukkit equivalents");
|
|
+ }
|
|
+}
|