Skip to content

Commit

Permalink
Fix double updating bee/bat/ghast AI
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jul 5, 2022
1 parent dfbdfae commit 35dd407
Show file tree
Hide file tree
Showing 25 changed files with 45 additions and 67 deletions.
4 changes: 2 additions & 2 deletions main/src/main/java/net/citizensnpcs/EventListen.java
Expand Up @@ -613,7 +613,7 @@ public void onVehicleDamage(VehicleDamageEvent event) {
if (npc == null) {
return;
}
event.setCancelled(npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true));
event.setCancelled(npc.isProtected());

NPCVehicleDamageEvent damageEvent = new NPCVehicleDamageEvent(npc, event);
Bukkit.getPluginManager().callEvent(damageEvent);
Expand All @@ -635,7 +635,7 @@ public void onVehicleDestroy(VehicleDestroyEvent event) {
if (npc == null) {
return;
}
event.setCancelled(npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true));
event.setCancelled(npc.isProtected());
}

@EventHandler(ignoreCancelled = true)
Expand Down
10 changes: 5 additions & 5 deletions main/src/main/java/net/citizensnpcs/commands/NPCCommands.java
Expand Up @@ -2494,15 +2494,15 @@ public void target(CommandContext args, Player sender, NPC npc) {

@Command(
aliases = { "npc" },
usage = "targetable",
usage = "targetable (-t(emporary))",
desc = "Toggles an NPC's targetability",
modifiers = { "targetable" },
min = 1,
max = 1,
flags = "t",
permission = "citizens.npc.targetable")
public void targetable(CommandContext args, CommandSender sender, NPC npc) {
boolean targetable = !npc.data().get(NPC.TARGETABLE_METADATA,
npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true));
boolean targetable = !npc.data().get(NPC.TARGETABLE_METADATA, npc.isProtected());
if (args.hasFlag('t')) {
npc.data().set(NPC.TARGETABLE_METADATA, targetable);
} else {
Expand Down Expand Up @@ -2688,15 +2688,15 @@ public void useitem(CommandContext args, CommandSender sender, NPC npc) throws C

@Command(
aliases = { "npc" },
usage = "vulnerable (-t)",
usage = "vulnerable (-t(emporary))",
desc = "Toggles an NPC's vulnerability",
modifiers = { "vulnerable" },
min = 1,
max = 1,
flags = "t",
permission = "citizens.npc.vulnerable")
public void vulnerable(CommandContext args, CommandSender sender, NPC npc) {
boolean vulnerable = !npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
boolean vulnerable = !npc.isProtected();
if (args.hasFlag('t')) {
npc.data().set(NPC.DEFAULT_PROTECTED_METADATA, vulnerable);
} else {
Expand Down
Expand Up @@ -183,8 +183,9 @@ public boolean isLeashed() {
@Override
public void mobTick() {
super.mobTick();
if (npc != null)
if (npc != null) {
npc.update();
}
}

@Override
Expand Down
Expand Up @@ -154,8 +154,8 @@ public void mobTick() {
super.mobTick();
} else {
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
if (npc.useMinecraftAI()) {
super.mobTick();
}
npc.update();
}
Expand Down
Expand Up @@ -153,10 +153,9 @@ public void mobTick() {
super.mobTick();
} else {
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
if (npc.useMinecraftAI()) {
super.mobTick();
}
NMSImpl.updateAI(this);
npc.update();
}
}
Expand Down
Expand Up @@ -184,9 +184,10 @@ public boolean isLeashed() {
@Override
public void mobTick() {
super.mobTick();
if (npc != null)
if (npc != null) {
NMSImpl.updateMinecraftAIState(npc, this);
npc.update();
npc.update();
}
}

@Override
Expand Down
Expand Up @@ -142,9 +142,6 @@ public void mobTick() {
if (npc != null) {
npc.update();
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
}
}
super.mobTick();
}
Expand Down
Expand Up @@ -147,8 +147,8 @@ public void mobTick() {
super.mobTick();
} else {
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
if (npc.useMinecraftAI()) {
super.mobTick();
}
npc.update();
}
Expand Down
Expand Up @@ -146,10 +146,9 @@ public void mobTick() {
super.mobTick();
} else {
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
if (npc.useMinecraftAI()) {
super.mobTick();
}
NMSImpl.updateAI(this);
npc.update();
}
}
Expand Down
Expand Up @@ -177,9 +177,10 @@ public boolean isLeashed() {
@Override
public void mobTick() {
super.mobTick();
if (npc != null)
if (npc != null) {
NMSImpl.updateMinecraftAIState(npc, this);
npc.update();
npc.update();
}
}

@Override
Expand Down
Expand Up @@ -143,9 +143,6 @@ public void mobTick() {
if (npc != null) {
npc.update();
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
}
}
super.mobTick();
}
Expand Down
Expand Up @@ -76,8 +76,8 @@ public void customServerAiStep() {
super.customServerAiStep();
} else {
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
if (npc.useMinecraftAI()) {
super.customServerAiStep();
}
npc.update();
}
Expand Down
Expand Up @@ -75,10 +75,9 @@ public void customServerAiStep() {
super.customServerAiStep();
} else {
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
if (npc.useMinecraftAI()) {
super.customServerAiStep();
}
NMSImpl.updateAI(this);
npc.update();
}
}
Expand Down
Expand Up @@ -90,9 +90,10 @@ protected void checkFallDamage(double d0, boolean flag, BlockState iblockdata, B
@Override
public void customServerAiStep() {
super.customServerAiStep();
if (npc != null)
if (npc != null) {
NMSImpl.updateMinecraftAIState(npc, this);
npc.update();
npc.update();
}
}

@Override
Expand Down
Expand Up @@ -68,9 +68,6 @@ public void customServerAiStep() {
if (npc != null) {
npc.update();
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
}
}
super.customServerAiStep();
}
Expand Down
Expand Up @@ -78,8 +78,8 @@ public void customServerAiStep() {
super.customServerAiStep();
} else {
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
if (npc.useMinecraftAI()) {
super.customServerAiStep();
}
npc.update();
}
Expand Down
Expand Up @@ -77,10 +77,9 @@ public void customServerAiStep() {
super.customServerAiStep();
} else {
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
if (npc.useMinecraftAI()) {
super.customServerAiStep();
}
NMSImpl.updateAI(this);
npc.update();
}
}
Expand Down
Expand Up @@ -95,10 +95,6 @@ protected void checkFallDamage(double d0, boolean flag, BlockState iblockdata, B
public void customServerAiStep() {
super.customServerAiStep();
if (npc != null) {
try {
} catch (Throwable e) {
e.printStackTrace();
}
NMSImpl.updateMinecraftAIState(npc, this);
npc.update();
}
Expand Down
Expand Up @@ -91,9 +91,10 @@ protected void checkFallDamage(double d0, boolean flag, BlockState iblockdata, B
@Override
public void customServerAiStep() {
super.customServerAiStep();
if (npc != null)
if (npc != null) {
NMSImpl.updateMinecraftAIState(npc, this);
npc.update();
npc.update();
}
}

@Override
Expand Down
Expand Up @@ -70,9 +70,6 @@ public void customServerAiStep() {
if (npc != null) {
npc.update();
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
}
}
super.customServerAiStep();
}
Expand Down
Expand Up @@ -78,8 +78,8 @@ public void customServerAiStep() {
super.customServerAiStep();
} else {
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
if (npc.useMinecraftAI()) {
super.customServerAiStep();
}
npc.update();
}
Expand Down
Expand Up @@ -77,10 +77,9 @@ public void customServerAiStep() {
super.customServerAiStep();
} else {
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
if (npc.useMinecraftAI()) {
super.customServerAiStep();
}
NMSImpl.updateAI(this);
npc.update();
}
}
Expand Down
Expand Up @@ -95,10 +95,6 @@ protected void checkFallDamage(double d0, boolean flag, BlockState iblockdata, B
public void customServerAiStep() {
super.customServerAiStep();
if (npc != null) {
try {
} catch (Throwable e) {
e.printStackTrace();
}
NMSImpl.updateMinecraftAIState(npc, this);
npc.update();
}
Expand Down
Expand Up @@ -91,9 +91,10 @@ protected void checkFallDamage(double d0, boolean flag, BlockState iblockdata, B
@Override
public void customServerAiStep() {
super.customServerAiStep();
if (npc != null)
if (npc != null) {
NMSImpl.updateMinecraftAIState(npc, this);
npc.update();
npc.update();
}
}

@Override
Expand Down
Expand Up @@ -69,10 +69,7 @@ public void checkDespawn() {
public void customServerAiStep() {
if (npc != null) {
npc.update();
NMSImpl.updateMinecraftAIState(npc, this);
if (!npc.useMinecraftAI()) {
NMSImpl.updateAI(this);
}
NMSImpl.updateMinecraftAIState(npc, this);
}
super.customServerAiStep();
}
Expand Down

0 comments on commit 35dd407

Please sign in to comment.