Use new spawnreason

This commit is contained in:
fullwall 2018-08-08 16:08:38 +08:00
parent 50cc44258f
commit 505ef8a926
24 changed files with 211 additions and 167 deletions

View File

@ -80,6 +80,7 @@ import net.citizensnpcs.api.event.NPCLeftClickEvent;
import net.citizensnpcs.api.event.NPCRightClickEvent;
import net.citizensnpcs.api.event.NPCSpawnEvent;
import net.citizensnpcs.api.event.PlayerCreateNPCEvent;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCRegistry;
import net.citizensnpcs.api.trait.trait.Owner;
@ -262,7 +263,7 @@ public class EventListen implements Listener {
@Override
public void run() {
if (!npc.isSpawned() && npc.getOwningRegistry().getByUniqueId(npc.getUniqueId()) == npc) {
npc.spawn(location);
npc.spawn(location, SpawnReason.TIMED_RESPAWN);
}
}
}, delay + 2);
@ -530,8 +531,7 @@ public class EventListen implements Listener {
@EventHandler(ignoreCancelled = true)
public void onWorldLoad(WorldLoadEvent event) {
for (ChunkCoord chunk : toRespawn.keySet()) {
if (!chunk.worldUUID.equals(event.getWorld().getUID())
|| !event.getWorld().isChunkLoaded(chunk.x, chunk.z))
if (!chunk.worldUUID.equals(event.getWorld().getUID()) || !event.getWorld().isChunkLoaded(chunk.x, chunk.z))
continue;
respawnAllFromCoord(chunk);
}

View File

@ -52,6 +52,7 @@ import net.citizensnpcs.api.command.exception.ServerCommandException;
import net.citizensnpcs.api.event.CommandSenderCreateNPCEvent;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.PlayerCreateNPCEvent;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCRegistry;
import net.citizensnpcs.api.trait.Trait;
@ -416,7 +417,7 @@ public class NPCCommands {
}
if (!args.hasFlag('u')) {
npc.spawn(spawnLoc);
npc.spawn(spawnLoc, SpawnReason.CREATE);
}
if (args.hasValueFlag("trait")) {
@ -687,8 +688,8 @@ public class NPCCommands {
break;
}
if (npc.isSpawned()) {
npc.despawn();
npc.spawn(npc.getStoredLocation());
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
Messaging.sendTr(sender, Messages.ITEM_SET, Util.prettyEnum(mat));
}
@ -915,7 +916,7 @@ public class NPCCommands {
public void moveto(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
// Spawn the NPC if it isn't spawned to prevent NPEs
if (!npc.isSpawned()) {
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation());
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation(), SpawnReason.COMMAND);
}
if (!npc.isSpawned()) {
throw new CommandException("NPC could not be spawned.");
@ -1144,7 +1145,7 @@ public class NPCCommands {
npc.data().setPersistent("removefromplayerlist", remove);
if (npc.isSpawned()) {
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation());
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation(), SpawnReason.RESPAWN);
NMS.addOrRemoveFromPlayerList(npc.getEntity(), remove);
}
Messaging.sendTr(sender, remove ? Messages.REMOVED_FROM_PLAYERLIST : Messages.ADDED_TO_PLAYERLIST,
@ -1333,7 +1334,7 @@ public class NPCCommands {
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.setName(newName);
if (prev != null) {
npc.spawn(prev);
npc.spawn(prev, SpawnReason.RESPAWN);
}
Messaging.sendTr(sender, Messages.NPC_RENAMED, oldName, newName);
@ -1664,7 +1665,7 @@ public class NPCCommands {
if (args.hasFlag('l') && !Util.isLoaded(location)) {
location.getChunk().load();
}
if (respawn.spawn(location)) {
if (respawn.spawn(location, SpawnReason.COMMAND)) {
selector.select(sender, respawn);
Messaging.sendTr(sender, Messages.NPC_SPAWNED, respawn.getName());
}
@ -1799,7 +1800,7 @@ public class NPCCommands {
throw new ServerCommandException();
// Spawn the NPC if it isn't spawned to prevent NPEs
if (!npc.isSpawned()) {
npc.spawn(args.getSenderLocation());
npc.spawn(args.getSenderLocation(), SpawnReason.COMMAND);
if (!sender.hasPermission("citizens.npc.tphere.multiworld")
&& npc.getEntity().getLocation().getWorld() != args.getSenderLocation().getWorld()) {
npc.despawn(DespawnReason.REMOVAL);

View File

@ -12,7 +12,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.scoreboard.Team;
import org.bukkit.scoreboard.Team.Option;
@ -28,6 +28,7 @@ import net.citizensnpcs.api.ai.Navigator;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCDespawnEvent;
import net.citizensnpcs.api.event.NPCSpawnEvent;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.AbstractNPC;
import net.citizensnpcs.api.npc.BlockBreaker;
import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration;
@ -139,7 +140,7 @@ public class CitizensNPC extends AbstractNPC {
// Spawn the NPC
CurrentLocation spawnLocation = getTrait(CurrentLocation.class);
if (getTrait(Spawned.class).shouldSpawn() && spawnLocation.getLocation() != null) {
spawn(spawnLocation.getLocation());
spawn(spawnLocation.getLocation(), SpawnReason.RESPAWN);
}
if (getTrait(Spawned.class).shouldSpawn() && spawnLocation.getLocation() == null) {
Messaging.debug("Tried to spawn", getId(), "on load but world was null");
@ -174,7 +175,7 @@ public class CitizensNPC extends AbstractNPC {
}
entityController = newController;
if (wasSpawned) {
spawn(prev);
spawn(prev, SpawnReason.RESPAWN);
}
}
@ -186,7 +187,13 @@ public class CitizensNPC extends AbstractNPC {
@Override
public boolean spawn(Location at) {
return spawn(at, SpawnReason.PLUGIN);
}
@Override
public boolean spawn(Location at, SpawnReason reason) {
Preconditions.checkNotNull(at, "location cannot be null");
Preconditions.checkNotNull(reason, "reason cannot be null");
if (isSpawned()) {
Messaging.debug("Tried to spawn", getId(), "while already spawned.");
return false;
@ -203,7 +210,8 @@ public class CitizensNPC extends AbstractNPC {
getEntity().setMetadata(NPC_METADATA_MARKER, new FixedMetadataValue(CitizensAPI.getPlugin(), true));
boolean couldSpawn = !Util.isLoaded(at) ? false : NMS.addEntityToWorld(getEntity(), SpawnReason.CUSTOM);
boolean couldSpawn = !Util.isLoaded(at) ? false
: NMS.addEntityToWorld(getEntity(), CreatureSpawnEvent.SpawnReason.CUSTOM);
// send skin packets, if applicable, before other NMS packets are sent
if (couldSpawn) {
@ -230,7 +238,7 @@ public class CitizensNPC extends AbstractNPC {
getTrait(CurrentLocation.class).setLocation(at);
getTrait(Spawned.class).setSpawned(true);
NPCSpawnEvent spawnEvent = new NPCSpawnEvent(this, at);
NPCSpawnEvent spawnEvent = new NPCSpawnEvent(this, at, reason);
Bukkit.getPluginManager().callEvent(spawnEvent);
if (spawnEvent.isCancelled()) {

View File

@ -12,6 +12,7 @@ import com.google.common.collect.Maps;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.DataKey;
import net.citizensnpcs.api.util.MemoryDataKey;
@ -54,7 +55,7 @@ public class Template {
}
npc.load(memoryKey);
if (wasSpawned && npc.getStoredLocation() != null) {
npc.spawn(npc.getStoredLocation());
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}

View File

@ -20,6 +20,7 @@ import com.mojang.authlib.properties.Property;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.npc.profile.ProfileFetchHandler;
@ -131,7 +132,7 @@ public class Skin {
if (npc.isSpawned()) {
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation());
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}

View File

@ -8,6 +8,7 @@ import org.bukkit.command.CommandSender;
import com.google.common.collect.Maps;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
@ -37,7 +38,7 @@ public class Poses extends Trait {
private void assumePose(float yaw, float pitch) {
if (!npc.isSpawned()) {
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation());
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation(), SpawnReason.COMMAND);
}
Util.assumePose(npc.getEntity(), yaw, pitch);
}

View File

@ -10,6 +10,7 @@ import org.bukkit.entity.EntityType;
import com.google.common.collect.Maps;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.MemoryNPCDataStore;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCRegistry;
@ -42,7 +43,7 @@ public class EntityMarkers<T> {
public Entity spawnMarker(World world, Location at) {
NPC npc = registry.createNPC(EntityType.ENDER_SIGNAL, "");
npc.spawn(at);
npc.spawn(at, SpawnReason.CREATE);
return npc.getEntity();
}
}

View File

@ -10,6 +10,7 @@ import org.bukkit.entity.EntityType;
import com.google.common.collect.Maps;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.MemoryNPCDataStore;
import net.citizensnpcs.api.npc.NPC;
@ -46,7 +47,7 @@ public class WaypointMarkers {
public Entity spawnMarker(World world, Location at) {
NPC npc = CitizensAPI.createAnonymousNPCRegistry(new MemoryNPCDataStore()).createNPC(EntityType.ENDER_SIGNAL,
"");
npc.spawn(at);
npc.spawn(at, SpawnReason.CREATE);
return npc.getEntity();
}
}

View File

@ -12,7 +12,9 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_10_R1.util.NMSImpl;
import net.citizensnpcs.npc.AbstractEntityController;
@ -118,15 +120,6 @@ public class FallingBlockController extends AbstractEntityController {
return npc;
}
@Override
public void setSize(float f, float f1) {
if (npc == null) {
super.setSize(f, f1);
} else {
NMSImpl.setSize(this, f, f1, justCreated);
}
}
@Override
public void m() {
if (npc != null) {
@ -142,6 +135,15 @@ public class FallingBlockController extends AbstractEntityController {
}
}
@Override
public void setSize(float f, float f1) {
if (npc == null) {
super.setSize(f, f1);
} else {
NMSImpl.setSize(this, f, f1, justCreated);
}
}
private static final double EPSILON = 0.001;
}
@ -162,8 +164,8 @@ public class FallingBlockController extends AbstractEntityController {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn();
npc.spawn(npc.getStoredLocation());
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
}

View File

@ -1,18 +1,5 @@
package net.citizensnpcs.nms.v1_10_R1.entity.nonliving;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.AbstractEntityController;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_10_R1.EntityHuman;
import net.minecraft.server.v1_10_R1.EntityItem;
import net.minecraft.server.v1_10_R1.ItemStack;
import net.minecraft.server.v1_10_R1.NBTTagCompound;
import net.minecraft.server.v1_10_R1.World;
import net.minecraft.server.v1_10_R1.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -25,6 +12,21 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.AbstractEntityController;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_10_R1.EntityHuman;
import net.minecraft.server.v1_10_R1.EntityItem;
import net.minecraft.server.v1_10_R1.ItemStack;
import net.minecraft.server.v1_10_R1.NBTTagCompound;
import net.minecraft.server.v1_10_R1.World;
import net.minecraft.server.v1_10_R1.WorldServer;
public class ItemController extends AbstractEntityController {
public ItemController() {
super(EntityItemNPC.class);
@ -145,8 +147,8 @@ public class ItemController extends AbstractEntityController {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn();
npc.spawn(npc.getStoredLocation());
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
}

View File

@ -10,7 +10,9 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame;
import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_10_R1.entity.MobEntityController;
import net.citizensnpcs.npc.CitizensNPC;
@ -103,11 +105,6 @@ public class ItemFrameController extends MobEntityController {
return npc;
}
@Override
public boolean survives() {
return npc == null || !npc.isProtected() ? super.survives() : true;
}
@Override
public void m() {
if (npc != null) {
@ -116,6 +113,11 @@ public class ItemFrameController extends MobEntityController {
super.m();
}
}
@Override
public boolean survives() {
return npc == null || !npc.isProtected() ? super.survives() : true;
}
}
public static class ItemFrameNPC extends CraftItemFrame implements NPCHolder {
@ -142,8 +144,8 @@ public class ItemFrameController extends MobEntityController {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn();
npc.spawn(npc.getStoredLocation());
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
}

View File

@ -12,7 +12,9 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_11_R1.util.NMSImpl;
import net.citizensnpcs.npc.AbstractEntityController;
@ -163,8 +165,8 @@ public class FallingBlockController extends AbstractEntityController {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn();
npc.spawn(npc.getStoredLocation());
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
}

View File

@ -1,18 +1,5 @@
package net.citizensnpcs.nms.v1_11_R1.entity.nonliving;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.AbstractEntityController;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_11_R1.EntityHuman;
import net.minecraft.server.v1_11_R1.EntityItem;
import net.minecraft.server.v1_11_R1.ItemStack;
import net.minecraft.server.v1_11_R1.NBTTagCompound;
import net.minecraft.server.v1_11_R1.World;
import net.minecraft.server.v1_11_R1.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -25,6 +12,21 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.AbstractEntityController;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_11_R1.EntityHuman;
import net.minecraft.server.v1_11_R1.EntityItem;
import net.minecraft.server.v1_11_R1.ItemStack;
import net.minecraft.server.v1_11_R1.NBTTagCompound;
import net.minecraft.server.v1_11_R1.World;
import net.minecraft.server.v1_11_R1.WorldServer;
public class ItemController extends AbstractEntityController {
public ItemController() {
super(EntityItemNPC.class);
@ -61,6 +63,15 @@ public class ItemController extends AbstractEntityController {
this.npc = (CitizensNPC) npc;
}
@Override
public void A_() {
if (npc != null) {
npc.update();
} else {
super.A_();
}
}
@Override
public void collide(net.minecraft.server.v1_11_R1.Entity entity) {
// this method is called by both the entities involved - cancelling
@ -117,15 +128,6 @@ public class ItemController extends AbstractEntityController {
public NPC getNPC() {
return npc;
}
@Override
public void A_() {
if (npc != null) {
npc.update();
} else {
super.A_();
}
}
}
public static class ItemNPC extends CraftItem implements NPCHolder {
@ -145,8 +147,8 @@ public class ItemController extends AbstractEntityController {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn();
npc.spawn(npc.getStoredLocation());
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
}

View File

@ -10,7 +10,9 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame;
import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_11_R1.entity.MobEntityController;
import net.citizensnpcs.npc.CitizensNPC;
@ -53,6 +55,15 @@ public class ItemFrameController extends MobEntityController {
this.npc = (CitizensNPC) npc;
}
@Override
public void A_() {
if (npc != null) {
npc.update();
} else {
super.A_();
}
}
@Override
public void collide(net.minecraft.server.v1_11_R1.Entity entity) {
// this method is called by both the entities involved - cancelling
@ -107,15 +118,6 @@ public class ItemFrameController extends MobEntityController {
public boolean survives() {
return npc == null || !npc.isProtected() ? super.survives() : true;
}
@Override
public void A_() {
if (npc != null) {
npc.update();
} else {
super.A_();
}
}
}
public static class ItemFrameNPC extends CraftItemFrame implements NPCHolder {
@ -142,8 +144,8 @@ public class ItemFrameController extends MobEntityController {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn();
npc.spawn(npc.getStoredLocation());
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
}

View File

@ -12,7 +12,9 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_12_R1.util.NMSImpl;
import net.citizensnpcs.npc.AbstractEntityController;
@ -163,8 +165,8 @@ public class FallingBlockController extends AbstractEntityController {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn();
npc.spawn(npc.getStoredLocation());
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
}

View File

@ -1,18 +1,5 @@
package net.citizensnpcs.nms.v1_12_R1.entity.nonliving;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.AbstractEntityController;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_12_R1.EntityHuman;
import net.minecraft.server.v1_12_R1.EntityItem;
import net.minecraft.server.v1_12_R1.ItemStack;
import net.minecraft.server.v1_12_R1.NBTTagCompound;
import net.minecraft.server.v1_12_R1.World;
import net.minecraft.server.v1_12_R1.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -25,6 +12,21 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.AbstractEntityController;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_12_R1.EntityHuman;
import net.minecraft.server.v1_12_R1.EntityItem;
import net.minecraft.server.v1_12_R1.ItemStack;
import net.minecraft.server.v1_12_R1.NBTTagCompound;
import net.minecraft.server.v1_12_R1.World;
import net.minecraft.server.v1_12_R1.WorldServer;
public class ItemController extends AbstractEntityController {
public ItemController() {
super(EntityItemNPC.class);
@ -61,6 +63,15 @@ public class ItemController extends AbstractEntityController {
this.npc = (CitizensNPC) npc;
}
@Override
public void B_() {
if (npc != null) {
npc.update();
} else {
super.B_();
}
}
@Override
public void collide(net.minecraft.server.v1_12_R1.Entity entity) {
// this method is called by both the entities involved - cancelling
@ -117,15 +128,6 @@ public class ItemController extends AbstractEntityController {
public NPC getNPC() {
return npc;
}
@Override
public void B_() {
if (npc != null) {
npc.update();
} else {
super.B_();
}
}
}
public static class ItemNPC extends CraftItem implements NPCHolder {
@ -145,8 +147,8 @@ public class ItemController extends AbstractEntityController {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn();
npc.spawn(npc.getStoredLocation());
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
}

View File

@ -10,7 +10,9 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame;
import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_12_R1.entity.MobEntityController;
import net.citizensnpcs.npc.CitizensNPC;
@ -53,6 +55,15 @@ public class ItemFrameController extends MobEntityController {
this.npc = (CitizensNPC) npc;
}
@Override
public void B_() {
if (npc != null) {
npc.update();
} else {
super.B_();
}
}
@Override
public void collide(net.minecraft.server.v1_12_R1.Entity entity) {
// this method is called by both the entities involved - cancelling
@ -107,15 +118,6 @@ public class ItemFrameController extends MobEntityController {
public boolean survives() {
return npc == null || !npc.isProtected() ? super.survives() : true;
}
@Override
public void B_() {
if (npc != null) {
npc.update();
} else {
super.B_();
}
}
}
public static class ItemFrameNPC extends CraftItemFrame implements NPCHolder {
@ -142,8 +144,8 @@ public class ItemFrameController extends MobEntityController {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn();
npc.spawn(npc.getStoredLocation());
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
}

View File

@ -1,4 +1,4 @@
package net.citizensnpcs.nms.v1_13_R1.entity; import net.minecraft.server.v1_13_R1.DamageSource;
package net.citizensnpcs.nms.v1_13_R1.entity;
import java.lang.reflect.Constructor;
import java.util.Map;

View File

@ -12,7 +12,9 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_13_R1.util.NMSImpl;
import net.citizensnpcs.npc.AbstractEntityController;
@ -164,8 +166,8 @@ public class FallingBlockController extends AbstractEntityController {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn();
npc.spawn(npc.getStoredLocation());
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
}

View File

@ -1,18 +1,5 @@
package net.citizensnpcs.nms.v1_13_R1.entity.nonliving;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.AbstractEntityController;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_13_R1.EntityHuman;
import net.minecraft.server.v1_13_R1.EntityItem;
import net.minecraft.server.v1_13_R1.ItemStack;
import net.minecraft.server.v1_13_R1.NBTTagCompound;
import net.minecraft.server.v1_13_R1.World;
import net.minecraft.server.v1_13_R1.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -25,6 +12,21 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.AbstractEntityController;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_13_R1.EntityHuman;
import net.minecraft.server.v1_13_R1.EntityItem;
import net.minecraft.server.v1_13_R1.ItemStack;
import net.minecraft.server.v1_13_R1.NBTTagCompound;
import net.minecraft.server.v1_13_R1.World;
import net.minecraft.server.v1_13_R1.WorldServer;
public class ItemController extends AbstractEntityController {
public ItemController() {
super(EntityItemNPC.class);
@ -145,8 +147,8 @@ public class ItemController extends AbstractEntityController {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn();
npc.spawn(npc.getStoredLocation());
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
}

View File

@ -10,7 +10,9 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame;
import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_13_R1.entity.MobEntityController;
import net.citizensnpcs.npc.CitizensNPC;
@ -142,8 +144,8 @@ public class ItemFrameController extends MobEntityController {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn();
npc.spawn(npc.getStoredLocation());
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
}

View File

@ -12,7 +12,9 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl;
import net.citizensnpcs.npc.AbstractEntityController;
@ -162,8 +164,8 @@ public class FallingBlockController extends AbstractEntityController {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn();
npc.spawn(npc.getStoredLocation());
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
}

View File

@ -1,18 +1,5 @@
package net.citizensnpcs.nms.v1_8_R3.entity.nonliving;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.AbstractEntityController;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_8_R3.EntityHuman;
import net.minecraft.server.v1_8_R3.EntityItem;
import net.minecraft.server.v1_8_R3.ItemStack;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import net.minecraft.server.v1_8_R3.World;
import net.minecraft.server.v1_8_R3.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -25,6 +12,21 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.AbstractEntityController;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_8_R3.EntityHuman;
import net.minecraft.server.v1_8_R3.EntityItem;
import net.minecraft.server.v1_8_R3.ItemStack;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import net.minecraft.server.v1_8_R3.World;
import net.minecraft.server.v1_8_R3.WorldServer;
public class ItemController extends AbstractEntityController {
public ItemController() {
super(EntityItemNPC.class);
@ -145,8 +147,8 @@ public class ItemController extends AbstractEntityController {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn();
npc.spawn(npc.getStoredLocation());
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
}

View File

@ -10,7 +10,9 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame;
import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.event.SpawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController;
import net.citizensnpcs.npc.CitizensNPC;
@ -142,8 +144,8 @@ public class ItemFrameController extends MobEntityController {
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
if (npc.isSpawned()) {
npc.despawn();
npc.spawn(npc.getStoredLocation());
npc.despawn(DespawnReason.PENDING_RESPAWN);
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
}
}
}