From 28e97e844104a8841c7fe953ca48e0148cdacf5c Mon Sep 17 00:00:00 2001
From: Phillipp Glanz
Date: Sat, 7 Oct 2023 20:15:26 +0200
Subject: [PATCH] Replace deprecated ageable with breedable (#4193)
* [#4164] Replace deprecated ageable with breedable
* [#4164] Correct methods and usage based on issue
* [#4164] Add since tag to deprecated and new methods
* [#4164] Add to deprecated annotation since argument with todo value
* [#4164] Change since to todo for changed code
* [#4164] Change access of storeBreedable to private
---
.../entity/ReplicatingEntityWrapper.java | 54 +++++++++++++++----
1 file changed, 44 insertions(+), 10 deletions(-)
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java
index d8167333b..8b6951ab8 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java
@@ -33,6 +33,7 @@ import org.bukkit.entity.Ageable;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Bat;
import org.bukkit.entity.Boat;
+import org.bukkit.entity.Breedable;
import org.bukkit.entity.ChestedHorse;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity;
@@ -165,7 +166,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
//this.horse.style = horse.getStyle();
//this.horse.color = horse.getColor();
storeTameable(horse);
- storeAgeable(horse);
+ storeBreedable(horse);
storeLiving(horse);
storeInventory(horse);
return;
@@ -173,7 +174,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
// END INVENTORY HOLDER //
case "WOLF", "OCELOT" -> {
storeTameable((Tameable) entity);
- storeAgeable((Ageable) entity);
+ storeBreedable((Breedable) entity);
storeLiving((LivingEntity) entity);
return;
}
@@ -187,18 +188,18 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
this.dataByte = (byte) 0;
}
this.dataByte2 = sheep.getColor().getDyeData();
- storeAgeable(sheep);
+ storeBreedable(sheep);
storeLiving(sheep);
return;
}
case "VILLAGER", "CHICKEN", "COW", "MUSHROOM_COW", "PIG", "TURTLE", "POLAR_BEAR" -> {
- storeAgeable((Ageable) entity);
+ storeBreedable((Breedable) entity);
storeLiving((LivingEntity) entity);
return;
}
case "RABBIT" -> {
this.dataByte = getOrdinal(Rabbit.Type.values(), ((Rabbit) entity).getRabbitType());
- storeAgeable((Ageable) entity);
+ storeBreedable((Breedable) entity);
storeLiving((LivingEntity) entity);
return;
}
@@ -382,6 +383,11 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
}
}
+ /**
+ * @deprecated Use {@link #restoreBreedable(Breedable)} instead
+ * @since TODO
+ */
+ @Deprecated(forRemoval = true, since = "TODO")
private void restoreAgeable(Ageable entity) {
if (!this.aged.adult) {
entity.setBaby();
@@ -392,6 +398,11 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
}
}
+ /**
+ * @deprecated Use {@link #storeBreedable(Breedable)} instead
+ * @since TODO
+ */
+ @Deprecated(forRemoval = true, since = "TODO")
public void storeAgeable(Ageable aged) {
this.aged = new AgeableStats();
this.aged.age = aged.getAge();
@@ -399,6 +410,29 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
this.aged.adult = aged.isAdult();
}
+ /**
+ * @since TODO
+ */
+ private void restoreBreedable(Breedable entity) {
+ if (!this.aged.adult) {
+ entity.setBaby();
+ }
+ entity.setAgeLock(this.aged.locked);
+ if (this.aged.age > 0) {
+ entity.setAge(this.aged.age);
+ }
+ }
+
+ /**
+ * @since TODO
+ */
+ private void storeBreedable(Breedable breedable) {
+ this.aged = new AgeableStats();
+ this.aged.age = breedable.getAge();
+ this.aged.locked = breedable.getAgeLock();
+ this.aged.adult = breedable.isAdult();
+ }
+
public void storeTameable(Tameable tamed) {
this.tamed = new TameableStats();
this.tamed.owner = tamed.getOwner();
@@ -502,7 +536,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
//horse.setStyle(this.horse.style);
//horse.setColor(this.horse.color);
restoreTameable(horse);
- restoreAgeable(horse);
+ restoreBreedable(horse);
restoreLiving(horse);
restoreInventory(horse);
return entity;
@@ -510,7 +544,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
// END INVENTORY HOLDER //
case "WOLF", "OCELOT" -> {
restoreTameable((Tameable) entity);
- restoreAgeable((Ageable) entity);
+ restoreBreedable((Breedable) entity);
restoreLiving((LivingEntity) entity);
return entity;
}
@@ -523,12 +557,12 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
if (this.dataByte2 != 0) {
sheep.setColor(DyeColor.getByDyeData(this.dataByte2));
}
- restoreAgeable(sheep);
+ restoreBreedable(sheep);
restoreLiving(sheep);
return sheep;
}
case "VILLAGER", "CHICKEN", "COW", "TURTLE", "POLAR_BEAR", "MUSHROOM_COW", "PIG" -> {
- restoreAgeable((Ageable) entity);
+ restoreBreedable((Breedable) entity);
restoreLiving((LivingEntity) entity);
return entity;
}
@@ -537,7 +571,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
if (this.dataByte != 0) {
((Rabbit) entity).setRabbitType(Rabbit.Type.values()[this.dataByte]);
}
- restoreAgeable((Ageable) entity);
+ restoreBreedable((Breedable) entity);
restoreLiving((LivingEntity) entity);
return entity;
}