Call NPCVehicleExitEvent for controllables, possibly fix a despawn/respawn bug

This commit is contained in:
fullwall 2013-08-13 12:20:57 +08:00
parent 59efe79cd1
commit f970e2b5ac
3 changed files with 15 additions and 6 deletions

View File

@ -214,7 +214,10 @@ public class EventListen implements Listener {
@EventHandler
public void onNeedsRespawn(NPCNeedsRespawnEvent event) {
toRespawn.put(toCoord(event.getSpawnLocation()), event.getNPC());
ChunkCoord coord = toCoord(event.getSpawnLocation());
if (toRespawn.containsEntry(coord, event.getNPC()))
return;
toRespawn.put(coord, event.getNPC());
}
@EventHandler
@ -289,8 +292,9 @@ public class EventListen implements Listener {
boolean despawned = npc.despawn(DespawnReason.WORLD_UNLOAD);
if (event.isCancelled() || !despawned) {
for (ChunkCoord coord : toRespawn.keySet()) {
if (event.getWorld().getName().equals(coord.worldName))
if (event.getWorld().getName().equals(coord.worldName)) {
respawnAllFromCoord(coord);
}
}
return;
}

View File

@ -155,7 +155,7 @@ public class CitizensNPC extends AbstractNPC {
// we need to wait for a chunk load before trying to spawn
entityController.remove();
Bukkit.getPluginManager().callEvent(new NPCNeedsRespawnEvent(this, at));
return true;
return false;
}
NMS.setHeadYaw(mcEntity, at.getYaw());
@ -214,7 +214,7 @@ public class CitizensNPC extends AbstractNPC {
@Override
public void teleport(Location location, TeleportCause cause) {
if (!this.isSpawned())
if (!isSpawned())
return;
teleport(NMS.getRootVehicle(getBukkitEntity()), location, false, 5);
}

View File

@ -7,6 +7,7 @@ import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.command.CommandConfigurable;
import net.citizensnpcs.api.command.CommandContext;
import net.citizensnpcs.api.event.NPCRightClickEvent;
import net.citizensnpcs.api.event.NPCVehicleExitEvent;
import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
@ -18,6 +19,7 @@ import net.minecraft.server.v1_6_R2.EntityEnderDragon;
import net.minecraft.server.v1_6_R2.EntityLiving;
import net.minecraft.server.v1_6_R2.EntityPlayer;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer;
import org.bukkit.entity.Entity;
@ -65,12 +67,15 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
private void enterOrLeaveVehicle(Player player) {
EntityPlayer handle = ((CraftPlayer) player).getHandle();
if (getHandle().passenger != null) {
if (getHandle().passenger == handle)
if (getHandle().passenger == handle) {
player.leaveVehicle();
Bukkit.getPluginManager().callEvent(new NPCVehicleExitEvent(npc, player));
}
return;
}
if (npc.getTrait(Owner.class).isOwnedBy(handle.getBukkitEntity()))
if (npc.getTrait(Owner.class).isOwnedBy(handle.getBukkitEntity())) {
handle.setPassengerOf(getHandle());
}
}
private EntityLiving getHandle() {