Skip to content

Commit

Permalink
Change npc.getBukkitEntity() to npc.getEntity()
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Jun 9, 2015
1 parent aaeda9c commit 2013c7d
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 51 deletions.
23 changes: 12 additions & 11 deletions src/main/java/net/aufdemrand/denizen/npc/traits/FishingTrait.java
Expand Up @@ -12,6 +12,7 @@
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;

import java.util.ArrayList;
Expand Down Expand Up @@ -73,7 +74,7 @@ public void run() {
reelCount++;
castCount++;
if(fish != null) {
if (fish.getBukkitEntity().getLocation().distance(npc.getBukkitEntity().getLocation()) < 3) {
if (fish.getBukkitEntity().getLocation().distance(npc.getEntity().getLocation()) < 3) {
try {
fish.getBukkitEntity().remove();
} catch (Exception e) {
Expand All @@ -96,8 +97,8 @@ public void run() {

@Override
public void onSpawn() {
eh = ((CraftPlayer) npc.getBukkitEntity()).getHandle();
nmsworld = ((CraftWorld) npc.getBukkitEntity().getWorld()).getHandle();
eh = ((CraftPlayer) npc.getEntity()).getHandle();
nmsworld = ((CraftWorld) npc.getEntity().getWorld()).getHandle();
}

// <--[action]
Expand Down Expand Up @@ -153,7 +154,7 @@ public void stopFishing() {
*/
public void startFishing() {
fishing = true;
fishingLocation = npc.getBukkitEntity().getLocation();
fishingLocation = npc.getEntity().getLocation();
}

// <--[action]
Expand Down Expand Up @@ -181,7 +182,7 @@ private void cast() {

fishHook = new EntityFishingHook(nmsworld, eh);
nmsworld.addEntity(fishHook);
from = npc.getBukkitEntity().getLocation();
from = npc.getEntity().getLocation();
from = from.add(0,.33,0);
to = fishingLocation;

Expand All @@ -208,10 +209,10 @@ private void cast() {
victor = victor.multiply(v / 20.0);

Projectile theHook = (Projectile) fishHook.getBukkitEntity();
theHook.setShooter(npc.getBukkitEntity());
theHook.setShooter((ProjectileSource) npc.getEntity());
theHook.setVelocity(victor);

PlayerAnimation.ARM_SWING.play((Player) npc.getBukkitEntity());
PlayerAnimation.ARM_SWING.play((Player) npc.getEntity());
}

// <--[action]
Expand All @@ -238,9 +239,9 @@ private void reel() {
fish.getBukkitEntity().remove();
} catch(Exception e) {}
fish = new EntityItem(nmsworld, fishHook.locX, fishHook.locY, fishHook.locZ, getFishingResult());
double d5 = npc.getBukkitEntity().getLocation().getX() - fishHook.locX;
double d6 = npc.getBukkitEntity().getLocation().getY() - fishHook.locY;
double d7 = npc.getBukkitEntity().getLocation().getZ() - fishHook.locZ;
double d5 = npc.getEntity().getLocation().getX() - fishHook.locX;
double d6 = npc.getEntity().getLocation().getY() - fishHook.locY;
double d7 = npc.getEntity().getLocation().getZ() - fishHook.locZ;
double d8 = (double) MathHelper.sqrt(d5 * d5 + d6 * d6 + d7 * d7);
double d9 = 0.1D;

Expand All @@ -251,7 +252,7 @@ private void reel() {
DenizenAPI.getDenizenNPC(npc).action("catch fish", null);
}

PlayerAnimation.ARM_SWING.play((Player) npc.getBukkitEntity());
PlayerAnimation.ARM_SWING.play((Player) npc.getEntity());
}

public ItemStack getFishingResult() {
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/net/aufdemrand/denizen/npc/traits/HealthTrait.java
Expand Up @@ -156,10 +156,10 @@ public void run() {
Bukkit.getScheduler().cancelTask(void_watcher_task);
return;
}
if (npc.getBukkitEntity().getLocation().getY() < -1000) {
if (npc.getEntity().getLocation().getY() < -1000) {
npc.despawn(DespawnReason.DEATH);
if (respawn) {
if (npc.isSpawned()) npc.getBukkitEntity().teleport(getRespawnLocation());
if (npc.isSpawned()) npc.getEntity().teleport(getRespawnLocation());
else npc.spawn(getRespawnLocation());
}
}
Expand All @@ -180,7 +180,7 @@ public HealthTrait() {
*/
public double getHealth() {
if (!npc.isSpawned()) return 0;
else return npc.getBukkitEntity().getHealth();
else return ((LivingEntity) npc.getEntity()).getHealth();
}

/**
Expand All @@ -190,7 +190,7 @@ public double getHealth() {
*
*/
public void setMaxhealth(int newMax) {
npc.getBukkitEntity().setMaxHealth(newMax);
((LivingEntity) npc.getEntity()).setMaxHealth(newMax);
}

/**
Expand All @@ -199,7 +199,7 @@ public void setMaxhealth(int newMax) {
* @return maximum health
*/
public double getMaxhealth() {
return npc.getBukkitEntity().getMaxHealth();
return ((LivingEntity) npc.getEntity()).getMaxHealth();
}

/**
Expand All @@ -216,7 +216,7 @@ public void heal(int health) {
*
*/
public void setHealth() {
setHealth(npc.getBukkitEntity().getMaxHealth());
setHealth(((LivingEntity) npc.getEntity()).getMaxHealth());
}

/**
Expand All @@ -225,12 +225,12 @@ public void setHealth() {
* @param health total health points
*/
public void setHealth(double health) {
if (npc.getBukkitEntity() != null)
npc.getBukkitEntity().setHealth(health);
if (npc.getEntity() != null)
((LivingEntity) npc.getEntity()).setHealth(health);
}

public void die() {
npc.getBukkitEntity().damage(npc.getBukkitEntity().getHealth());
((LivingEntity) npc.getEntity()).damage(((LivingEntity) npc.getEntity()).getHealth());
}

// Listen for deaths to clear drops
Expand Down Expand Up @@ -262,7 +262,7 @@ public void onDamage(EntityDamageEvent event) {
// Don't use NPCDamageEvent because it doesn't work well

// Check if the event pertains to this NPC
if (event.getEntity() != npc.getBukkitEntity() || dying) return;
if (event.getEntity() != npc.getEntity() || dying) return;

// Make sure this is a killing blow
if (this.getHealth() - event.getDamage() > 0)
Expand All @@ -272,7 +272,7 @@ public void onDamage(EntityDamageEvent event) {
player = null;

// Save entityId for EntityDeath event
entityId = npc.getBukkitEntity().getEntityId();
entityId = npc.getEntity().getEntityId();

String deathCause = event.getCause().toString().toLowerCase().replace('_', ' ');
Map<String, dObject> context = new HashMap<String, dObject>();
Expand Down Expand Up @@ -331,13 +331,13 @@ else if (event instanceof EntityDamageByBlockEvent)

// One of the actions above may have removed the NPC, so check if the
// NPC's entity still exists before proceeding
if (npc.getBukkitEntity() == null)
if (npc.getEntity() == null)
return;

loc = dLocation.valueOf(TagManager.tag(respawnLocation, // TODO: debug option?
new BukkitTagContext(null, DenizenAPI.getDenizenNPC(npc), false, null, true, null)));

if (loc == null) loc = npc.getBukkitEntity().getLocation();
if (loc == null) loc = npc.getEntity().getLocation();

if (animatedeath) {
// Cancel navigation to keep the NPC from damaging players
Expand All @@ -346,7 +346,7 @@ else if (event instanceof EntityDamageByBlockEvent)
// Reset health now to avoid the death from happening instantly
//setHealth();
// Play animation (TODO)
// playDeathAnimation(npc.getBukkitEntity());
// playDeathAnimation(npc.getEntity());

}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/aufdemrand/denizen/npc/traits/HungerTrait.java
Expand Up @@ -42,9 +42,9 @@ public void run() {
if (count >= 20) {
// Reset counter
count = 0;
double td = getDistance(npc.getBukkitEntity().getLocation());
double td = getDistance(npc.getEntity().getLocation());
if (td > 0) {
location = npc.getBukkitEntity().getLocation().clone();
location = npc.getEntity().getLocation().clone();
currenthunger = currenthunger - (td * 0.01 * multiplier);
}
}
Expand Down Expand Up @@ -89,7 +89,7 @@ public void onMove(NavigationBeginEvent event) {
}
}

location = npc.getBukkitEntity().getLocation();
location = npc.getEntity().getLocation();
listening = true;
}

Expand Down Expand Up @@ -223,9 +223,9 @@ public boolean isHungry() {

// Used internally
private double getDistance(Location location) {
if (!npc.getBukkitEntity().getWorld().equals(location.getWorld())) {
if (!npc.getEntity().getWorld().equals(location.getWorld())) {
// World change, update location
this.location = npc.getBukkitEntity().getLocation();
this.location = npc.getEntity().getLocation();
return 0;
}
return location.distance(this.location);
Expand Down
Expand Up @@ -128,7 +128,7 @@ public void onTraitAttachEvent(NPCTraitCommandAttachEvent event) {
}
@Override
public void onSpawn() {
liveEnt = getNPC().getBukkitEntity();
liveEnt = (LivingEntity) getNPC().getEntity();
dnpc = dNPC.mirrorCitizensNPC(getNPC());
frange = DenizenAPI.getCurrentInstance().flagManager().getNPCFlag(dnpc.getId(), "mobprox_range");
if (frange.isEmpty()) {
Expand Down
Expand Up @@ -109,19 +109,19 @@ public void run() {

@Override
public void onSpawn() {
//el = ((CraftLivingEntity)npc.getBukkitEntity()).getHandle();
//el = ((CraftLivingEntity)npc.getEntity()).getHandle();
//dw = el.getDataWatcher();
world = npc.getBukkitEntity().getWorld();
world = npc.getEntity().getWorld();
}

public void playFlameEffect() {
Location location = npc.getBukkitEntity().getLocation();
Location location = npc.getEntity().getLocation();
world.playEffect(location, Effect.MOBSPAWNER_FLAMES, 0);
if (dense) world.playEffect(location.add(0, 1, 0), Effect.MOBSPAWNER_FLAMES, 0);
}

public void playEnderEffect() {
Location location = npc.getBukkitEntity().getLocation();
Location location = npc.getEntity().getLocation();
world.playEffect(location, Effect.ENDER_SIGNAL, 0);
if (dense) world.playEffect(location.add(0, 1, 0), Effect.ENDER_SIGNAL, 0);
}
Expand All @@ -131,13 +131,13 @@ public void playPotionEffect() { // TODO: Implement?
}

public void playPotionBreakEffect() {
Location location = npc.getBukkitEntity().getLocation();
Location location = npc.getEntity().getLocation();
world.playEffect(location, Effect.POTION_BREAK, 0);
if (dense) world.playEffect(location.add(0, 1, 0), Effect.POTION_BREAK, 0);
}

public void playHeartEffect() {
Location location = npc.getBukkitEntity().getLocation();
Location location = npc.getEntity().getLocation();
Wolf tempWolf = world.spawn(location, Wolf.class);
((CraftWolf) tempWolf).getHandle().setInvisible(true);
tempWolf.playEffect(EntityEffect.WOLF_HEARTS);
Expand All @@ -146,7 +146,7 @@ public void playHeartEffect() {
}

public void playSmokeEffect() {
Location location = npc.getBukkitEntity().getLocation();
Location location = npc.getEntity().getLocation();
world.playEffect(location, Effect.SMOKE, 0);
world.playEffect(location, Effect.SMOKE, 1);
world.playEffect(location, Effect.SMOKE, 2);
Expand All @@ -170,7 +170,7 @@ public void playSmokeEffect() {
}

public void playExplosionEffect() {
Location location = npc.getBukkitEntity().getLocation();
Location location = npc.getEntity().getLocation();
world.createExplosion(location, 0);
}

Expand Down
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
Expand All @@ -30,7 +31,7 @@ public class SittingTrait extends Trait implements Listener {
@Override
public void run() {
if (!npc.isSpawned() || chairLocation == null) return;
if (!Utilities.checkLocation(npc.getBukkitEntity(), chairLocation, 1)) {
if (!Utilities.checkLocation((LivingEntity) npc.getEntity(), chairLocation, 1)) {
stand();
}
}
Expand Down Expand Up @@ -63,12 +64,12 @@ public void onDespawn() {
public void sit() {
DenizenAPI.getDenizenNPC(npc).action("sit", null);

if (npc.getBukkitEntity().getType() != EntityType.PLAYER) {
if (npc.getEntity().getType() != EntityType.PLAYER) {
return;
}

sitInternal();
chairLocation = npc.getBukkitEntity().getLocation().clone();
chairLocation = npc.getEntity().getLocation().clone();
}

private void sitInternal() {
Expand Down
Expand Up @@ -6,6 +6,7 @@
import net.citizensnpcs.util.PlayerAnimation;

import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent;
Expand All @@ -22,9 +23,9 @@ public class SleepingTrait extends Trait {
public void run() {
if (npc == null || bedLocation == null) return;

//if (npc.getBukkitEntity().getPassenger() == null && sitting) eh.mount(eh);
//if (npc.getEntity().getPassenger() == null && sitting) eh.mount(eh);

if (!Utilities.checkLocation(npc.getBukkitEntity(), bedLocation, 1)) wakeUp();
if (!Utilities.checkLocation((LivingEntity) npc.getEntity(), bedLocation, 1)) wakeUp();
}

/**
Expand All @@ -35,10 +36,10 @@ public void toSleep() {
return;
}

PlayerAnimation.SLEEP.play((Player) npc.getBukkitEntity());
PlayerAnimation.SLEEP.play((Player) npc.getEntity());

sleeping = true;
bedLocation = npc.getBukkitEntity().getLocation();
bedLocation = npc.getEntity().getLocation();
}

/**
Expand All @@ -56,9 +57,9 @@ public void toSleep(Location location) {
* playing sleep animation.
*/
//TODO Adjust the .add()
npc.getBukkitEntity().teleport(location.add(0.5, 0, 0.5));
npc.getEntity().teleport(location.add(0.5, 0, 0.5));

PlayerAnimation.SLEEP.play((Player) npc.getBukkitEntity());
PlayerAnimation.SLEEP.play((Player) npc.getEntity());

sleeping = true;
bedLocation = location;
Expand All @@ -72,7 +73,7 @@ public void wakeUp() {
return;
}

PlayerAnimation.STOP_SLEEPING.play((Player) npc.getBukkitEntity());
PlayerAnimation.STOP_SLEEPING.play((Player) npc.getEntity());

bedLocation = null;
sleeping = false;
Expand Down
Expand Up @@ -18,7 +18,7 @@ public class SneakingTrait extends Trait implements Listener {

@Override
public void onSpawn() {
eh = ((CraftPlayer) npc.getBukkitEntity()).getHandle();
eh = ((CraftPlayer) npc.getEntity()).getHandle();
if (sneaking) sneak();
}

Expand All @@ -38,7 +38,7 @@ public void onSpawn() {
public void sneak() {
DenizenAPI.getDenizenNPC(npc).action("sneak", null);

if (npc.getBukkitEntity().getType() != EntityType.PLAYER) {
if (npc.getEntity().getType() != EntityType.PLAYER) {
return;
}

Expand Down

0 comments on commit 2013c7d

Please sign in to comment.