Skip to content

Commit

Permalink
replace HasAI NMS Module with spigot api method
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 23, 2020
1 parent faa27a0 commit 15b5345
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 98 deletions.
Expand Up @@ -80,18 +80,14 @@ public void setCarriedItem(Enderman entity, ItemStack item) {

public abstract void stopWalking(Entity entity);

public abstract void toggleAI(Entity entity, boolean hasAI);

public abstract boolean isAIDisabled(Entity entity);

public abstract double getSpeed(Entity entity);

public abstract void setSpeed(Entity entity, double speed);

public abstract void follow(final Entity target, final Entity follower, final double speed, final double lead,
final double maxRange, final boolean allowWander);

public abstract void walkTo(final Entity entity, Location location, double speed, final Runnable callback);
public abstract void walkTo(final LivingEntity entity, Location location, double speed, final Runnable callback);

public class EnforcePlayerHides implements Listener {

Expand Down
@@ -1,6 +1,5 @@
package com.denizenscript.denizen.objects.properties.entity;

import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.Mechanism;
Expand Down Expand Up @@ -40,7 +39,7 @@ private EntityAI(EntityTag ent) {

@Override
public String getPropertyString() {
return String.valueOf(!NMSHandler.getEntityHelper().isAIDisabled(entity.getBukkitEntity()));
return String.valueOf(entity.getLivingEntity().hasAI());
}

@Override
Expand All @@ -67,7 +66,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// Other programmatic methods of blocking AI might also not be accounted for by this tag.
// -->
if (attribute.startsWith("has_ai")) {
return new ElementTag(!NMSHandler.getEntityHelper().isAIDisabled(entity.getBukkitEntity()))
return new ElementTag(entity.getLivingEntity().hasAI())
.getObjectAttribute(attribute.fulfill(1));
}

Expand All @@ -88,7 +87,7 @@ public void adjust(Mechanism mechanism) {
// <EntityTag.has_ai>
// -->
if ((mechanism.matches("has_ai") || mechanism.matches("toggle_ai")) && mechanism.requireBoolean()) {
NMSHandler.getEntityHelper().toggleAI(entity.getBukkitEntity(), mechanism.getValue().asBoolean());
entity.getLivingEntity().setAI(mechanism.getValue().asBoolean());
}
}
}
Expand Up @@ -229,7 +229,7 @@ else if (shouldStop) {
}
else {
waitForEntities.add(entity);
NMSHandler.getEntityHelper().walkTo(entity.getBukkitEntity(), loc, speed != null ? speed.asDouble() : 0.2,
NMSHandler.getEntityHelper().walkTo(entity.getLivingEntity(), loc, speed != null ? speed.asDouble() : 0.2,
new Runnable() {
@Override
public void run() {
Expand Down
Expand Up @@ -214,24 +214,6 @@ public void stopWalking(Entity entity) {
((EntityInsentient) nmsEntity).getNavigation().p();
}

@Override
public void toggleAI(Entity entity, boolean hasAI) {
net.minecraft.server.v1_12_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (!(nmsEntity instanceof EntityInsentient)) {
return;
}
((EntityInsentient) nmsEntity).setNoAI(!hasAI);
}

@Override
public boolean isAIDisabled(Entity entity) {
net.minecraft.server.v1_12_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (!(nmsEntity instanceof EntityInsentient)) {
return true;
}
return ((EntityInsentient) nmsEntity).isNoAI();
}

@Override
public double getSpeed(Entity entity) {
net.minecraft.server.v1_12_R1.Entity nmsEntityEntity = ((CraftEntity) entity).getHandle();
Expand Down Expand Up @@ -320,7 +302,7 @@ else if (!inRadius && !Utilities.checkLocation(targetLocation, follower.getLocat
}

@Override
public void walkTo(final Entity entity, Location location, double speed, final Runnable callback) {
public void walkTo(final LivingEntity entity, Location location, double speed, final Runnable callback) {
if (entity == null || location == null) {
return;
}
Expand All @@ -333,9 +315,9 @@ public void walkTo(final Entity entity, Location location, double speed, final R
final NavigationAbstract entityNavigation = nmsEntity.getNavigation();

final PathEntity path;
final boolean aiDisabled = isAIDisabled(entity);
final boolean aiDisabled = !entity.hasAI();
if (aiDisabled) {
toggleAI(entity, true);
entity.setAI(true);
nmsEntity.onGround = true;
}
path = entityNavigation.a(location.getX(), location.getY(), location.getZ());
Expand All @@ -353,7 +335,7 @@ public void run() {
}
nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(oldSpeed);
if (aiDisabled) {
toggleAI(entity, false);
entity.setAI(false);
}
cancel();
}
Expand Down
Expand Up @@ -224,24 +224,6 @@ public void stopWalking(Entity entity) {
((EntityInsentient) nmsEntity).getNavigation().q();
}

@Override
public void toggleAI(Entity entity, boolean hasAI) {
net.minecraft.server.v1_13_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (!(nmsEntity instanceof EntityInsentient)) {
return;
}
((EntityInsentient) nmsEntity).setNoAI(!hasAI);
}

@Override
public boolean isAIDisabled(Entity entity) {
net.minecraft.server.v1_13_R2.Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (!(nmsEntity instanceof EntityInsentient)) {
return true;
}
return ((EntityInsentient) nmsEntity).isNoAI();
}

@Override
public double getSpeed(Entity entity) {
net.minecraft.server.v1_13_R2.Entity nmsEntityEntity = ((CraftEntity) entity).getHandle();
Expand Down Expand Up @@ -330,7 +312,7 @@ else if (!inRadius && !Utilities.checkLocation(targetLocation, follower.getLocat
}

@Override
public void walkTo(final Entity entity, Location location, double speed, final Runnable callback) {
public void walkTo(final LivingEntity entity, Location location, double speed, final Runnable callback) {
if (entity == null || location == null) {
return;
}
Expand All @@ -343,9 +325,9 @@ public void walkTo(final Entity entity, Location location, double speed, final R
final NavigationAbstract entityNavigation = nmsEntity.getNavigation();

final PathEntity path;
final boolean aiDisabled = isAIDisabled(entity);
final boolean aiDisabled = !entity.hasAI();
if (aiDisabled) {
toggleAI(entity, true);
entity.setAI(true);
nmsEntity.onGround = true;
}
path = entityNavigation.a(location.getX(), location.getY(), location.getZ());
Expand All @@ -363,7 +345,7 @@ public void run() {
}
nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(oldSpeed);
if (aiDisabled) {
toggleAI(entity, false);
entity.setAI(false);
}
cancel();
}
Expand Down
Expand Up @@ -254,24 +254,6 @@ public void stopWalking(Entity entity) {
((EntityInsentient) nmsEntity).getNavigation().o();
}

@Override
public void toggleAI(Entity entity, boolean hasAI) {
net.minecraft.server.v1_14_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (!(nmsEntity instanceof EntityInsentient)) {
return;
}
((EntityInsentient) nmsEntity).setNoAI(!hasAI);
}

@Override
public boolean isAIDisabled(Entity entity) {
net.minecraft.server.v1_14_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (!(nmsEntity instanceof EntityInsentient)) {
return true;
}
return ((EntityInsentient) nmsEntity).isNoAI();
}

@Override
public double getSpeed(Entity entity) {
net.minecraft.server.v1_14_R1.Entity nmsEntityEntity = ((CraftEntity) entity).getHandle();
Expand Down Expand Up @@ -360,7 +342,7 @@ else if (!inRadius && !Utilities.checkLocation(targetLocation, follower.getLocat
}

@Override
public void walkTo(final Entity entity, Location location, double speed, final Runnable callback) {
public void walkTo(final LivingEntity entity, Location location, double speed, final Runnable callback) {
if (entity == null || location == null) {
return;
}
Expand All @@ -373,9 +355,9 @@ public void walkTo(final Entity entity, Location location, double speed, final R
final NavigationAbstract entityNavigation = nmsEntity.getNavigation();

final PathEntity path;
final boolean aiDisabled = isAIDisabled(entity);
final boolean aiDisabled = !entity.hasAI();
if (aiDisabled) {
toggleAI(entity, true);
entity.setAI(true);
nmsEntity.onGround = true;
}
path = entityNavigation.a(location.getX(), location.getY(), location.getZ(), 0);
Expand Down Expand Up @@ -403,7 +385,7 @@ public void run() {
}
nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(oldSpeed);
if (aiDisabled) {
toggleAI(entity, false);
entity.setAI(false);
}
cancel();
}
Expand Down
Expand Up @@ -254,24 +254,6 @@ public void stopWalking(Entity entity) {
((EntityInsentient) nmsEntity).getNavigation().o();
}

@Override
public void toggleAI(Entity entity, boolean hasAI) {
net.minecraft.server.v1_15_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (!(nmsEntity instanceof EntityInsentient)) {
return;
}
((EntityInsentient) nmsEntity).setNoAI(!hasAI);
}

@Override
public boolean isAIDisabled(Entity entity) {
net.minecraft.server.v1_15_R1.Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (!(nmsEntity instanceof EntityInsentient)) {
return true;
}
return ((EntityInsentient) nmsEntity).isNoAI();
}

@Override
public double getSpeed(Entity entity) {
net.minecraft.server.v1_15_R1.Entity nmsEntityEntity = ((CraftEntity) entity).getHandle();
Expand Down Expand Up @@ -360,7 +342,7 @@ else if (!inRadius && !Utilities.checkLocation(targetLocation, follower.getLocat
}

@Override
public void walkTo(final Entity entity, Location location, double speed, final Runnable callback) {
public void walkTo(final LivingEntity entity, Location location, double speed, final Runnable callback) {
if (entity == null || location == null) {
return;
}
Expand All @@ -373,9 +355,9 @@ public void walkTo(final Entity entity, Location location, double speed, final R
final NavigationAbstract entityNavigation = nmsEntity.getNavigation();

final PathEntity path;
final boolean aiDisabled = isAIDisabled(entity);
final boolean aiDisabled = !entity.hasAI();
if (aiDisabled) {
toggleAI(entity, true);
entity.setAI(true);
nmsEntity.onGround = true;
}
path = entityNavigation.a(location.getX(), location.getY(), location.getZ(), 0);
Expand Down Expand Up @@ -403,7 +385,7 @@ public void run() {
}
nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(oldSpeed);
if (aiDisabled) {
toggleAI(entity, false);
entity.setAI(false);
}
cancel();
}
Expand Down

0 comments on commit 15b5345

Please sign in to comment.