@Override public void enderTeleportTo(double d0, double d1, double d2) { if (npc == null) super.enderTeleportTo(d0, d1, d2); NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { super.enderTeleportTo(d0, d1, d2); } }
@Override public void A_() { super.A_(); if (npc == null) return; if (updateCounter + 1 > Setting.PACKET_UPDATE_DELAY.asInt()) { updateEffects = true; } livingEntityBaseTick(); boolean navigating = npc.getNavigator().isNavigating(); updatePackets(navigating); if (!navigating && getBukkitEntity() != null && npc.getTrait(Gravity.class).hasGravity() && Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))) { g(0, 0); } if (Math.abs(motX) < EPSILON && Math.abs(motY) < EPSILON && Math.abs(motZ) < EPSILON) { motX = motY = motZ = 0; } if (navigating) { if (!NMSImpl.isNavigationFinished(navigation)) { NMSImpl.updateNavigation(navigation); } moveOnCurrentHeading(); } NMSImpl.updateAI(this); if (noDamageTicks > 0) { --noDamageTicks; } npc.update(); }
@Override public void g(float f, float f1) { if (npc == null || !npc.isFlyable()) { super.g(f, f1); } else { NMSImpl.flyingMoveLogic(this, f, f1); } }
@Override public void collide(net.minecraft.server.v1_11_R1.Entity entity) { // this method is called by both the entities involved - cancelling // it will not stop the NPC from moving. super.collide(entity); if (npc != null) { Util.callCollisionEvent(npc, entity.getBukkitEntity()); } }
@Override public void f(double x, double y, double z) { if (npc == null) { super.f(x, y, z); return; } if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) { super.f(x, y, z); } return; } Vector vector = new Vector(x, y, z); NPCPushEvent event = Util.callPushEvent(npc, vector); if (!event.isCancelled()) { vector = event.getCollisionVector(); super.f(vector.getX(), vector.getY(), vector.getZ()); } // when another entity collides, this method is called to push the // NPC so we prevent it from doing anything if the event is // cancelled. }
@Override public void die(DamageSource damagesource) { // players that die are not normally removed from the world. when the // NPC dies, we are done with the instance and it should be removed. if (dead) { return; } super.die(damagesource); Bukkit.getScheduler() .runTaskLater( CitizensAPI.getPlugin(), new Runnable() { @Override public void run() { world.removeEntity(EntityHumanNPC.this); } }, 35); // give enough time for death and smoke animation }
@Override public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block b) { EntityPlayer player = ((CraftPlayer) p).getHandle(); // Silent ender chest is pretty much API-only if (silentchest && b.getType() == Material.ENDER_CHEST) { p.openInventory(p.getEnderChest()); player.b(StatisticList.X); return true; } final World world = player.world; final BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ()); Object tile = world.getTileEntity(blockPosition); if (tile == null) { return false; } if (tile instanceof TileEntityEnderChest) { // Anychest ender chest. See net.minecraft.server.BlockEnderChest InventoryEnderChest enderChest = player.getEnderChest(); enderChest.a((TileEntityEnderChest) tile); player.openContainer(enderChest); player.b(StatisticList.X); return true; } if (!(tile instanceof IInventory)) { return false; } Block block = world.getType(blockPosition).getBlock(); Container container = null; if (block instanceof BlockChest) { BlockChest blockChest = (BlockChest) block; for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) { BlockPosition localBlockPosition = blockPosition.shift(localEnumDirection); Block localBlock = world.getType(localBlockPosition).getBlock(); if (localBlock != block) { continue; } TileEntity localTileEntity = world.getTileEntity(localBlockPosition); if (!(localTileEntity instanceof TileEntityChest)) { continue; } if ((localEnumDirection == EnumDirection.WEST) || (localEnumDirection == EnumDirection.NORTH)) { tile = new InventoryLargeChest( "container.chestDouble", (TileEntityChest) localTileEntity, (ITileInventory) tile); } else { tile = new InventoryLargeChest( "container.chestDouble", (ITileInventory) tile, (TileEntityChest) localTileEntity); } break; } if (blockChest.g == Type.BASIC) { player.b(StatisticList.ac); } else if (blockChest.g == Type.TRAP) { player.b(StatisticList.W); } if (silentchest) { container = new SilentContainerChest(player.inventory, ((IInventory) tile), player); } } if (block instanceof BlockShulkerBox) { player.b(StatisticList.ae); if (silentchest && tile instanceof TileEntityShulkerBox) { // Set value to current + 1. Ensures consistency later when resetting. SilentContainerShulkerBox.setOpenValue( (TileEntityShulkerBox) tile, SilentContainerShulkerBox.getOpenValue((TileEntityShulkerBox) tile) + 1); container = new SilentContainerShulkerBox(player.inventory, (IInventory) tile, player); } } boolean returnValue = false; final IInventory iInventory = (IInventory) tile; if (!silentchest || container == null) { player.openContainer(iInventory); returnValue = true; } else { try { int windowId = player.nextContainerCounter(); player.playerConnection.sendPacket( new PacketPlayOutOpenWindow( windowId, iInventory.getName(), iInventory.getScoreboardDisplayName(), iInventory.getSize())); player.activeContainer = container; player.activeContainer.windowId = windowId; player.activeContainer.addSlotListener(player); returnValue = true; if (tile instanceof TileEntityShulkerBox) { new BukkitRunnable() { @Override public void run() { // TODO hacky Object tile = world.getTileEntity(blockPosition); if (!(tile instanceof TileEntityShulkerBox)) { return; } TileEntityShulkerBox box = (TileEntityShulkerBox) tile; // Reset back - we added 1, and calling TileEntityShulkerBox#startOpen adds 1 more. SilentContainerShulkerBox.setOpenValue( box, SilentContainerShulkerBox.getOpenValue((TileEntityShulkerBox) tile) - 2); } }.runTaskLater(Bukkit.getPluginManager().getPlugin("OpenInv"), 2); } } catch (Exception e) { e.printStackTrace(); p.sendMessage(ChatColor.RED + "Error while sending silent chest."); } } return returnValue; }
@Override protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) { if (npc == null || !npc.isFlyable()) { super.a(d0, flag, block, blockposition); } }
@Override public void e(float f, float f1) { if (npc == null || !npc.isFlyable()) { super.e(f, f1); } }