Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-15 19:10:09 +01:00
ac554ad46d
Updated Upstream (Bukkit/CraftBukkit) 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: fa99e752 PR-1007: Add ItemMeta#getAsComponentString() 94a91782 Fix copy-pasted BlockType.Typed documentation 9b34ac8c Largely restore deprecated PotionData API 51a6449b PR-1008: Deprecate ITEMS_TOOLS, removed in 1.20.5 702d15fe Fix Javadoc reference 42f6cdf4 PR-919: Add internal ItemType and BlockType, delegate Material methods to them 237bb37b SPIGOT-1166, SPIGOT-7647: Expose Damager BlockState in EntityDamageByBlockEvent 035ea146 SPIGOT-6993: Allow #setVelocity to change the speed of a fireball and add a note to #setDirection about it 8c7880fb PR-1004: Improve field rename handling and centralize conversion between bukkit and string more 87c90e93 SPIGOT-7650: Add DamageSource for EntityDeathEvent and PlayerDeathEvent CraftBukkit Changes: 4af0f22e8 SPIGOT-7664: Item meta should prevail over block states c2ccc46ec SPIGOT-7666: Fix access to llama and horse special slot 124ac66d7 SPIGOT-7665: Fix ThrownPotion#getEffects() implementation only bringing custom effects 66f1f439a Restore null page behaviour of signed books even though not strictly allowed by API 6118e5398 Fix regression listening to minecraft:brand custom payloads c1a26b366 Fix unnecessary and potential not thread-safe chat visibility check 12360a7ec Remove unused imports 147b098b4 PR-1397: Add ItemMeta#getAsComponentString() 428aefe0e Largely restore deprecated PotionData API afe5b5ee9 PR-1275: Add internal ItemType and BlockType, delegate Material methods to them 8afeafa7d SPIGOT-1166, SPIGOT-7647: Expose Damager BlockState in EntityDamageByBlockEvent 4e7d749d4 SPIGOT-6993: Allow #setVelocity to change the speed of a fireball and add a note to #setDirection about it 441880757 Support both entity_data and bucket_entity_data on axolotl/fish buckets 0e22fdd1e Fix custom direct BlockState being not correctly set in DamageSource f2182ed47 SPIGOT-7659: TropicalFishBucketMeta should use BUCKET_ENTITY_DATA 2a6207fe1 PR-1393: Improve field rename handling and centralize conversion between bukkit and string more c024a5039 SPIGOT-7650: Add DamageSource for EntityDeathEvent and PlayerDeathEvent 741b84480 PR-1390: Improve internal handling of damage sources 0364df4e1 SPIGOT-7657: Error when loading angry entities
232 Zeilen
13 KiB
Diff
232 Zeilen
13 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
|
|
Date: Sun, 3 Mar 2024 19:43:40 +0100
|
|
Subject: [PATCH] Suspicious Effect Entry API
|
|
|
|
Exposes a new suspicious effect entry type that properly represents
|
|
storable effects in the context of suspicious effects as they only
|
|
define the potion effect type and duration.
|
|
|
|
This differentiates them from the existing PotionEffect API found in
|
|
bukkit and hence clarifies that storable values in the parts of the API
|
|
in which it replaces PotionEffect.
|
|
|
|
Co-authored-by: Yannick Lamprecht <yannicklamprecht@live.de>
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java
|
|
index 9cc81bcccbf1141f66fedada1359b7c0dfa8e22a..5c5b64bd058684520fa175bfd10622ff57856b7c 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java
|
|
@@ -37,16 +37,24 @@ public class CraftMushroomCow extends CraftCow implements MushroomCow, io.paperm
|
|
@Override
|
|
public boolean addEffectToNextStew(PotionEffect potionEffect, boolean overwrite) {
|
|
Preconditions.checkArgument(potionEffect != null, "PotionEffect cannot be null");
|
|
- MobEffectInstance minecraftPotionEffect = CraftPotionUtil.fromBukkit(potionEffect);
|
|
- if (!overwrite && this.hasEffectForNextStew(potionEffect.getType())) {
|
|
+ // Paper start - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
|
|
+ return this.addEffectToNextStew(io.papermc.paper.potion.SuspiciousEffectEntry.create(potionEffect.getType(), potionEffect.getDuration()), overwrite);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean addEffectToNextStew(io.papermc.paper.potion.SuspiciousEffectEntry suspiciousEffectEntry, boolean overwrite) {
|
|
+ Preconditions.checkArgument(suspiciousEffectEntry != null, "SuspiciousEffectEntry cannot be null");
|
|
+ Holder<MobEffect> minecraftPotionEffect = CraftPotionEffectType.bukkitToMinecraftHolder(suspiciousEffectEntry.effect());
|
|
+ // Paper end - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
|
|
+ if (!overwrite && this.hasEffectForNextStew(suspiciousEffectEntry.effect())) {
|
|
return false;
|
|
}
|
|
SuspiciousStewEffects stewEffects = this.getHandle().stewEffects;
|
|
if (stewEffects == null) {
|
|
stewEffects = SuspiciousStewEffects.EMPTY;
|
|
}
|
|
- SuspiciousStewEffects.Entry recordSuspiciousEffect = new SuspiciousStewEffects.Entry(minecraftPotionEffect.getEffect(), minecraftPotionEffect.getDuration());
|
|
- this.removeEffectFromNextStew(potionEffect.getType()); // Avoid duplicates of effects
|
|
+ SuspiciousStewEffects.Entry recordSuspiciousEffect = new SuspiciousStewEffects.Entry(minecraftPotionEffect, suspiciousEffectEntry.duration()); // Paper - sus effect entry API
|
|
+ this.removeEffectFromNextStew(suspiciousEffectEntry.effect()); // Avoid duplicates of effects // Paper - sus effect entry API
|
|
this.getHandle().stewEffects = stewEffects.withEffectAdded(recordSuspiciousEffect);
|
|
return true;
|
|
}
|
|
@@ -101,6 +109,43 @@ public class CraftMushroomCow extends CraftCow implements MushroomCow, io.paperm
|
|
this.getHandle().setVariant(net.minecraft.world.entity.animal.MushroomCow.MushroomType.values()[variant.ordinal()]);
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public List<io.papermc.paper.potion.SuspiciousEffectEntry> getStewEffects() {
|
|
+ if (this.getHandle().stewEffects == null) {
|
|
+ return List.of();
|
|
+ }
|
|
+
|
|
+ final List<io.papermc.paper.potion.SuspiciousEffectEntry> effectEntries = new java.util.ArrayList<>(this.getHandle().stewEffects.effects().size());
|
|
+ for (final SuspiciousStewEffects.Entry effect : this.getHandle().stewEffects.effects()) {
|
|
+ effectEntries.add(io.papermc.paper.potion.SuspiciousEffectEntry.create(
|
|
+ org.bukkit.craftbukkit.potion.CraftPotionEffectType.minecraftHolderToBukkit(effect.effect()),
|
|
+ effect.duration()
|
|
+ ));
|
|
+ }
|
|
+
|
|
+ return java.util.Collections.unmodifiableList(effectEntries);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setStewEffects(final List<io.papermc.paper.potion.SuspiciousEffectEntry> effects) {
|
|
+ if (effects.isEmpty()) {
|
|
+ this.getHandle().stewEffects = null;
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ List<SuspiciousStewEffects.Entry> nmsPairs = new java.util.ArrayList<>(effects.size());
|
|
+ for (final io.papermc.paper.potion.SuspiciousEffectEntry effect : effects) {
|
|
+ nmsPairs.add(new SuspiciousStewEffects.Entry(
|
|
+ org.bukkit.craftbukkit.potion.CraftPotionEffectType.bukkitToMinecraftHolder(effect.effect()),
|
|
+ effect.duration()
|
|
+ ));
|
|
+ }
|
|
+
|
|
+ this.getHandle().stewEffects = new SuspiciousStewEffects(nmsPairs);
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public String toString() {
|
|
return "CraftMushroomCow";
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSuspiciousStew.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSuspiciousStew.java
|
|
index 8fc3cd507d333d2bdea759d7c102a56e88ad5f5a..14e944b4e83b80e0fc6d81e346cc305ab00561c5 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSuspiciousStew.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSuspiciousStew.java
|
|
@@ -22,7 +22,7 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
|
|
|
|
static final ItemMetaKeyType<SuspiciousStewEffects> EFFECTS = new ItemMetaKeyType<>(DataComponents.SUSPICIOUS_STEW_EFFECTS, "effects");
|
|
|
|
- private List<PotionEffect> customEffects;
|
|
+ private List<io.papermc.paper.potion.SuspiciousEffectEntry> customEffects; // Paper - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
|
|
|
|
CraftMetaSuspiciousStew(CraftMetaItem meta) {
|
|
super(meta);
|
|
@@ -48,7 +48,7 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
|
|
continue;
|
|
}
|
|
int duration = effect.duration();
|
|
- this.customEffects.add(new PotionEffect(type, duration, 0));
|
|
+ this.customEffects.add(io.papermc.paper.potion.SuspiciousEffectEntry.create(type, duration)); // Paper - use suspicious effect entry for suspicious stew meta
|
|
}
|
|
});
|
|
}
|
|
@@ -74,8 +74,8 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
|
|
if (this.customEffects != null) {
|
|
List<SuspiciousStewEffects.Entry> effectList = new ArrayList<>();
|
|
|
|
- for (PotionEffect effect : this.customEffects) {
|
|
- effectList.add(new net.minecraft.world.item.component.SuspiciousStewEffects.Entry(CraftPotionEffectType.bukkitToMinecraftHolder(effect.getType()), effect.getDuration()));
|
|
+ for (io.papermc.paper.potion.SuspiciousEffectEntry effect : this.customEffects) {
|
|
+ effectList.add(new net.minecraft.world.item.component.SuspiciousStewEffects.Entry(CraftPotionEffectType.bukkitToMinecraftHolder(effect.effect()), effect.duration())); // Paper - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
|
|
}
|
|
tag.put(CraftMetaSuspiciousStew.EFFECTS, new SuspiciousStewEffects(effectList));
|
|
}
|
|
@@ -112,7 +112,7 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
|
|
@Override
|
|
public List<PotionEffect> getCustomEffects() {
|
|
if (this.hasCustomEffects()) {
|
|
- return ImmutableList.copyOf(this.customEffects);
|
|
+ return this.customEffects.stream().map(suspiciousEffectEntry -> suspiciousEffectEntry.effect().createEffect(suspiciousEffectEntry.duration(), 0)).toList(); // Paper - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
|
|
}
|
|
return ImmutableList.of();
|
|
}
|
|
@@ -120,27 +120,47 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
|
|
@Override
|
|
public boolean addCustomEffect(PotionEffect effect, boolean overwrite) {
|
|
Preconditions.checkArgument(effect != null, "Potion effect cannot be null");
|
|
+ return addCustomEffect(io.papermc.paper.potion.SuspiciousEffectEntry.create(effect.getType(), effect.getDuration()), overwrite); // Paper - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
|
|
+ }
|
|
|
|
- int index = this.indexOfEffect(effect.getType());
|
|
- if (index != -1) {
|
|
- if (overwrite) {
|
|
- PotionEffect old = this.customEffects.get(index);
|
|
- if (old.getDuration() == effect.getDuration()) {
|
|
+ // Paper start - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
|
|
+ @Override
|
|
+ public boolean addCustomEffect(final io.papermc.paper.potion.SuspiciousEffectEntry suspiciousEffectEntry, final boolean overwrite) {
|
|
+ Preconditions.checkArgument(suspiciousEffectEntry != null, "Suspicious effect entry cannot be null");
|
|
+ if (this.hasCustomEffects()) {
|
|
+ final List<io.papermc.paper.potion.SuspiciousEffectEntry> matchingEffects = this.customEffects.stream().filter(
|
|
+ entry -> entry.effect() == suspiciousEffectEntry.effect()
|
|
+ ).toList();
|
|
+ if (!matchingEffects.isEmpty()) {
|
|
+ if (overwrite) {
|
|
+ boolean foundMatchingDuration = false;
|
|
+ boolean mutated = false;
|
|
+ for (final io.papermc.paper.potion.SuspiciousEffectEntry matchingEffect : matchingEffects) {
|
|
+ if (matchingEffect.duration() != suspiciousEffectEntry.duration()) {
|
|
+ this.customEffects.remove(suspiciousEffectEntry);
|
|
+ mutated = true;
|
|
+ } else {
|
|
+ foundMatchingDuration = true;
|
|
+ }
|
|
+ }
|
|
+ if (foundMatchingDuration && !mutated) {
|
|
+ return false;
|
|
+ } else if (!foundMatchingDuration) {
|
|
+ this.customEffects.add(suspiciousEffectEntry);
|
|
+ }
|
|
+ return true;
|
|
+ } else {
|
|
return false;
|
|
}
|
|
- this.customEffects.set(index, effect);
|
|
- return true;
|
|
- } else {
|
|
- return false;
|
|
}
|
|
- } else {
|
|
- if (this.customEffects == null) {
|
|
- this.customEffects = new ArrayList<>();
|
|
- }
|
|
- this.customEffects.add(effect);
|
|
- return true;
|
|
}
|
|
+ if (this.customEffects == null) {
|
|
+ this.customEffects = new ArrayList<>();
|
|
+ }
|
|
+ this.customEffects.add(suspiciousEffectEntry);
|
|
+ return true;
|
|
}
|
|
+ // Paper end - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
|
|
|
|
@Override
|
|
public boolean removeCustomEffect(PotionEffectType type) {
|
|
@@ -151,10 +171,12 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
|
|
}
|
|
|
|
boolean changed = false;
|
|
- Iterator<PotionEffect> iterator = this.customEffects.iterator();
|
|
+ // Paper start - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
|
|
+ Iterator<io.papermc.paper.potion.SuspiciousEffectEntry> iterator = this.customEffects.iterator();
|
|
while (iterator.hasNext()) {
|
|
- PotionEffect effect = iterator.next();
|
|
- if (type.equals(effect.getType())) {
|
|
+ io.papermc.paper.potion.SuspiciousEffectEntry effect = iterator.next();
|
|
+ if (type.equals(effect.effect())) {
|
|
+ // Paper end - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
|
|
iterator.remove();
|
|
changed = true;
|
|
}
|
|
@@ -177,7 +199,7 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
|
|
}
|
|
|
|
for (int i = 0; i < this.customEffects.size(); i++) {
|
|
- if (this.customEffects.get(i).getType().equals(type)) {
|
|
+ if (this.customEffects.get(i).effect().equals(type)) { // Paper - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
|
|
return i;
|
|
}
|
|
}
|
|
@@ -222,7 +244,7 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
|
|
super.serialize(builder);
|
|
|
|
if (this.hasCustomEffects()) {
|
|
- builder.put(CraftMetaSuspiciousStew.EFFECTS.BUKKIT, ImmutableList.copyOf(this.customEffects));
|
|
+ builder.put(CraftMetaSuspiciousStew.EFFECTS.BUKKIT, ImmutableList.copyOf(com.google.common.collect.Lists.transform(this.customEffects, s -> new PotionEffect(s.effect(), s.duration(), 0)))); // Paper - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta - convert back to potion effect for bukkit legacy item serialisation to maintain backwards compatibility for the written format.
|
|
}
|
|
|
|
return builder;
|