2017-12-30 08:36:36 +01:00
|
|
|
package net.citizensnpcs.trait;
|
|
|
|
|
|
|
|
import org.bukkit.entity.Wither;
|
|
|
|
|
|
|
|
import net.citizensnpcs.api.persistence.Persist;
|
|
|
|
import net.citizensnpcs.api.trait.Trait;
|
|
|
|
import net.citizensnpcs.api.trait.TraitName;
|
|
|
|
import net.citizensnpcs.util.NMS;
|
|
|
|
|
2019-05-16 13:58:29 +02:00
|
|
|
/**
|
|
|
|
* Persists {@link Wither} metadata.
|
|
|
|
*
|
|
|
|
* @see Wither
|
|
|
|
*/
|
2017-12-30 08:36:36 +01:00
|
|
|
@TraitName("withertrait")
|
|
|
|
public class WitherTrait extends Trait {
|
2022-09-08 07:28:14 +02:00
|
|
|
@Persist("arrowshield")
|
|
|
|
private Boolean arrowShield;
|
2017-12-30 08:36:36 +01:00
|
|
|
@Persist("charged")
|
2022-09-08 07:28:14 +02:00
|
|
|
private Boolean invulnerable;
|
2024-03-31 17:10:01 +02:00
|
|
|
@Persist("invulnerableticks")
|
|
|
|
private Integer invulnerableTicks;
|
2017-12-30 08:36:36 +01:00
|
|
|
|
|
|
|
public WitherTrait() {
|
|
|
|
super("withertrait");
|
|
|
|
}
|
|
|
|
|
2022-09-08 07:28:14 +02:00
|
|
|
public Boolean blocksArrows() {
|
|
|
|
return arrowShield;
|
|
|
|
}
|
|
|
|
|
2024-03-31 17:10:01 +02:00
|
|
|
public Integer getInvulnerableTicks() {
|
|
|
|
return invulnerableTicks;
|
|
|
|
}
|
|
|
|
|
2022-09-08 07:28:14 +02:00
|
|
|
public boolean isInvulnerable() {
|
2024-03-31 17:10:01 +02:00
|
|
|
if (invulnerable != null)
|
|
|
|
return invulnerable;
|
|
|
|
if (invulnerableTicks != null)
|
|
|
|
return invulnerableTicks > 0;
|
|
|
|
return npc.isProtected();
|
2017-12-30 08:36:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2022-09-08 07:28:14 +02:00
|
|
|
if (!(npc.getEntity() instanceof Wither))
|
|
|
|
return;
|
|
|
|
Wither wither = (Wither) npc.getEntity();
|
2024-03-31 17:10:01 +02:00
|
|
|
if (invulnerable != null) {
|
|
|
|
NMS.setWitherInvulnerableTicks(wither, invulnerable ? 20 : 0);
|
|
|
|
} else if (invulnerableTicks != null) {
|
|
|
|
NMS.setWitherInvulnerableTicks(wither, invulnerableTicks);
|
|
|
|
} else {
|
|
|
|
NMS.setWitherInvulnerableTicks(wither, npc.isProtected() ? 20 : 0);
|
|
|
|
}
|
2022-09-08 07:28:14 +02:00
|
|
|
if (arrowShield != null) {
|
|
|
|
npc.data().set("wither-arrow-shield", arrowShield);
|
|
|
|
} else {
|
|
|
|
npc.data().remove("wither-arrow-shield");
|
2017-12-30 08:36:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-08 07:28:14 +02:00
|
|
|
public void setBlocksArrows(boolean arrowShield) {
|
|
|
|
this.arrowShield = arrowShield;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setInvulnerable(boolean invulnerable) {
|
|
|
|
this.invulnerable = invulnerable;
|
2017-12-30 08:36:36 +01:00
|
|
|
}
|
2024-03-31 17:10:01 +02:00
|
|
|
|
|
|
|
public void setInvulnerableTicks(int ticks) {
|
|
|
|
this.invulnerableTicks = ticks;
|
|
|
|
}
|
2017-12-30 08:36:36 +01:00
|
|
|
}
|