Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 04:20:04 +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
171 Zeilen
8.1 KiB
Diff
171 Zeilen
8.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Tamion <70228790+notTamion@users.noreply.github.com>
|
|
Date: Sun, 5 Nov 2023 09:50:48 +0100
|
|
Subject: [PATCH] Add HiddenPotionEffect API
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/entity/LivingEntity.java b/src/main/java/org/bukkit/entity/LivingEntity.java
|
|
index 5f070c7563151c40cf4d691fc2a10d8a2766982a..b777e530122549455dcce6fac8d4a151c1c0af42 100644
|
|
--- a/src/main/java/org/bukkit/entity/LivingEntity.java
|
|
+++ b/src/main/java/org/bukkit/entity/LivingEntity.java
|
|
@@ -591,6 +591,9 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
|
|
|
|
/**
|
|
* Adds the given {@link PotionEffect} to the living entity.
|
|
+ * <p>
|
|
+ * Note: {@link PotionEffect#getHiddenPotionEffect()} is ignored when
|
|
+ * adding the effect to the entity.
|
|
*
|
|
* @param effect PotionEffect to be added
|
|
* @return whether the effect could be added
|
|
@@ -615,6 +618,9 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
|
|
/**
|
|
* Attempts to add all of the given {@link PotionEffect} to the living
|
|
* entity.
|
|
+ * <p>
|
|
+ * Note: {@link PotionEffect#getHiddenPotionEffect()} is ignored when
|
|
+ * adding the effect to the entity.
|
|
*
|
|
* @param effects the effects to add
|
|
* @return whether all of the effects could be added
|
|
diff --git a/src/main/java/org/bukkit/potion/PotionEffect.java b/src/main/java/org/bukkit/potion/PotionEffect.java
|
|
index 575156c089e45a3d6a43ca6b7adfbc7b473a60ab..704b6d615e7490d433b703f5a6a8d3c40aa6425e 100644
|
|
--- a/src/main/java/org/bukkit/potion/PotionEffect.java
|
|
+++ b/src/main/java/org/bukkit/potion/PotionEffect.java
|
|
@@ -28,6 +28,7 @@ public class PotionEffect implements ConfigurationSerializable {
|
|
*/
|
|
public static final int INFINITE_DURATION = -1;
|
|
|
|
+ private static final String HIDDEN_EFFECT = "hidden_effect"; // Paper
|
|
private static final String AMPLIFIER = "amplifier";
|
|
private static final String DURATION = "duration";
|
|
private static final String TYPE = "effect";
|
|
@@ -40,6 +41,7 @@ public class PotionEffect implements ConfigurationSerializable {
|
|
private final boolean ambient;
|
|
private final boolean particles;
|
|
private final boolean icon;
|
|
+ private final PotionEffect hiddenEffect; // Paper
|
|
|
|
/**
|
|
* Creates a potion effect.
|
|
@@ -50,8 +52,11 @@ public class PotionEffect implements ConfigurationSerializable {
|
|
* @param ambient the ambient status, see {@link PotionEffect#isAmbient()}
|
|
* @param particles the particle status, see {@link PotionEffect#hasParticles()}
|
|
* @param icon the icon status, see {@link PotionEffect#hasIcon()}
|
|
+ * @param hiddenEffect the hidden PotionEffect
|
|
+ * @hidden Internal-- hidden effects are only shown internally
|
|
*/
|
|
- public PotionEffect(@NotNull PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles, boolean icon) {
|
|
+ @org.jetbrains.annotations.ApiStatus.Internal // Paper
|
|
+ public PotionEffect(@NotNull PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles, boolean icon, @Nullable PotionEffect hiddenEffect) { // Paper
|
|
Preconditions.checkArgument(type != null, "effect type cannot be null");
|
|
this.type = type;
|
|
this.duration = duration;
|
|
@@ -59,6 +64,23 @@ public class PotionEffect implements ConfigurationSerializable {
|
|
this.ambient = ambient;
|
|
this.particles = particles;
|
|
this.icon = icon;
|
|
+ // Paper start
|
|
+ this.hiddenEffect = hiddenEffect;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Creates a potion effect.
|
|
+ * @param type effect type
|
|
+ * @param duration measured in ticks, see {@link
|
|
+ * PotionEffect#getDuration()}
|
|
+ * @param amplifier the amplifier, see {@link PotionEffect#getAmplifier()}
|
|
+ * @param ambient the ambient status, see {@link PotionEffect#isAmbient()}
|
|
+ * @param particles the particle status, see {@link PotionEffect#hasParticles()}
|
|
+ * @param icon the icon status, see {@link PotionEffect#hasIcon()}
|
|
+ */
|
|
+ public PotionEffect(@NotNull PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles, boolean icon) {
|
|
+ this(type, duration, amplifier, ambient, particles, icon, null);
|
|
+ // Paper end
|
|
}
|
|
|
|
/**
|
|
@@ -106,7 +128,7 @@ public class PotionEffect implements ConfigurationSerializable {
|
|
* @param map the map to deserialize from
|
|
*/
|
|
public PotionEffect(@NotNull Map<String, Object> map) {
|
|
- this(getEffectType(map), getInt(map, DURATION), getInt(map, AMPLIFIER), getBool(map, AMBIENT, false), getBool(map, PARTICLES, true), getBool(map, ICON, getBool(map, PARTICLES, true)));
|
|
+ this(getEffectType(map), getInt(map, DURATION), getInt(map, AMPLIFIER), getBool(map, AMBIENT, false), getBool(map, PARTICLES, true), getBool(map, ICON, getBool(map, PARTICLES, true)), (PotionEffect) map.get(HIDDEN_EFFECT)); // Paper
|
|
}
|
|
|
|
// Paper start
|
|
@@ -134,6 +156,19 @@ public class PotionEffect implements ConfigurationSerializable {
|
|
public PotionEffect withIcon(boolean icon) {
|
|
return new PotionEffect(this.type, duration, amplifier, ambient, particles, icon);
|
|
}
|
|
+
|
|
+ /**
|
|
+ * Returns the PotionEffect that will become active
|
|
+ * after the current PotionEffect has run out.
|
|
+ * <p>
|
|
+ * Note: This value is only applicable to type applied to living entities.
|
|
+ *
|
|
+ * @return The hidden PotionEffect.
|
|
+ */
|
|
+ @Nullable
|
|
+ public PotionEffect getHiddenPotionEffect() {
|
|
+ return hiddenEffect;
|
|
+ }
|
|
// Paper end
|
|
|
|
@NotNull
|
|
@@ -170,19 +205,27 @@ public class PotionEffect implements ConfigurationSerializable {
|
|
@Override
|
|
@NotNull
|
|
public Map<String, Object> serialize() {
|
|
- return ImmutableMap.<String, Object>builder()
|
|
+ ImmutableMap.Builder<String, Object> builder = ImmutableMap.<String, Object>builder() // Paper
|
|
.put(TYPE, type.getKey().toString())
|
|
.put(DURATION, duration)
|
|
.put(AMPLIFIER, amplifier)
|
|
.put(AMBIENT, ambient)
|
|
.put(PARTICLES, particles)
|
|
- .put(ICON, icon)
|
|
- .build();
|
|
+ .put(ICON, icon);
|
|
+ // Paper start
|
|
+ if (this.hiddenEffect != null) {
|
|
+ builder.put(HIDDEN_EFFECT, this.hiddenEffect);
|
|
+ }
|
|
+ return builder.build();
|
|
+ // Paper end
|
|
}
|
|
|
|
/**
|
|
* Attempts to add the effect represented by this object to the given
|
|
* {@link LivingEntity}.
|
|
+ * <p>
|
|
+ * Note: {@link PotionEffect#getHiddenPotionEffect()} is ignored when
|
|
+ * adding the effect to the entity.
|
|
*
|
|
* @param entity The entity to add this effect to
|
|
* @return Whether the effect could be added
|
|
@@ -201,7 +244,7 @@ public class PotionEffect implements ConfigurationSerializable {
|
|
return false;
|
|
}
|
|
PotionEffect that = (PotionEffect) obj;
|
|
- return this.type.equals(that.type) && this.ambient == that.ambient && this.amplifier == that.amplifier && this.duration == that.duration && this.particles == that.particles && this.icon == that.icon;
|
|
+ return this.type.equals(that.type) && this.ambient == that.ambient && this.amplifier == that.amplifier && this.duration == that.duration && this.particles == that.particles && this.icon == that.icon && java.util.Objects.equals(this.hiddenEffect, that.hiddenEffect); // Paper
|
|
}
|
|
|
|
/**
|
|
@@ -306,11 +349,12 @@ public class PotionEffect implements ConfigurationSerializable {
|
|
hash ^= 0x22222222 >> (ambient ? 1 : -1);
|
|
hash ^= 0x22222222 >> (particles ? 1 : -1);
|
|
hash ^= 0x22222222 >> (icon ? 1 : -1);
|
|
+ if (hiddenEffect != null) hash = hash * 31 + hiddenEffect.hashCode(); // Paper
|
|
return hash;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
- return type.getName() + (ambient ? ":(" : ":") + duration + "t-x" + amplifier + (ambient ? ")" : "");
|
|
+ return "PotionEffect{" + "amplifier=" + amplifier + ", duration=" + duration + ", type=" + type + ", ambient=" + ambient + ", particles=" + particles + ", icon=" + icon + ", hiddenEffect=" + hiddenEffect + '}'; // Paper
|
|
}
|
|
}
|