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
This commit is contained in:
Phillipp Glanz 2023-10-07 20:15:26 +02:00 committed by GitHub
parent a30cdb37d6
commit 28e97e8441
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,6 +33,7 @@ import org.bukkit.entity.Ageable;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Bat; import org.bukkit.entity.Bat;
import org.bukkit.entity.Boat; import org.bukkit.entity.Boat;
import org.bukkit.entity.Breedable;
import org.bukkit.entity.ChestedHorse; import org.bukkit.entity.ChestedHorse;
import org.bukkit.entity.EnderDragon; import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -165,7 +166,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
//this.horse.style = horse.getStyle(); //this.horse.style = horse.getStyle();
//this.horse.color = horse.getColor(); //this.horse.color = horse.getColor();
storeTameable(horse); storeTameable(horse);
storeAgeable(horse); storeBreedable(horse);
storeLiving(horse); storeLiving(horse);
storeInventory(horse); storeInventory(horse);
return; return;
@ -173,7 +174,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
// END INVENTORY HOLDER // // END INVENTORY HOLDER //
case "WOLF", "OCELOT" -> { case "WOLF", "OCELOT" -> {
storeTameable((Tameable) entity); storeTameable((Tameable) entity);
storeAgeable((Ageable) entity); storeBreedable((Breedable) entity);
storeLiving((LivingEntity) entity); storeLiving((LivingEntity) entity);
return; return;
} }
@ -187,18 +188,18 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
this.dataByte = (byte) 0; this.dataByte = (byte) 0;
} }
this.dataByte2 = sheep.getColor().getDyeData(); this.dataByte2 = sheep.getColor().getDyeData();
storeAgeable(sheep); storeBreedable(sheep);
storeLiving(sheep); storeLiving(sheep);
return; return;
} }
case "VILLAGER", "CHICKEN", "COW", "MUSHROOM_COW", "PIG", "TURTLE", "POLAR_BEAR" -> { case "VILLAGER", "CHICKEN", "COW", "MUSHROOM_COW", "PIG", "TURTLE", "POLAR_BEAR" -> {
storeAgeable((Ageable) entity); storeBreedable((Breedable) entity);
storeLiving((LivingEntity) entity); storeLiving((LivingEntity) entity);
return; return;
} }
case "RABBIT" -> { case "RABBIT" -> {
this.dataByte = getOrdinal(Rabbit.Type.values(), ((Rabbit) entity).getRabbitType()); this.dataByte = getOrdinal(Rabbit.Type.values(), ((Rabbit) entity).getRabbitType());
storeAgeable((Ageable) entity); storeBreedable((Breedable) entity);
storeLiving((LivingEntity) entity); storeLiving((LivingEntity) entity);
return; 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) { private void restoreAgeable(Ageable entity) {
if (!this.aged.adult) { if (!this.aged.adult) {
entity.setBaby(); 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) { public void storeAgeable(Ageable aged) {
this.aged = new AgeableStats(); this.aged = new AgeableStats();
this.aged.age = aged.getAge(); this.aged.age = aged.getAge();
@ -399,6 +410,29 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
this.aged.adult = aged.isAdult(); 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) { public void storeTameable(Tameable tamed) {
this.tamed = new TameableStats(); this.tamed = new TameableStats();
this.tamed.owner = tamed.getOwner(); this.tamed.owner = tamed.getOwner();
@ -502,7 +536,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
//horse.setStyle(this.horse.style); //horse.setStyle(this.horse.style);
//horse.setColor(this.horse.color); //horse.setColor(this.horse.color);
restoreTameable(horse); restoreTameable(horse);
restoreAgeable(horse); restoreBreedable(horse);
restoreLiving(horse); restoreLiving(horse);
restoreInventory(horse); restoreInventory(horse);
return entity; return entity;
@ -510,7 +544,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
// END INVENTORY HOLDER // // END INVENTORY HOLDER //
case "WOLF", "OCELOT" -> { case "WOLF", "OCELOT" -> {
restoreTameable((Tameable) entity); restoreTameable((Tameable) entity);
restoreAgeable((Ageable) entity); restoreBreedable((Breedable) entity);
restoreLiving((LivingEntity) entity); restoreLiving((LivingEntity) entity);
return entity; return entity;
} }
@ -523,12 +557,12 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
if (this.dataByte2 != 0) { if (this.dataByte2 != 0) {
sheep.setColor(DyeColor.getByDyeData(this.dataByte2)); sheep.setColor(DyeColor.getByDyeData(this.dataByte2));
} }
restoreAgeable(sheep); restoreBreedable(sheep);
restoreLiving(sheep); restoreLiving(sheep);
return sheep; return sheep;
} }
case "VILLAGER", "CHICKEN", "COW", "TURTLE", "POLAR_BEAR", "MUSHROOM_COW", "PIG" -> { case "VILLAGER", "CHICKEN", "COW", "TURTLE", "POLAR_BEAR", "MUSHROOM_COW", "PIG" -> {
restoreAgeable((Ageable) entity); restoreBreedable((Breedable) entity);
restoreLiving((LivingEntity) entity); restoreLiving((LivingEntity) entity);
return entity; return entity;
} }
@ -537,7 +571,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
if (this.dataByte != 0) { if (this.dataByte != 0) {
((Rabbit) entity).setRabbitType(Rabbit.Type.values()[this.dataByte]); ((Rabbit) entity).setRabbitType(Rabbit.Type.values()[this.dataByte]);
} }
restoreAgeable((Ageable) entity); restoreBreedable((Breedable) entity);
restoreLiving((LivingEntity) entity); restoreLiving((LivingEntity) entity);
return entity; return entity;
} }