mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 02:25:57 +01:00
Add /npc wither --invulnerableticks command
This commit is contained in:
parent
8cf37b0ecc
commit
9729e356a5
@ -3422,7 +3422,7 @@ public class NPCCommands {
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "wither (--invulnerable [true|false]) (--arrow-shield [true|false])",
|
||||
usage = "wither (--invulnerable [true|false]) (--invulnerable-ticks [ticks]) (--arrow-shield [true|false])",
|
||||
desc = "",
|
||||
modifiers = { "wither" },
|
||||
min = 1,
|
||||
@ -3431,11 +3431,15 @@ public class NPCCommands {
|
||||
permission = "citizens.npc.wither")
|
||||
@Requirements(selected = true, ownership = true, types = { EntityType.WITHER })
|
||||
public void wither(CommandContext args, CommandSender sender, NPC npc, @Flag("invulnerable") Boolean invulnerable,
|
||||
@Flag("arrow-shield") Boolean arrows) throws CommandException {
|
||||
@Flag("arrow-shield") Boolean arrows, @Flag("invulnerable-ticks") Integer invulnerableTicks)
|
||||
throws CommandException {
|
||||
WitherTrait trait = npc.getOrAddTrait(WitherTrait.class);
|
||||
if (invulnerable != null) {
|
||||
trait.setInvulnerable(invulnerable);
|
||||
}
|
||||
if (invulnerableTicks != null) {
|
||||
trait.setInvulnerableTicks(invulnerableTicks);
|
||||
}
|
||||
if (arrows != null) {
|
||||
trait.setBlocksArrows(arrows);
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ public class WitherTrait extends Trait {
|
||||
private Boolean arrowShield;
|
||||
@Persist("charged")
|
||||
private Boolean invulnerable;
|
||||
@Persist("invulnerableticks")
|
||||
private Integer invulnerableTicks;
|
||||
|
||||
public WitherTrait() {
|
||||
super("withertrait");
|
||||
@ -27,8 +29,16 @@ public class WitherTrait extends Trait {
|
||||
return arrowShield;
|
||||
}
|
||||
|
||||
public Integer getInvulnerableTicks() {
|
||||
return invulnerableTicks;
|
||||
}
|
||||
|
||||
public boolean isInvulnerable() {
|
||||
return invulnerable == null ? npc.isProtected() : invulnerable;
|
||||
if (invulnerable != null)
|
||||
return invulnerable;
|
||||
if (invulnerableTicks != null)
|
||||
return invulnerableTicks > 0;
|
||||
return npc.isProtected();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -36,7 +46,13 @@ public class WitherTrait extends Trait {
|
||||
if (!(npc.getEntity() instanceof Wither))
|
||||
return;
|
||||
Wither wither = (Wither) npc.getEntity();
|
||||
NMS.setWitherInvulnerable(wither, invulnerable == null ? npc.isProtected() : invulnerable);
|
||||
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);
|
||||
}
|
||||
if (arrowShield != null) {
|
||||
npc.data().set("wither-arrow-shield", arrowShield);
|
||||
} else {
|
||||
@ -51,4 +67,8 @@ public class WitherTrait extends Trait {
|
||||
public void setInvulnerable(boolean invulnerable) {
|
||||
this.invulnerable = invulnerable;
|
||||
}
|
||||
|
||||
public void setInvulnerableTicks(int ticks) {
|
||||
this.invulnerableTicks = ticks;
|
||||
}
|
||||
}
|
||||
|
@ -914,8 +914,8 @@ public class NMS {
|
||||
BRIDGE.setWardenPose(entity, pose);
|
||||
}
|
||||
|
||||
public static void setWitherInvulnerable(Wither wither, boolean charged) {
|
||||
BRIDGE.setWitherCharged(wither, charged);
|
||||
public static void setWitherInvulnerableTicks(Wither wither, int ticks) {
|
||||
BRIDGE.setWitherInvulnerableTicks(wither, ticks);
|
||||
}
|
||||
|
||||
public static boolean shouldJump(org.bukkit.entity.Entity entity) {
|
||||
|
@ -271,7 +271,9 @@ public interface NMSBridge {
|
||||
public default void setWardenPose(Entity entity, Object pose) {
|
||||
}
|
||||
|
||||
public void setWitherCharged(Wither wither, boolean charged);
|
||||
public default void setWitherInvulnerableTicks(Wither wither, int ticks) {
|
||||
wither.setInvulnerabilityTicks(ticks);
|
||||
}
|
||||
|
||||
public boolean shouldJump(Entity entity);
|
||||
|
||||
|
@ -1334,9 +1334,9 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWitherCharged(Wither wither, boolean charged) {
|
||||
public void setWitherInvulnerableTicks(Wither wither, int ticks) {
|
||||
EntityWither handle = ((CraftWither) wither).getHandle();
|
||||
handle.g(charged ? 20 : 0);
|
||||
handle.g(ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1387,9 +1387,9 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWitherCharged(Wither wither, boolean charged) {
|
||||
public void setWitherInvulnerableTicks(Wither wither, int ticks) {
|
||||
EntityWither handle = ((CraftWither) wither).getHandle();
|
||||
handle.g(charged ? 20 : 0);
|
||||
handle.g(ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1394,9 +1394,9 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWitherCharged(Wither wither, boolean charged) {
|
||||
public void setWitherInvulnerableTicks(Wither wither, int ticks) {
|
||||
EntityWither handle = ((CraftWither) wither).getHandle();
|
||||
handle.g(charged ? 20 : 0);
|
||||
handle.g(ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1431,9 +1431,9 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWitherCharged(Wither wither, boolean charged) {
|
||||
public void setWitherInvulnerableTicks(Wither wither, int ticks) {
|
||||
EntityWither handle = ((CraftWither) wither).getHandle();
|
||||
handle.d(charged ? 20 : 0);
|
||||
handle.d(ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1490,9 +1490,9 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWitherCharged(Wither wither, boolean charged) {
|
||||
public void setWitherInvulnerableTicks(Wither wither, int ticks) {
|
||||
EntityWither handle = ((CraftWither) wither).getHandle();
|
||||
handle.r(charged ? 20 : 0);
|
||||
handle.r(ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1539,9 +1539,9 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWitherCharged(Wither wither, boolean charged) {
|
||||
public void setWitherInvulnerableTicks(Wither wither, int ticks) {
|
||||
EntityWither handle = ((CraftWither) wither).getHandle();
|
||||
handle.s(charged ? 20 : 0);
|
||||
handle.s(ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1563,9 +1563,9 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWitherCharged(Wither wither, boolean charged) {
|
||||
public void setWitherInvulnerableTicks(Wither wither, int ticks) {
|
||||
EntityWither handle = ((CraftWither) wither).getHandle();
|
||||
handle.setInvul(charged ? 20 : 0);
|
||||
handle.setInvul(ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1559,9 +1559,9 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWitherCharged(Wither wither, boolean charged) {
|
||||
public void setWitherInvulnerableTicks(Wither wither, int ticks) {
|
||||
WitherBoss handle = ((CraftWither) wither).getHandle();
|
||||
handle.setInvulnerableTicks(charged ? 20 : 0);
|
||||
handle.setInvulnerableTicks(ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1567,9 +1567,9 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWitherCharged(Wither wither, boolean charged) {
|
||||
public void setWitherInvulnerableTicks(Wither wither, int ticks) {
|
||||
WitherBoss handle = ((CraftWither) wither).getHandle();
|
||||
handle.setInvulnerableTicks(charged ? 20 : 0);
|
||||
handle.setInvulnerableTicks(ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1759,9 +1759,9 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWitherCharged(Wither wither, boolean charged) {
|
||||
public void setWitherInvulnerableTicks(Wither wither, int ticks) {
|
||||
WitherBoss handle = ((CraftWither) wither).getHandle();
|
||||
handle.setInvulnerableTicks(charged ? 20 : 0);
|
||||
handle.setInvulnerableTicks(ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,7 +34,6 @@ import org.bukkit.craftbukkit.v1_20_R3.boss.CraftBossBar;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.command.CraftBlockCommandSender;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftWither;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.event.CraftEventFactory;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.event.CraftPortalEvent;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventoryAnvil;
|
||||
@ -44,7 +43,6 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.FishHook;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.Wither;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
@ -1722,12 +1720,6 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWitherCharged(Wither wither, boolean charged) {
|
||||
WitherBoss handle = ((CraftWither) wither).getHandle();
|
||||
handle.setInvulnerableTicks(charged ? 20 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldJump(org.bukkit.entity.Entity entity) {
|
||||
if (JUMP_FIELD == null || !(entity instanceof org.bukkit.entity.LivingEntity))
|
||||
|
@ -1258,9 +1258,9 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWitherCharged(Wither wither, boolean charged) {
|
||||
public void setWitherInvulnerableTicks(Wither wither, int ticks) {
|
||||
EntityWither handle = ((CraftWither) wither).getHandle();
|
||||
handle.r(charged ? 20 : 0);
|
||||
handle.r(ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user