mirror of
https://github.com/PaperMC/Paper.git
synced 2024-09-15 08:28:01 +02:00
e035fd7034
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: cc9aa21a SPIGOT-6399, SPIGOT-7344: Clarify collidable behavior for player entities f23325b6 Add API for per-world simulation distances 26e1774e Add API for per-world view distances 0b541e60 Add PlayerLoginEvent#getRealAddress 5f027d2d PR-949: Add Vector#fromJOML() overloads for read-only vector types CraftBukkit Changes: bcf56171a PR-1321: Clean up some stuff which got missed during previous PRs 7f833a2d1 SPIGOT-7462: Players no longer drop XP after dying near a Sculk Catalyst 752aac669 Implement APIs for per world view and simulation distances 57d7ef433 Preserve empty enchantment tags for glow effect 465ec3fb4 Remove connected check on setScoreboard f90ce621e Use one PermissibleBase for all command blocks 5876cca44 SPIGOT-7550: Fix creation of Arrow instances f03fc3aa3 SPIGOT-7549: ServerTickManager#setTickRate incorrect Precondition 9d7f49b01 SPIGOT-7548: Fix wrong spawn location for experience orb and dropped item Spigot Changes: ed9ba9a4 Drop no longer required patch ignoring -o option 86b5dd6a SPIGOT-7546: Fix hardcoded check for outdated client message aa7cde7a Remove obsolete APIs for per world view and simulation distances 6dff577e Remove obsolete patch preserving empty `ench` tags a3bf95b8 Remove obsolete PlayerLoginEvent#getRealAddress 1b02f5d6 Remove obsolete connected check on setScoreboard patch acf717eb Remove obsolete command block PermissibleBase patch 053fa2a9 Remove redundant patch dealing with null tile entities
92 lines
4.5 KiB
Diff
92 lines
4.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
Date: Thu, 27 May 2021 21:58:24 -0700
|
|
Subject: [PATCH] More PotionEffectType API
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionEffectType.java b/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionEffectType.java
|
|
index 7055a051759bf01dd76cc53b74fe1e65c521403e..a1a386b09f477056bb2f764ec414782ba61460ea 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionEffectType.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionEffectType.java
|
|
@@ -139,4 +139,46 @@ public class CraftPotionEffectType extends PotionEffectType {
|
|
|
|
return ((CraftPotionEffectType) bukkit).getHandle();
|
|
}
|
|
+
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public java.util.Map<org.bukkit.attribute.Attribute, org.bukkit.attribute.AttributeModifier> getEffectAttributes() {
|
|
+ // re-create map each time because a nms MobEffect can have its attributes modified
|
|
+ final java.util.Map<org.bukkit.attribute.Attribute, org.bukkit.attribute.AttributeModifier> attributeMap = new java.util.HashMap<>();
|
|
+ this.handle.getAttributeModifiers().forEach((attribute, attributeModifier) -> {
|
|
+ attributeMap.put(
|
|
+ org.bukkit.craftbukkit.attribute.CraftAttribute.stringToBukkit(attribute.toString()),
|
|
+ // use zero as amplifier to get the base amount, as it is amount = base * (amplifier + 1)
|
|
+ org.bukkit.craftbukkit.attribute.CraftAttributeInstance.convert(attributeModifier.create(0))
|
|
+ );
|
|
+ });
|
|
+ return java.util.Map.copyOf(attributeMap);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public double getAttributeModifierAmount(org.bukkit.attribute.Attribute attribute, int effectAmplifier) {
|
|
+ com.google.common.base.Preconditions.checkArgument(effectAmplifier >= 0, "effectAmplifier must be greater than or equal to 0");
|
|
+ net.minecraft.world.entity.ai.attributes.Attribute nmsAttribute = org.bukkit.craftbukkit.attribute.CraftAttribute.bukkitToMinecraft(attribute);
|
|
+ com.google.common.base.Preconditions.checkArgument(this.handle.getAttributeModifiers().containsKey(nmsAttribute), attribute + " is not present on " + this.getKey());
|
|
+ return this.handle.getAttributeModifiers().get(nmsAttribute).create(effectAmplifier).getAmount();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public PotionEffectType.Category getEffectCategory() {
|
|
+ return fromNMS(handle.getCategory());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public String translationKey() {
|
|
+ return this.handle.getDescriptionId();
|
|
+ }
|
|
+
|
|
+ public static PotionEffectType.Category fromNMS(net.minecraft.world.effect.MobEffectCategory mobEffectInfo) {
|
|
+ return switch (mobEffectInfo) {
|
|
+ case BENEFICIAL -> PotionEffectType.Category.BENEFICIAL;
|
|
+ case HARMFUL -> PotionEffectType.Category.HARMFUL;
|
|
+ case NEUTRAL -> PotionEffectType.Category.NEUTRAL;
|
|
+ };
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
diff --git a/src/test/java/io/papermc/paper/effects/EffectCategoryTest.java b/src/test/java/io/papermc/paper/effects/EffectCategoryTest.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..6262598f85bd7d9af5546cc0a96531b2f4baf64d
|
|
--- /dev/null
|
|
+++ b/src/test/java/io/papermc/paper/effects/EffectCategoryTest.java
|
|
@@ -0,0 +1,28 @@
|
|
+package io.papermc.paper.effects;
|
|
+
|
|
+import io.papermc.paper.adventure.PaperAdventure;
|
|
+import net.minecraft.world.effect.MobEffectCategory;
|
|
+import org.bukkit.craftbukkit.potion.CraftPotionEffectType;
|
|
+import org.bukkit.potion.PotionEffectType;
|
|
+import org.junit.jupiter.api.Test;
|
|
+
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
+import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
+
|
|
+public class EffectCategoryTest {
|
|
+
|
|
+ @Test
|
|
+ public void testEffectCategoriesExist() {
|
|
+ for (MobEffectCategory mobEffectInfo : MobEffectCategory.values()) {
|
|
+ assertNotNull(CraftPotionEffectType.fromNMS(mobEffectInfo), mobEffectInfo + " is missing a bukkit equivalent");
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Test
|
|
+ public void testCategoryHasEquivalentColors() {
|
|
+ for (MobEffectCategory mobEffectInfo : MobEffectCategory.values()) {
|
|
+ PotionEffectType.Category bukkitEffectCategory = CraftPotionEffectType.fromNMS(mobEffectInfo);
|
|
+ assertEquals(bukkitEffectCategory.getColor(), PaperAdventure.asAdventure(mobEffectInfo.getTooltipFormatting()), mobEffectInfo.getTooltipFormatting().name() + " doesn't equal " + bukkitEffectCategory.getColor());
|
|
+ }
|
|
+ }
|
|
+}
|