From 1ccc2eae6d11c98b7f971a1e07627d5b8142733a Mon Sep 17 00:00:00 2001 From: fullwall Date: Thu, 8 Sep 2022 13:28:14 +0800 Subject: [PATCH] Adjust /npc wither charged -> invulnerable, add arrow-shield --- .../citizensnpcs/commands/NPCCommands.java | 13 +++++--- .../net/citizensnpcs/trait/WitherTrait.java | 31 ++++++++++++++----- .../main/java/net/citizensnpcs/util/NMS.java | 2 +- .../nms/v1_10_R1/entity/WitherController.java | 6 ++++ .../nms/v1_11_R1/entity/WitherController.java | 6 ++++ .../nms/v1_12_R1/entity/WitherController.java | 6 ++++ .../nms/v1_13_R2/entity/WitherController.java | 6 ++++ .../nms/v1_14_R1/entity/WitherController.java | 6 ++++ .../nms/v1_15_R1/entity/WitherController.java | 6 ++++ .../nms/v1_16_R3/entity/WitherController.java | 6 ++++ .../nms/v1_17_R1/entity/WitherController.java | 6 ++++ .../nms/v1_18_R2/entity/WitherController.java | 6 ++++ .../nms/v1_19_R1/entity/WitherController.java | 6 ++++ .../nms/v1_8_R3/entity/WitherController.java | 6 ++++ 14 files changed, 98 insertions(+), 14 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java index 00c0bc42c..8ddaa1696 100644 --- a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -2804,7 +2804,7 @@ public class NPCCommands { @Command( aliases = { "npc" }, - usage = "wither (--charged [charged])", + usage = "wither (--invulnerable [true|false]) (--arrow-shield [true|false])", desc = "Sets wither modifiers", modifiers = { "wither" }, min = 1, @@ -2812,11 +2812,14 @@ public class NPCCommands { max = 1, permission = "citizens.npc.wither") @Requirements(selected = true, ownership = true, types = { EntityType.WITHER }) - public void wither(CommandContext args, CommandSender sender, NPC npc, @Flag("charged") Boolean charged) - throws CommandException { + public void wither(CommandContext args, CommandSender sender, NPC npc, @Flag("invulnerable") Boolean invulnerable, + @Flag("arrow-shield") Boolean arrows) throws CommandException { WitherTrait trait = npc.getOrAddTrait(WitherTrait.class); - if (charged != null) { - trait.setCharged(charged); + if (invulnerable != null) { + trait.setInvulnerable(invulnerable); + } + if (arrows != null) { + trait.setBlocksArrows(arrows); } } diff --git a/main/src/main/java/net/citizensnpcs/trait/WitherTrait.java b/main/src/main/java/net/citizensnpcs/trait/WitherTrait.java index 6fc8c472c..2f8556062 100644 --- a/main/src/main/java/net/citizensnpcs/trait/WitherTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/WitherTrait.java @@ -14,26 +14,41 @@ import net.citizensnpcs.util.NMS; */ @TraitName("withertrait") public class WitherTrait extends Trait { + @Persist("arrowshield") + private Boolean arrowShield; @Persist("charged") - private boolean charged = false; + private Boolean invulnerable; public WitherTrait() { super("withertrait"); } - public boolean isCharged() { - return charged; + public Boolean blocksArrows() { + return arrowShield; + } + + public boolean isInvulnerable() { + return invulnerable == null ? npc.isProtected() : invulnerable; } @Override public void run() { - if (npc.getEntity() instanceof Wither) { - Wither wither = (Wither) npc.getEntity(); - NMS.setWitherCharged(wither, charged); + if (!(npc.getEntity() instanceof Wither)) + return; + Wither wither = (Wither) npc.getEntity(); + NMS.setWitherInvulnerable(wither, invulnerable == null ? npc.isProtected() : invulnerable); + if (arrowShield != null) { + npc.data().set("wither-arrow-shield", arrowShield); + } else { + npc.data().remove("wither-arrow-shield"); } } - public void setCharged(boolean charged) { - this.charged = charged; + public void setBlocksArrows(boolean arrowShield) { + this.arrowShield = arrowShield; + } + + public void setInvulnerable(boolean invulnerable) { + this.invulnerable = invulnerable; } } diff --git a/main/src/main/java/net/citizensnpcs/util/NMS.java b/main/src/main/java/net/citizensnpcs/util/NMS.java index 5ab471d4c..fcbda9e52 100644 --- a/main/src/main/java/net/citizensnpcs/util/NMS.java +++ b/main/src/main/java/net/citizensnpcs/util/NMS.java @@ -607,7 +607,7 @@ public class NMS { BRIDGE.setVerticalMovement(bukkitEntity, d); } - public static void setWitherCharged(Wither wither, boolean charged) { + public static void setWitherInvulnerable(Wither wither, boolean charged) { BRIDGE.setWitherCharged(wither, charged); } diff --git a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/entity/WitherController.java b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/entity/WitherController.java index 85c3cf260..a2cf89f96 100644 --- a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/entity/WitherController.java +++ b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/entity/WitherController.java @@ -64,6 +64,12 @@ public class WitherController extends MobEntityController { return npc == null ? super.d(save) : false; } + @Override + public boolean df() { + return npc == null || !npc.data().has("wither-arrow-damageable") ? super.df() + : npc.data().get("wither-arrow-damageable"); + } + @Override public void enderTeleportTo(double d0, double d1, double d2) { if (npc == null) diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/WitherController.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/WitherController.java index bb806f637..223f3ecba 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/WitherController.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/WitherController.java @@ -64,6 +64,12 @@ public class WitherController extends MobEntityController { return npc == null ? super.d(save) : false; } + @Override + public boolean di() { + return npc == null || !npc.data().has("wither-arrow-damageable") ? super.di() + : npc.data().get("wither-arrow-damageable"); + } + @Override public void enderTeleportTo(double d0, double d1, double d2) { if (npc == null) diff --git a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/entity/WitherController.java b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/entity/WitherController.java index d7c26d0a7..f2f4da61a 100644 --- a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/entity/WitherController.java +++ b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/entity/WitherController.java @@ -65,6 +65,12 @@ public class WitherController extends MobEntityController { return npc == null ? super.d(save) : false; } + @Override + public boolean dn() { + return npc == null || !npc.data().has("wither-arrow-damageable") ? super.dn() + : npc.data().get("wither-arrow-damageable"); + } + @Override public void enderTeleportTo(double d0, double d1, double d2) { if (npc == null) { diff --git a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/WitherController.java b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/WitherController.java index 8ae2a6968..1fd574a0d 100644 --- a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/WitherController.java +++ b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/WitherController.java @@ -73,6 +73,12 @@ public class WitherController extends MobEntityController { return NMSImpl.getSoundEffect(npc, super.D(), NPC.AMBIENT_SOUND_METADATA); } + @Override + public boolean dA() { + return npc == null || !npc.data().has("wither-arrow-damageable") ? super.dA() + : npc.data().get("wither-arrow-damageable"); + } + @Override public void enderTeleportTo(double d0, double d1, double d2) { if (npc == null) { diff --git a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/WitherController.java b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/WitherController.java index c3b45d6be..fa78649e8 100644 --- a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/WitherController.java +++ b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/WitherController.java @@ -66,6 +66,12 @@ public class WitherController extends MobEntityController { return npc == null ? super.d(save) : false; } + @Override + public boolean dW() { + return npc == null || !npc.data().has("wither-arrow-damageable") ? super.dW() + : npc.data().get("wither-arrow-damageable"); + } + @Override public void enderTeleportTo(double d0, double d1, double d2) { if (npc == null) { diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/WitherController.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/WitherController.java index a96ad77c7..9752acc2b 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/WitherController.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/WitherController.java @@ -129,6 +129,12 @@ public class WitherController extends MobEntityController { return false; // shouldLeash } + @Override + public boolean J_() { + return npc == null || !npc.data().has("wither-arrow-damageable") ? super.J_() + : npc.data().get("wither-arrow-damageable"); + } + @Override public int l(int i) { return npc == null ? super.l(i) : 0; diff --git a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/WitherController.java b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/WitherController.java index 9a3e6ea0b..50d400ad8 100644 --- a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/WitherController.java +++ b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/WitherController.java @@ -154,6 +154,12 @@ public class WitherController extends MobEntityController { } return super.n(entity); } + + @Override + public boolean S_() { + return npc == null || !npc.data().has("wither-arrow-damageable") ? super.S_() + : npc.data().get("wither-arrow-damageable"); + } } public static class WitherNPC extends CraftWither implements ForwardingNPCHolder { diff --git a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/entity/WitherController.java b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/entity/WitherController.java index 21ca2878a..9ffcee1c3 100644 --- a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/entity/WitherController.java +++ b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/entity/WitherController.java @@ -132,6 +132,12 @@ public class WitherController extends MobEntityController { return false; // shouldLeash } + @Override + public boolean isPowered() { + return npc == null || !npc.data().has("wither-arrow-damageable") ? super.isPowered() + : npc.data().get("wither-arrow-damageable"); + } + @Override public void push(double x, double y, double z) { Vector vector = Util.callPushEvent(npc, x, y, z); diff --git a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/entity/WitherController.java b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/entity/WitherController.java index 761d49d7e..3d6fba8a5 100644 --- a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/entity/WitherController.java +++ b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/entity/WitherController.java @@ -134,6 +134,12 @@ public class WitherController extends MobEntityController { return false; // shouldLeash } + @Override + public boolean isPowered() { + return npc == null || !npc.data().has("wither-arrow-damageable") ? super.isPowered() + : npc.data().get("wither-arrow-damageable"); + } + @Override public void push(double x, double y, double z) { Vector vector = Util.callPushEvent(npc, x, y, z); diff --git a/v1_19_R1/src/main/java/net/citizensnpcs/nms/v1_19_R1/entity/WitherController.java b/v1_19_R1/src/main/java/net/citizensnpcs/nms/v1_19_R1/entity/WitherController.java index fce0360ae..f272c5354 100644 --- a/v1_19_R1/src/main/java/net/citizensnpcs/nms/v1_19_R1/entity/WitherController.java +++ b/v1_19_R1/src/main/java/net/citizensnpcs/nms/v1_19_R1/entity/WitherController.java @@ -126,6 +126,12 @@ public class WitherController extends MobEntityController { return NMSImpl.isLeashed(this, super.isLeashed()); } + @Override + public boolean isPowered() { + return npc == null || !npc.data().has("wither-arrow-damageable") ? super.isPowered() + : npc.data().get("wither-arrow-damageable"); + } + @Override public void push(double x, double y, double z) { Vector vector = Util.callPushEvent(npc, x, y, z); diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/WitherController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/WitherController.java index 1507534bf..f8f15fafa 100644 --- a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/WitherController.java +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/WitherController.java @@ -62,6 +62,12 @@ public class WitherController extends MobEntityController { return false; // shouldLeash } + @Override + public boolean cm() { + return npc == null || !npc.data().has("wither-arrow-damageable") ? super.cm() + : npc.data(). get("wither-arrow-damageable"); + } + @Override public void collide(net.minecraft.server.v1_8_R3.Entity entity) { // this method is called by both the entities involved - cancelling