From 4c99dc0e7cc456e714a1f043eba9f5232d131514 Mon Sep 17 00:00:00 2001 From: fullwall Date: Sat, 7 Apr 2018 16:02:35 +0800 Subject: [PATCH] Initial 1.8.8 support --- dist/pom.xml | 9 +- .../main/java/net/citizensnpcs/Citizens.java | 4 +- .../java/net/citizensnpcs/EventListen.java | 7 +- .../citizensnpcs/commands/NPCCommands.java | 70 - .../citizensnpcs/editor/EndermanEquipper.java | 4 +- .../citizensnpcs/editor/EquipmentEditor.java | 8 +- .../citizensnpcs/editor/GenericEquipper.java | 117 +- .../net/citizensnpcs/editor/PigEquipper.java | 4 +- .../citizensnpcs/editor/SheepEquipper.java | 4 +- .../net/citizensnpcs/npc/CitizensNPC.java | 22 +- .../npc/CitizensTraitFactory.java | 4 - .../trait/VillagerProfession.java | 4 +- .../waypoint/GuidedWaypointProvider.java | 6 +- .../waypoint/LinearWaypointProvider.java | 6 +- .../waypoint/WanderWaypointProvider.java | 7 +- .../main/java/net/citizensnpcs/util/NMS.java | 15 - .../java/net/citizensnpcs/util/NMSBridge.java | 9 - .../main/java/net/citizensnpcs/util/Util.java | 34 +- pom.xml | 3 +- .../nms/v1_10_R1}/trait/BossBarTrait.java | 6 +- .../nms/v1_10_R1/trait/Commands.java | 90 ++ .../nms/v1_10_R1}/trait/ShulkerTrait.java | 100 +- .../nms/v1_10_R1/util/NMSImpl.java | 71 +- .../v1_10_R1/util/PlayerAnimationImpl.java | 4 +- .../nms/v1_11_R1/trait/BossBarTrait.java | 74 + .../nms/v1_11_R1/trait/Commands.java | 74 + .../nms/v1_11_R1/trait/ShulkerTrait.java | 50 + .../nms/v1_11_R1/util/NMSImpl.java | 67 +- .../v1_11_R1/util/PlayerAnimationImpl.java | 2 +- .../nms/v1_12_R1/trait/BossBarTrait.java | 74 + .../nms/v1_12_R1/trait/Commands.java | 74 + .../nms/v1_12_R1/trait/ShulkerTrait.java | 50 + .../nms/v1_12_R1/util/NMSImpl.java | 67 +- .../v1_12_R1/util/PlayerAnimationImpl.java | 2 +- v1_8_R3/pom.xml | 77 + .../nms/v1_8_R3/entity/BatController.java | 171 +++ .../nms/v1_8_R3/entity/BlazeController.java | 162 ++ .../v1_8_R3/entity/CaveSpiderController.java | 208 +++ .../nms/v1_8_R3/entity/ChickenController.java | 216 +++ .../nms/v1_8_R3/entity/CowController.java | 209 +++ .../nms/v1_8_R3/entity/CreeperController.java | 225 +++ .../v1_8_R3/entity/EnderDragonController.java | 179 +++ .../v1_8_R3/entity/EndermanController.java | 213 +++ .../v1_8_R3/entity/EndermiteController.java | 204 +++ .../nms/v1_8_R3/entity/EntityHumanNPC.java | 497 +++++++ .../nms/v1_8_R3/entity/GhastController.java | 168 +++ .../nms/v1_8_R3/entity/GiantController.java | 205 +++ .../v1_8_R3/entity/GuardianController.java | 218 +++ .../nms/v1_8_R3/entity/HorseController.java | 228 +++ .../nms/v1_8_R3/entity/HumanController.java | 142 ++ .../v1_8_R3/entity/IronGolemController.java | 205 +++ .../v1_8_R3/entity/MagmaCubeController.java | 216 +++ .../v1_8_R3/entity/MobEntityController.java | 61 + .../v1_8_R3/entity/MushroomCowController.java | 207 +++ .../nms/v1_8_R3/entity/OcelotController.java | 214 +++ .../nms/v1_8_R3/entity/PigController.java | 224 +++ .../v1_8_R3/entity/PigZombieController.java | 197 +++ .../nms/v1_8_R3/entity/RabbitController.java | 226 +++ .../nms/v1_8_R3/entity/SheepController.java | 206 +++ .../v1_8_R3/entity/SilverfishController.java | 204 +++ .../v1_8_R3/entity/SkeletonController.java | 205 +++ .../nms/v1_8_R3/entity/SlimeController.java | 217 +++ .../nms/v1_8_R3/entity/SnowmanController.java | 217 +++ .../nms/v1_8_R3/entity/SpiderController.java | 205 +++ .../nms/v1_8_R3/entity/SquidController.java | 197 +++ .../v1_8_R3/entity/VillagerController.java | 236 +++ .../nms/v1_8_R3/entity/WitchController.java | 204 +++ .../nms/v1_8_R3/entity/WitherController.java | 168 +++ .../nms/v1_8_R3/entity/WolfController.java | 223 +++ .../nms/v1_8_R3/entity/ZombieController.java | 196 +++ .../nonliving/ArmorStandController.java | 139 ++ .../entity/nonliving/BoatController.java | 125 ++ .../entity/nonliving/EggController.java | 134 ++ .../nonliving/EnderCrystalController.java | 115 ++ .../nonliving/EnderPearlController.java | 118 ++ .../nonliving/EnderSignalController.java | 115 ++ .../nonliving/ExperienceOrbController.java | 115 ++ .../nonliving/FallingBlockController.java | 170 +++ .../entity/nonliving/FireworkController.java | 115 ++ .../nonliving/FishingHookController.java | 115 ++ .../entity/nonliving/ItemController.java | 153 ++ .../entity/nonliving/ItemFrameController.java | 150 ++ .../nonliving/LargeFireballController.java | 128 ++ .../entity/nonliving/LeashController.java | 120 ++ .../nonliving/MinecartChestController.java | 124 ++ .../nonliving/MinecartCommandController.java | 124 ++ .../nonliving/MinecartFurnaceController.java | 124 ++ .../nonliving/MinecartHopperController.java | 98 ++ .../nonliving/MinecartRideableController.java | 124 ++ .../nonliving/MinecartSpawnerController.java | 98 ++ .../nonliving/MinecartTNTController.java | 98 ++ .../entity/nonliving/PaintingController.java | 120 ++ .../nonliving/SmallFireballController.java | 118 ++ .../entity/nonliving/SnowballController.java | 115 ++ .../entity/nonliving/TNTPrimedController.java | 115 ++ .../nonliving/ThrownExpBottleController.java | 118 ++ .../nonliving/WitherSkullController.java | 115 ++ .../nms/v1_8_R3/network/EmptyChannel.java | 80 + .../nms/v1_8_R3/network/EmptyNetHandler.java | 17 + .../v1_8_R3/network/EmptyNetworkManager.java | 19 + .../nms/v1_8_R3/network/EmptySocket.java | 21 + .../v1_8_R3/util/CitizensBlockBreaker.java | 173 +++ .../nms/v1_8_R3/util/NMSImpl.java | 1314 +++++++++++++++++ .../nms/v1_8_R3/util/PlayerAnimationImpl.java | 119 ++ .../v1_8_R3/util/PlayerControllerJump.java | 21 + .../v1_8_R3/util/PlayerControllerLook.java | 110 ++ .../v1_8_R3/util/PlayerControllerMove.java | 134 ++ .../nms/v1_8_R3/util/PlayerNavigation.java | 431 ++++++ .../nms/v1_8_R3/util/PlayerPathfinder.java | 137 ++ .../util/PlayerPathfinderAbstract.java | 51 + .../v1_8_R3/util/PlayerPathfinderNormal.java | 221 +++ .../v1_8_R3/util/PlayerlistTrackerEntry.java | 96 ++ 112 files changed, 14388 insertions(+), 351 deletions(-) rename {main/src/main/java/net/citizensnpcs => v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1}/trait/BossBarTrait.java (92%) create mode 100644 v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/trait/Commands.java rename {main/src/main/java/net/citizensnpcs => v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1}/trait/ShulkerTrait.java (79%) create mode 100644 v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/trait/BossBarTrait.java create mode 100644 v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/trait/ShulkerTrait.java create mode 100644 v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/trait/BossBarTrait.java create mode 100644 v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/trait/ShulkerTrait.java create mode 100644 v1_8_R3/pom.xml create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/BatController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/BlazeController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/CaveSpiderController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/ChickenController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/CowController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/CreeperController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EnderDragonController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EndermanController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EndermiteController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EntityHumanNPC.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/GhastController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/GiantController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/GuardianController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/HorseController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/HumanController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/IronGolemController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/MagmaCubeController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/MobEntityController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/MushroomCowController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/OcelotController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/PigController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/PigZombieController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/RabbitController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SheepController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SilverfishController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SkeletonController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SlimeController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SnowmanController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SpiderController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SquidController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/VillagerController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/WitchController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/WitherController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/WolfController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/ZombieController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/ArmorStandController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/BoatController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/EggController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/EnderCrystalController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/EnderPearlController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/EnderSignalController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/ExperienceOrbController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/FallingBlockController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/FireworkController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/FishingHookController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/ItemController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/ItemFrameController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/LargeFireballController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/LeashController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartChestController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartCommandController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartFurnaceController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartHopperController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartRideableController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartSpawnerController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartTNTController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/PaintingController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/SmallFireballController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/SnowballController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/TNTPrimedController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/ThrownExpBottleController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/WitherSkullController.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/network/EmptyChannel.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/network/EmptyNetHandler.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/network/EmptyNetworkManager.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/network/EmptySocket.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/CitizensBlockBreaker.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerAnimationImpl.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerControllerJump.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerControllerLook.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerControllerMove.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerNavigation.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerPathfinder.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerPathfinderAbstract.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerPathfinderNormal.java create mode 100644 v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerlistTrackerEntry.java diff --git a/dist/pom.xml b/dist/pom.xml index 20a476777..db555ae84 100644 --- a/dist/pom.xml +++ b/dist/pom.xml @@ -40,7 +40,14 @@ ${project.version} jar compile - + + + ${project.groupId} + citizens-v1_8_R3 + ${project.version} + jar + compile + ${project.groupId} citizens-v1_10_R1 diff --git a/main/src/main/java/net/citizensnpcs/Citizens.java b/main/src/main/java/net/citizensnpcs/Citizens.java index 883963791..77e42378f 100644 --- a/main/src/main/java/net/citizensnpcs/Citizens.java +++ b/main/src/main/java/net/citizensnpcs/Citizens.java @@ -307,7 +307,9 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { startMetrics(); scheduleSaveTask(Setting.SAVE_TASK_DELAY.asInt()); Bukkit.getPluginManager().callEvent(new CitizensEnableEvent()); - new PlayerUpdateTask().runTaskTimer(Citizens.this, 0, 1); + if (!Util.getMinecraftRevision().equals("1_8_R3")) { + new PlayerUpdateTask().runTaskTimer(Citizens.this, 0, 1); + } } }, 1) == -1) { Messaging.severeTr(Messages.LOAD_TASK_NOT_SCHEDULED); diff --git a/main/src/main/java/net/citizensnpcs/EventListen.java b/main/src/main/java/net/citizensnpcs/EventListen.java index 47f40135d..0821d1ba9 100644 --- a/main/src/main/java/net/citizensnpcs/EventListen.java +++ b/main/src/main/java/net/citizensnpcs/EventListen.java @@ -10,7 +10,6 @@ import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.entity.AbstractHorse; import org.bukkit.entity.EntityType; import org.bukkit.entity.FishHook; import org.bukkit.entity.LivingEntity; @@ -46,7 +45,6 @@ import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.event.world.WorldUnloadEvent; -import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.scheduler.BukkitRunnable; @@ -93,6 +91,7 @@ import net.citizensnpcs.trait.Controllable; import net.citizensnpcs.trait.CurrentLocation; import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.NMS; +import net.citizensnpcs.util.Util; public class EventListen implements Listener { private final NPCRegistry npcRegistry = CitizensAPI.getNPCRegistry(); @@ -409,7 +408,7 @@ public class EventListen implements Listener { @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { NPC npc = npcRegistry.getNPC(event.getRightClicked()); - if (npc == null || event.getHand() == EquipmentSlot.OFF_HAND) { + if (npc == null || Util.isOffHand(event)) { return; } Player player = event.getPlayer(); @@ -519,7 +518,7 @@ public class EventListen implements Listener { if (!npcRegistry.isNPC(event.getVehicle())) return; NPC npc = npcRegistry.getNPC(event.getVehicle()); - if ((npc.getEntity() instanceof AbstractHorse || npc.getEntity().getType() == EntityType.BOAT + if ((Util.isHorse(npc.getEntity()) || npc.getEntity().getType() == EntityType.BOAT || npc.getEntity().getType() == EntityType.PIG || npc.getEntity() instanceof Minecart) && (!npc.hasTrait(Controllable.class) || !npc.getTrait(Controllable.class).isEnabled())) { event.setCancelled(true); diff --git a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java index bb072115f..9f09a7708 100644 --- a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -16,8 +16,6 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; -import org.bukkit.boss.BarColor; -import org.bukkit.boss.BarFlag; import org.bukkit.command.BlockCommandSender; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; @@ -48,7 +46,6 @@ import net.citizensnpcs.api.command.CommandContext; import net.citizensnpcs.api.command.CommandMessages; import net.citizensnpcs.api.command.Requirements; import net.citizensnpcs.api.command.exception.CommandException; -import net.citizensnpcs.api.command.exception.CommandUsageException; import net.citizensnpcs.api.command.exception.NoPermissionsException; import net.citizensnpcs.api.command.exception.ServerCommandException; import net.citizensnpcs.api.event.CommandSenderCreateNPCEvent; @@ -72,7 +69,6 @@ import net.citizensnpcs.npc.skin.SkinnableEntity; import net.citizensnpcs.trait.Age; import net.citizensnpcs.trait.Anchors; import net.citizensnpcs.trait.ArmorStandTrait; -import net.citizensnpcs.trait.BossBarTrait; import net.citizensnpcs.trait.Controllable; import net.citizensnpcs.trait.CurrentLocation; import net.citizensnpcs.trait.Gravity; @@ -84,7 +80,6 @@ import net.citizensnpcs.trait.Powered; import net.citizensnpcs.trait.RabbitType; import net.citizensnpcs.trait.ScriptTrait; import net.citizensnpcs.trait.SheepTrait; -import net.citizensnpcs.trait.ShulkerTrait; import net.citizensnpcs.trait.SkinLayers; import net.citizensnpcs.trait.SkinLayers.Layer; import net.citizensnpcs.trait.SlimeSize; @@ -254,38 +249,6 @@ public class NPCCommands { } } - @Command( - aliases = { "npc" }, - usage = "bossbar --color [color] --title [title] --visible [visible] --flags [flags]", - desc = "Edit bossbar properties", - modifiers = { "bossbar" }, - min = 1, - max = 1) - @Requirements(selected = true, ownership = true, types = { EntityType.WITHER, EntityType.ENDER_DRAGON }) - public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws CommandException { - BossBarTrait trait = npc.getTrait(BossBarTrait.class); - if (args.hasValueFlag("color")) { - BarColor color = Util.matchEnum(BarColor.values(), args.getFlag("color")); - trait.setColor(color); - } - if (args.hasValueFlag("title")) { - trait.setTitle(args.getFlag("title")); - } - if (args.hasValueFlag("visible")) { - trait.setVisible(Boolean.parseBoolean(args.getFlag("visible"))); - } - if (args.hasValueFlag("flags")) { - List flags = Lists.newArrayList(); - for (String s : Splitter.on(',').omitEmptyStrings().trimResults().split(args.getFlag("flags"))) { - BarFlag flag = Util.matchEnum(BarFlag.values(), s); - if (flag != null) { - flags.add(flag); - } - } - trait.setFlags(flags); - } - } - @Command( aliases = { "npc" }, usage = "collidable", @@ -1494,39 +1457,6 @@ public class NPCCommands { } } - @Command( - aliases = { "npc" }, - usage = "shulker (--peek [peek] --color [color])", - desc = "Sets shulker modifiers.", - modifiers = { "shulker" }, - min = 1, - max = 1, - permission = "citizens.npc.shulker") - @Requirements(selected = true, ownership = true, types = { EntityType.SHULKER }) - public void shulker(CommandContext args, CommandSender sender, NPC npc) throws CommandException { - ShulkerTrait trait = npc.getTrait(ShulkerTrait.class); - boolean hasArg = false; - if (args.hasValueFlag("peek")) { - int peek = (byte) args.getFlagInteger("peek"); - trait.setPeek(peek); - Messaging.sendTr(sender, Messages.SHULKER_PEEK_SET, npc.getName(), peek); - hasArg = true; - } - if (args.hasValueFlag("color")) { - DyeColor color = Util.matchEnum(DyeColor.values(), args.getFlag("color")); - if (color == null) { - Messaging.sendErrorTr(sender, Messages.INVALID_SHULKER_COLOR, Util.listValuesPretty(DyeColor.values())); - return; - } - trait.setColor(color); - Messaging.sendTr(sender, Messages.SHULKER_COLOR_SET, npc.getName(), Util.prettyEnum(color)); - hasArg = true; - } - if (!hasArg) { - throw new CommandUsageException(); - } - } - @Command( aliases = { "npc" }, usage = "skin (-c -l(atest)) [name]", diff --git a/main/src/main/java/net/citizensnpcs/editor/EndermanEquipper.java b/main/src/main/java/net/citizensnpcs/editor/EndermanEquipper.java index 93587469d..731d93f05 100644 --- a/main/src/main/java/net/citizensnpcs/editor/EndermanEquipper.java +++ b/main/src/main/java/net/citizensnpcs/editor/EndermanEquipper.java @@ -14,7 +14,7 @@ import net.citizensnpcs.util.Messages; public class EndermanEquipper implements Equipper { @Override public void equip(Player equipper, NPC npc) { - ItemStack hand = equipper.getInventory().getItemInMainHand(); + ItemStack hand = equipper.getInventory().getItemInHand(); if (!hand.getType().isBlock()) { Messaging.sendErrorTr(equipper, Messages.EQUIPMENT_EDITOR_INVALID_BLOCK); return; @@ -35,7 +35,7 @@ public class EndermanEquipper implements Equipper { if (set.getType() != Material.AIR) { set.setAmount(1); hand.setAmount(hand.getAmount() - 1); - equipper.getInventory().setItemInMainHand(hand); + equipper.getInventory().setItemInHand(hand); } npc.getTrait(Equipment.class).set(0, set); } diff --git a/main/src/main/java/net/citizensnpcs/editor/EquipmentEditor.java b/main/src/main/java/net/citizensnpcs/editor/EquipmentEditor.java index 4d2f7b49f..b8a42b387 100644 --- a/main/src/main/java/net/citizensnpcs/editor/EquipmentEditor.java +++ b/main/src/main/java/net/citizensnpcs/editor/EquipmentEditor.java @@ -22,6 +22,7 @@ import net.citizensnpcs.api.trait.trait.Equipment; import net.citizensnpcs.api.trait.trait.Equipment.EquipmentSlot; import net.citizensnpcs.api.util.Messaging; import net.citizensnpcs.util.Messages; +import net.citizensnpcs.util.Util; public class EquipmentEditor extends Editor { private final NPC npc; @@ -62,7 +63,7 @@ public class EquipmentEditor extends Editor { public void run() { if (!event.getPlayer().isValid()) return; - ItemStack hand = event.getPlayer().getInventory().getItemInMainHand(); + ItemStack hand = event.getPlayer().getInventory().getItemInHand(); if (hand.getType() == Material.AIR || hand.getAmount() <= 0) { return; } @@ -74,7 +75,7 @@ public class EquipmentEditor extends Editor { newStack.setAmount(1); npc.getTrait(Equipment.class).set(finalSlot, newStack); hand.setAmount(hand.getAmount() - 1); - event.getPlayer().getInventory().setItemInMainHand(hand); + event.getPlayer().getInventory().setItemInHand(hand); } }); event.setCancelled(true); @@ -89,8 +90,7 @@ public class EquipmentEditor extends Editor { @EventHandler public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { - if (!npc.isSpawned() || !event.getPlayer().equals(player) - || event.getHand() != org.bukkit.inventory.EquipmentSlot.HAND + if (!npc.isSpawned() || !event.getPlayer().equals(player) || Util.isOffHand(event) || !npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getRightClicked()))) return; diff --git a/main/src/main/java/net/citizensnpcs/editor/GenericEquipper.java b/main/src/main/java/net/citizensnpcs/editor/GenericEquipper.java index 3dab798dd..5f5a59ce3 100644 --- a/main/src/main/java/net/citizensnpcs/editor/GenericEquipper.java +++ b/main/src/main/java/net/citizensnpcs/editor/GenericEquipper.java @@ -13,67 +13,70 @@ import net.citizensnpcs.util.Messages; public class GenericEquipper implements Equipper { @Override public void equip(Player equipper, NPC toEquip) { - ItemStack hand = equipper.getInventory().getItemInMainHand(); + ItemStack hand = equipper.getInventory().getItemInHand(); Equipment trait = toEquip.getTrait(Equipment.class); EquipmentSlot slot = EquipmentSlot.HAND; Material type = hand == null ? Material.AIR : hand.getType(); // First, determine the slot to edit - switch (type) { - case SKULL_ITEM: - case PUMPKIN: - case JACK_O_LANTERN: - case LEATHER_HELMET: - case CHAINMAIL_HELMET: - case GOLD_HELMET: - case IRON_HELMET: - case DIAMOND_HELMET: - if (!equipper.isSneaking()) { - slot = EquipmentSlot.HELMET; - } - break; - case ELYTRA: - case LEATHER_CHESTPLATE: - case CHAINMAIL_CHESTPLATE: - case GOLD_CHESTPLATE: - case IRON_CHESTPLATE: - case DIAMOND_CHESTPLATE: - if (!equipper.isSneaking()) { - slot = EquipmentSlot.CHESTPLATE; - } - break; - case LEATHER_LEGGINGS: - case CHAINMAIL_LEGGINGS: - case GOLD_LEGGINGS: - case IRON_LEGGINGS: - case DIAMOND_LEGGINGS: - if (!equipper.isSneaking()) { - slot = EquipmentSlot.LEGGINGS; - } - break; - case LEATHER_BOOTS: - case CHAINMAIL_BOOTS: - case GOLD_BOOTS: - case IRON_BOOTS: - case DIAMOND_BOOTS: - if (!equipper.isSneaking()) { - slot = EquipmentSlot.BOOTS; - } - break; - case AIR: - if (equipper.isSneaking()) { - for (int i = 0; i < 6; i++) { - if (trait.get(i) != null && trait.get(i).getType() != Material.AIR) { - equipper.getWorld().dropItemNaturally(toEquip.getEntity().getLocation(), trait.get(i)); - trait.set(i, null); - } + if (type.name().equals("ELYTRA") && !equipper.isSneaking()) { + slot = EquipmentSlot.CHESTPLATE; + } else { + switch (type) { + case SKULL_ITEM: + case PUMPKIN: + case JACK_O_LANTERN: + case LEATHER_HELMET: + case CHAINMAIL_HELMET: + case GOLD_HELMET: + case IRON_HELMET: + case DIAMOND_HELMET: + if (!equipper.isSneaking()) { + slot = EquipmentSlot.HELMET; } - Messaging.sendTr(equipper, Messages.EQUIPMENT_EDITOR_ALL_ITEMS_REMOVED, toEquip.getName()); - } else { - return; - } - break; - default: - break; + break; + case LEATHER_CHESTPLATE: + case CHAINMAIL_CHESTPLATE: + case GOLD_CHESTPLATE: + case IRON_CHESTPLATE: + case DIAMOND_CHESTPLATE: + if (!equipper.isSneaking()) { + slot = EquipmentSlot.CHESTPLATE; + } + break; + case LEATHER_LEGGINGS: + case CHAINMAIL_LEGGINGS: + case GOLD_LEGGINGS: + case IRON_LEGGINGS: + case DIAMOND_LEGGINGS: + if (!equipper.isSneaking()) { + slot = EquipmentSlot.LEGGINGS; + } + break; + case LEATHER_BOOTS: + case CHAINMAIL_BOOTS: + case GOLD_BOOTS: + case IRON_BOOTS: + case DIAMOND_BOOTS: + if (!equipper.isSneaking()) { + slot = EquipmentSlot.BOOTS; + } + break; + case AIR: + if (equipper.isSneaking()) { + for (int i = 0; i < 6; i++) { + if (trait.get(i) != null && trait.get(i).getType() != Material.AIR) { + equipper.getWorld().dropItemNaturally(toEquip.getEntity().getLocation(), trait.get(i)); + trait.set(i, null); + } + } + Messaging.sendTr(equipper, Messages.EQUIPMENT_EDITOR_ALL_ITEMS_REMOVED, toEquip.getName()); + } else { + return; + } + break; + default: + break; + } } // Drop any previous equipment on the ground ItemStack equippedItem = trait.get(slot); @@ -88,7 +91,7 @@ public class GenericEquipper implements Equipper { clone.setAmount(1); trait.set(slot, clone); hand.setAmount(hand.getAmount() - 1); - equipper.getInventory().setItemInMainHand(hand); + equipper.getInventory().setItemInHand(hand); } } } diff --git a/main/src/main/java/net/citizensnpcs/editor/PigEquipper.java b/main/src/main/java/net/citizensnpcs/editor/PigEquipper.java index 081513a1b..f400800fb 100644 --- a/main/src/main/java/net/citizensnpcs/editor/PigEquipper.java +++ b/main/src/main/java/net/citizensnpcs/editor/PigEquipper.java @@ -13,7 +13,7 @@ import net.citizensnpcs.util.Messages; public class PigEquipper implements Equipper { @Override public void equip(Player equipper, NPC toEquip) { - ItemStack hand = equipper.getInventory().getItemInMainHand(); + ItemStack hand = equipper.getInventory().getItemInHand(); Pig pig = (Pig) toEquip.getEntity(); if (hand.getType() == Material.SADDLE) { if (!pig.hasSaddle()) { @@ -26,6 +26,6 @@ public class PigEquipper implements Equipper { toEquip.getTrait(Saddle.class).toggle(); Messaging.sendTr(equipper, Messages.SADDLED_STOPPED, toEquip.getName()); } - equipper.getInventory().setItemInMainHand(hand); + equipper.getInventory().setItemInHand(hand); } } diff --git a/main/src/main/java/net/citizensnpcs/editor/SheepEquipper.java b/main/src/main/java/net/citizensnpcs/editor/SheepEquipper.java index d33e3d30f..26919bf76 100644 --- a/main/src/main/java/net/citizensnpcs/editor/SheepEquipper.java +++ b/main/src/main/java/net/citizensnpcs/editor/SheepEquipper.java @@ -16,7 +16,7 @@ import net.citizensnpcs.util.Messages; public class SheepEquipper implements Equipper { @Override public void equip(Player equipper, NPC toEquip) { - ItemStack hand = equipper.getInventory().getItemInMainHand(); + ItemStack hand = equipper.getInventory().getItemInHand(); Sheep sheep = (Sheep) toEquip.getEntity(); if (hand.getType() == Material.SHEARS) { Messaging.sendTr(equipper, toEquip.getTrait(SheepTrait.class).toggleSheared() ? Messages.SHEARED_SET @@ -35,6 +35,6 @@ public class SheepEquipper implements Equipper { toEquip.getTrait(WoolColor.class).setColor(DyeColor.WHITE); Messaging.sendTr(equipper, Messages.EQUIPMENT_EDITOR_SHEEP_COLOURED, toEquip.getName(), "white"); } - equipper.getInventory().setItemInMainHand(hand); + equipper.getInventory().setItemInHand(hand); } } diff --git a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java index e1d0778ba..d8fd32deb 100644 --- a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java +++ b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java @@ -275,17 +275,19 @@ public class CitizensNPC extends AbstractNPC { NMS.trySwim(getEntity()); } navigator.run(); - - getEntity().setGlowing(data().get(NPC.GLOWING_METADATA, false)); + try { + getEntity().setGlowing(data().get(NPC.GLOWING_METADATA, false)); + } catch (NoSuchMethodError e) { + } if (!getNavigator().isNavigating() && updateCounter++ > Setting.PACKET_UPDATE_DELAY.asInt()) { updateCounter = 0; if (getEntity() instanceof LivingEntity) { - OptionStatus nameVisibility = OptionStatus.NEVER; + boolean nameVisibility = false; if (!getEntity().isCustomNameVisible() && !data(). get(NPC.NAMEPLATE_VISIBLE_METADATA, true).toString().equals("hover")) { getEntity().setCustomName(""); } else { - nameVisibility = OptionStatus.ALWAYS; + nameVisibility = true; getEntity().setCustomName(getFullName()); } String teamName = data().get(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, ""); @@ -296,7 +298,12 @@ public class CitizensNPC extends AbstractNPC { team.unregister(); data().remove(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA); } else { - team.setOption(Option.NAME_TAG_VISIBILITY, nameVisibility); + try { + team.setOption(Option.NAME_TAG_VISIBILITY, + nameVisibility ? OptionStatus.NEVER : OptionStatus.ALWAYS); + } catch (NoSuchMethodError e) { + } catch (NoClassDefFoundError e) { + } if (data().has(NPC.GLOWING_COLOR_METADATA)) { if (team.getPrefix() == null || team.getPrefix().length() == 0 || (data().has("previous-glowing-color") @@ -328,7 +335,10 @@ public class CitizensNPC extends AbstractNPC { } if (data().has(NPC.SILENT_METADATA)) { - getEntity().setSilent(Boolean.parseBoolean(data().get(NPC.SILENT_METADATA).toString())); + try { + getEntity().setSilent(Boolean.parseBoolean(data().get(NPC.SILENT_METADATA).toString())); + } catch (NoSuchMethodError e) { + } } } catch (Exception ex) { Throwable error = Throwables.getRootCause(ex); diff --git a/main/src/main/java/net/citizensnpcs/npc/CitizensTraitFactory.java b/main/src/main/java/net/citizensnpcs/npc/CitizensTraitFactory.java index 366b9fbea..d60e3b9a7 100644 --- a/main/src/main/java/net/citizensnpcs/npc/CitizensTraitFactory.java +++ b/main/src/main/java/net/citizensnpcs/npc/CitizensTraitFactory.java @@ -25,7 +25,6 @@ import net.citizensnpcs.api.trait.trait.Speech; import net.citizensnpcs.trait.Age; import net.citizensnpcs.trait.Anchors; import net.citizensnpcs.trait.ArmorStandTrait; -import net.citizensnpcs.trait.BossBarTrait; import net.citizensnpcs.trait.Controllable; import net.citizensnpcs.trait.CurrentLocation; import net.citizensnpcs.trait.Gravity; @@ -39,7 +38,6 @@ import net.citizensnpcs.trait.RabbitType; import net.citizensnpcs.trait.Saddle; import net.citizensnpcs.trait.ScriptTrait; import net.citizensnpcs.trait.SheepTrait; -import net.citizensnpcs.trait.ShulkerTrait; import net.citizensnpcs.trait.SkinLayers; import net.citizensnpcs.trait.SlimeSize; import net.citizensnpcs.trait.VillagerProfession; @@ -57,7 +55,6 @@ public class CitizensTraitFactory implements TraitFactory { registerTrait(TraitInfo.create(Age.class)); registerTrait(TraitInfo.create(ArmorStandTrait.class)); registerTrait(TraitInfo.create(Anchors.class)); - registerTrait(TraitInfo.create(BossBarTrait.class)); registerTrait(TraitInfo.create(Controllable.class)); registerTrait(TraitInfo.create(Equipment.class)); registerTrait(TraitInfo.create(Gravity.class)); @@ -73,7 +70,6 @@ public class CitizensTraitFactory implements TraitFactory { registerTrait(TraitInfo.create(Saddle.class)); registerTrait(TraitInfo.create(ScriptTrait.class)); registerTrait(TraitInfo.create(SheepTrait.class)); - registerTrait(TraitInfo.create(ShulkerTrait.class)); registerTrait(TraitInfo.create(SkinLayers.class)); registerTrait(TraitInfo.create(MountTrait.class)); registerTrait(TraitInfo.create(SlimeSize.class)); diff --git a/main/src/main/java/net/citizensnpcs/trait/VillagerProfession.java b/main/src/main/java/net/citizensnpcs/trait/VillagerProfession.java index b29de06b6..c8baab2e4 100644 --- a/main/src/main/java/net/citizensnpcs/trait/VillagerProfession.java +++ b/main/src/main/java/net/citizensnpcs/trait/VillagerProfession.java @@ -20,7 +20,7 @@ public class VillagerProfession extends Trait { public void load(DataKey key) throws NPCLoadException { try { profession = Profession.valueOf(key.getString("")); - if (profession == Profession.NORMAL) { + if (profession.name().equals("NORMAL")) { profession = Profession.FARMER; } } catch (IllegalArgumentException ex) { @@ -41,7 +41,7 @@ public class VillagerProfession extends Trait { } public void setProfession(Profession profession) { - if (profession == Profession.NORMAL) { + if (profession.name().equals("NORMAL")) { profession = Profession.FARMER; } this.profession = profession; diff --git a/main/src/main/java/net/citizensnpcs/trait/waypoint/GuidedWaypointProvider.java b/main/src/main/java/net/citizensnpcs/trait/waypoint/GuidedWaypointProvider.java index be7dedbbf..15d782123 100644 --- a/main/src/main/java/net/citizensnpcs/trait/waypoint/GuidedWaypointProvider.java +++ b/main/src/main/java/net/citizensnpcs/trait/waypoint/GuidedWaypointProvider.java @@ -13,7 +13,6 @@ import org.bukkit.event.block.Action; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.EquipmentSlot; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; @@ -115,7 +114,7 @@ public class GuidedWaypointProvider implements EnumerableWaypointProvider { public void onPlayerInteract(PlayerInteractEvent event) { if (!event.getPlayer().equals(player) || event.getAction() == Action.PHYSICAL || event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK - || event.getClickedBlock() == null || event.getHand() == EquipmentSlot.OFF_HAND) + || event.getClickedBlock() == null || Util.isOffHand(event)) return; if (event.getPlayer().getWorld() != npc.getEntity().getWorld()) return; @@ -135,8 +134,7 @@ public class GuidedWaypointProvider implements EnumerableWaypointProvider { @EventHandler(ignoreCancelled = true) public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { - if (!event.getRightClicked().hasMetadata("citizens.waypointhashcode") - || event.getHand() == EquipmentSlot.OFF_HAND) + if (!event.getRightClicked().hasMetadata("citizens.waypointhashcode") || Util.isOffHand(event)) return; int hashcode = event.getRightClicked().getMetadata("citizens.waypointhashcode").get(0).asInt(); Iterator itr = Iterables.concat(available, helpers).iterator(); diff --git a/main/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java b/main/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java index ba005d218..44dad7baa 100644 --- a/main/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java +++ b/main/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java @@ -17,7 +17,6 @@ import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerItemHeldEvent; -import org.bukkit.inventory.EquipmentSlot; import com.google.common.collect.Lists; @@ -264,8 +263,7 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider { @EventHandler(ignoreCancelled = true) public void onPlayerInteract(PlayerInteractEvent event) { if (!event.getPlayer().equals(player) || event.getAction() == Action.PHYSICAL || !npc.isSpawned() - || event.getPlayer().getWorld() != npc.getEntity().getWorld() - || event.getHand() == EquipmentSlot.OFF_HAND) + || event.getPlayer().getWorld() != npc.getEntity().getWorld() || Util.isOffHand(event)) return; if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR) { if (event.getClickedBlock() == null) @@ -309,7 +307,7 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider { @EventHandler(ignoreCancelled = true) public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { - if (!player.equals(event.getPlayer()) || !showPath || event.getHand() == EquipmentSlot.OFF_HAND) + if (!player.equals(event.getPlayer()) || !showPath || Util.isOffHand(event)) return; if (!event.getRightClicked().hasMetadata("waypointindex")) return; diff --git a/main/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java b/main/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java index 568f1f97a..5944511f2 100644 --- a/main/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java +++ b/main/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java @@ -11,7 +11,6 @@ import org.bukkit.event.block.Action; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.EquipmentSlot; import org.bukkit.metadata.FixedMetadataValue; import com.google.common.base.Supplier; @@ -27,6 +26,7 @@ import net.citizensnpcs.api.util.Messaging; import net.citizensnpcs.api.util.cuboid.QuadCuboid; import net.citizensnpcs.api.util.cuboid.QuadTree; import net.citizensnpcs.util.Messages; +import net.citizensnpcs.util.Util; public class WanderWaypointProvider implements WaypointProvider, Supplier { private WanderGoal currentGoal; @@ -122,8 +122,7 @@ public class WanderWaypointProvider implements WaypointProvider, Supplier[] values) { return "" + Joiner.on(", ").join(values).toLowerCase(); } @@ -150,7 +178,7 @@ public class Util { if (parts.contains("*")) return true; for (String part : Splitter.on(',').split(parts)) { - if (Material.matchMaterial(part) == player.getInventory().getItemInMainHand().getType()) { + if (Material.matchMaterial(part) == player.getInventory().getItemInHand().getType()) { return true; } } diff --git a/pom.xml b/pom.xml index 31043334f..5dc633e10 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,8 @@ citizens-parent 2.0.22-SNAPSHOT - main + main + v1_8_R3 v1_10_R1 v1_11_R1 v1_12_R1 diff --git a/main/src/main/java/net/citizensnpcs/trait/BossBarTrait.java b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/trait/BossBarTrait.java similarity index 92% rename from main/src/main/java/net/citizensnpcs/trait/BossBarTrait.java rename to v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/trait/BossBarTrait.java index 52dcb1737..c2371598d 100644 --- a/main/src/main/java/net/citizensnpcs/trait/BossBarTrait.java +++ b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/trait/BossBarTrait.java @@ -1,4 +1,4 @@ -package net.citizensnpcs.trait; +package net.citizensnpcs.nms.v1_10_R1.trait; import java.util.Collection; import java.util.List; @@ -14,7 +14,7 @@ import com.google.common.collect.Lists; import net.citizensnpcs.api.persistence.Persist; import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.TraitName; -import net.citizensnpcs.util.NMS; +import net.citizensnpcs.nms.v1_10_R1.util.NMSImpl; @TraitName("bossbar") public class BossBarTrait extends Trait { @@ -40,7 +40,7 @@ public class BossBarTrait extends Trait { public void run() { if (!npc.isSpawned() || !isBoss(npc.getEntity())) return; - BossBar bar = NMS.getBossBar(npc.getEntity()); + BossBar bar = NMSImpl.getBossBar(npc.getEntity()); bar.setVisible(visible); if (color != null) { bar.setColor(color); diff --git a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/trait/Commands.java b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/trait/Commands.java new file mode 100644 index 000000000..ebca491f6 --- /dev/null +++ b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/trait/Commands.java @@ -0,0 +1,90 @@ +package net.citizensnpcs.nms.v1_10_R1.trait; + +import java.util.List; + +import org.bukkit.DyeColor; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarFlag; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.EntityType; + +import com.google.common.base.Splitter; +import com.google.common.collect.Lists; + +import net.citizensnpcs.api.command.Command; +import net.citizensnpcs.api.command.CommandContext; +import net.citizensnpcs.api.command.Requirements; +import net.citizensnpcs.api.command.exception.CommandException; +import net.citizensnpcs.api.command.exception.CommandUsageException; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.api.util.Messaging; +import net.citizensnpcs.util.Messages; +import net.citizensnpcs.util.Util; + +public class Commands { + + @Command( + aliases = { "npc" }, + usage = "bossbar --color [color] --title [title] --visible [visible] --flags [flags]", + desc = "Edit bossbar properties", + modifiers = { "bossbar" }, + min = 1, + max = 1) + @Requirements(selected = true, ownership = true, types = { EntityType.WITHER, EntityType.ENDER_DRAGON }) + public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws CommandException { + BossBarTrait trait = npc.getTrait(BossBarTrait.class); + if (args.hasValueFlag("color")) { + BarColor color = Util.matchEnum(BarColor.values(), args.getFlag("color")); + trait.setColor(color); + } + if (args.hasValueFlag("title")) { + trait.setTitle(args.getFlag("title")); + } + if (args.hasValueFlag("visible")) { + trait.setVisible(Boolean.parseBoolean(args.getFlag("visible"))); + } + if (args.hasValueFlag("flags")) { + List flags = Lists.newArrayList(); + for (String s : Splitter.on(',').omitEmptyStrings().trimResults().split(args.getFlag("flags"))) { + BarFlag flag = Util.matchEnum(BarFlag.values(), s); + if (flag != null) { + flags.add(flag); + } + } + trait.setFlags(flags); + } + } + + @Command( + aliases = { "npc" }, + usage = "shulker (--peek [peek] --color [color])", + desc = "Sets shulker modifiers.", + modifiers = { "shulker" }, + min = 1, + max = 1, + permission = "citizens.npc.shulker") + @Requirements(selected = true, ownership = true, types = { EntityType.SHULKER }) + public void shulker(CommandContext args, CommandSender sender, NPC npc) throws CommandException { + ShulkerTrait trait = npc.getTrait(ShulkerTrait.class); + boolean hasArg = false; + if (args.hasValueFlag("peek")) { + int peek = (byte) args.getFlagInteger("peek"); + trait.setPeek(peek); + Messaging.sendTr(sender, Messages.SHULKER_PEEK_SET, npc.getName(), peek); + hasArg = true; + } + if (args.hasValueFlag("color")) { + DyeColor color = Util.matchEnum(DyeColor.values(), args.getFlag("color")); + if (color == null) { + Messaging.sendErrorTr(sender, Messages.INVALID_SHULKER_COLOR, Util.listValuesPretty(DyeColor.values())); + return; + } + trait.setColor(color); + Messaging.sendTr(sender, Messages.SHULKER_COLOR_SET, npc.getName(), Util.prettyEnum(color)); + hasArg = true; + } + if (!hasArg) { + throw new CommandUsageException(); + } + } +} diff --git a/main/src/main/java/net/citizensnpcs/trait/ShulkerTrait.java b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/trait/ShulkerTrait.java similarity index 79% rename from main/src/main/java/net/citizensnpcs/trait/ShulkerTrait.java rename to v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/trait/ShulkerTrait.java index af6a9886d..d744695cb 100644 --- a/main/src/main/java/net/citizensnpcs/trait/ShulkerTrait.java +++ b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/trait/ShulkerTrait.java @@ -1,50 +1,50 @@ -package net.citizensnpcs.trait; - -import org.bukkit.DyeColor; -import org.bukkit.entity.Shulker; - -import net.citizensnpcs.api.persistence.Persist; -import net.citizensnpcs.api.trait.Trait; -import net.citizensnpcs.api.trait.TraitName; -import net.citizensnpcs.util.NMS; - -@TraitName("shulkertrait") -public class ShulkerTrait extends Trait { - @Persist("color") - private DyeColor color = DyeColor.PURPLE; - private int lastPeekSet = 0; - @Persist("peek") - private int peek = 0; - - public ShulkerTrait() { - super("shulkertrait"); - } - - @Override - public void onSpawn() { - setPeek(peek); - } - - @Override - public void run() { - if (color == null) { - color = DyeColor.PURPLE; - } - if (npc.getEntity() instanceof Shulker) { - if (peek != lastPeekSet) { - NMS.setShulkerPeek((Shulker) npc.getEntity(), peek); - lastPeekSet = peek; - } - NMS.setShulkerColor((Shulker) npc.getEntity(), color); - } - } - - public void setColor(DyeColor color) { - this.color = color; - } - - public void setPeek(int peek) { - this.peek = peek; - lastPeekSet = -1; - } -} +package net.citizensnpcs.nms.v1_10_R1.trait; + +import org.bukkit.DyeColor; +import org.bukkit.entity.Shulker; + +import net.citizensnpcs.api.persistence.Persist; +import net.citizensnpcs.api.trait.Trait; +import net.citizensnpcs.api.trait.TraitName; +import net.citizensnpcs.nms.v1_10_R1.util.NMSImpl; + +@TraitName("shulkertrait") +public class ShulkerTrait extends Trait { + @Persist("color") + private DyeColor color = DyeColor.PURPLE; + private int lastPeekSet = 0; + @Persist("peek") + private int peek = 0; + + public ShulkerTrait() { + super("shulkertrait"); + } + + @Override + public void onSpawn() { + setPeek(peek); + } + + @Override + public void run() { + if (color == null) { + color = DyeColor.PURPLE; + } + if (npc.getEntity() instanceof Shulker) { + if (peek != lastPeekSet) { + NMSImpl.setShulkerPeek((Shulker) npc.getEntity(), peek); + lastPeekSet = peek; + } + NMSImpl.setShulkerColor((Shulker) npc.getEntity(), color); + } + } + + public void setColor(DyeColor color) { + this.color = color; + } + + public void setPeek(int peek) { + this.peek = peek; + lastPeekSet = -1; + } +} diff --git a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java index 0fc5647f4..9e3ec65ad 100644 --- a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java +++ b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java @@ -57,6 +57,7 @@ import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse; import com.mojang.util.UUIDTypeAdapter; import net.citizensnpcs.Settings.Setting; +import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.ai.NavigatorParameters; import net.citizensnpcs.api.ai.event.CancelReason; import net.citizensnpcs.api.command.CommandManager; @@ -65,6 +66,7 @@ import net.citizensnpcs.api.npc.BlockBreaker; import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPCRegistry; +import net.citizensnpcs.api.trait.TraitInfo; import net.citizensnpcs.api.util.Messaging; import net.citizensnpcs.nms.v1_10_R1.entity.BatController; import net.citizensnpcs.nms.v1_10_R1.entity.BlazeController; @@ -134,6 +136,9 @@ import net.citizensnpcs.nms.v1_10_R1.entity.nonliving.ThrownPotionController; import net.citizensnpcs.nms.v1_10_R1.entity.nonliving.TippedArrowController; import net.citizensnpcs.nms.v1_10_R1.entity.nonliving.WitherSkullController; import net.citizensnpcs.nms.v1_10_R1.network.EmptyChannel; +import net.citizensnpcs.nms.v1_10_R1.trait.BossBarTrait; +import net.citizensnpcs.nms.v1_10_R1.trait.Commands; +import net.citizensnpcs.nms.v1_10_R1.trait.ShulkerTrait; import net.citizensnpcs.npc.EntityControllers; import net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator; import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator; @@ -295,29 +300,6 @@ public class NMSImpl implements NMSBridge { return new CitizensBlockBreaker(entity, targetBlock, config); } - @Override - public BossBar getBossBar(org.bukkit.entity.Entity entity) { - BossBattleServer bserver = null; - try { - if (entity.getType() == EntityType.WITHER) { - bserver = (BossBattleServer) WITHER_BOSS_BAR_FIELD.get(NMSImpl.getHandle(entity)); - } else if (entity.getType() == EntityType.ENDER_DRAGON) { - bserver = (BossBattleServer) ENDERDRAGON_BATTLE_BAR_FIELD - .get(ENDERDRAGON_BATTLE_FIELD.get(NMSImpl.getHandle(entity))); - } - } catch (Exception e) { - } - if (bserver == null) { - return null; - } - BossBar ret = Bukkit.createBossBar("", BarColor.BLUE, BarStyle.SEGMENTED_10); - try { - CRAFT_BOSSBAR_HANDLE_FIELD.set(ret, bserver); - } catch (Exception e) { - } - return ret; - } - @Override public BoundingBox getBoundingBox(org.bukkit.entity.Entity handle) { AxisAlignedBB bb = NMSImpl.getHandle(handle).getBoundingBox(); @@ -528,6 +510,9 @@ public class NMSImpl implements NMSBridge { @Override public void load(CommandManager commands) { + CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(BossBarTrait.class)); + CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(ShulkerTrait.class)); + commands.register(Commands.class); } private void loadEntityTypes() { @@ -884,15 +869,6 @@ public class NMSImpl implements NMSBridge { } } - @Override - public void setShulkerColor(Shulker shulker, DyeColor color) { - } - - @Override - public void setShulkerPeek(Shulker shulker, int peek) { - ((EntityShulker) getHandle(shulker)).a((byte) peek); - } - @Override public void setSitting(Tameable tameable, boolean sitting) { ((EntityTameableAnimal) NMSImpl.getHandle((LivingEntity) tameable)).setSitting(sitting); @@ -914,7 +890,7 @@ public class NMSImpl implements NMSBridge { @Override public void setWitherCharged(Wither wither, boolean charged) { EntityWither handle = ((CraftWither) wither).getHandle(); - handle.l(charged ? 20 : 0); + handle.g(charged ? 20 : 0); } @Override @@ -1273,6 +1249,28 @@ public class NMSImpl implements NMSBridge { entity.aI += entity.aH; } + public static BossBar getBossBar(org.bukkit.entity.Entity entity) { + BossBattleServer bserver = null; + try { + if (entity.getType() == EntityType.WITHER) { + bserver = (BossBattleServer) WITHER_BOSS_BAR_FIELD.get(NMSImpl.getHandle(entity)); + } else if (entity.getType() == EntityType.ENDER_DRAGON) { + bserver = (BossBattleServer) ENDERDRAGON_BATTLE_BAR_FIELD + .get(ENDERDRAGON_BATTLE_FIELD.get(NMSImpl.getHandle(entity))); + } + } catch (Exception e) { + } + if (bserver == null) { + return null; + } + BossBar ret = Bukkit.createBossBar("", BarColor.BLUE, BarStyle.SEGMENTED_10); + try { + CRAFT_BOSSBAR_HANDLE_FIELD.set(ret, bserver); + } catch (Exception e) { + } + return ret; + } + private static EntityLiving getHandle(LivingEntity entity) { return (EntityLiving) NMSImpl.getHandle((org.bukkit.entity.Entity) entity); } @@ -1381,6 +1379,13 @@ public class NMSImpl implements NMSBridge { NMSImpl.sendPacketsNearby(from, location, Arrays.asList(packets), 64); } + public static void setShulkerColor(Shulker shulker, DyeColor color) { + } + + public static void setShulkerPeek(Shulker shulker, int peek) { + ((EntityShulker) getHandle(shulker)).a((byte) peek); + } + public static void setSize(Entity entity, float f, float f1, boolean justCreated) { if ((f != entity.width) || (f1 != entity.length)) { float f2 = entity.width; diff --git a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/PlayerAnimationImpl.java b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/PlayerAnimationImpl.java index 6be29060a..bab4dceb4 100644 --- a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/PlayerAnimationImpl.java +++ b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/PlayerAnimationImpl.java @@ -105,12 +105,12 @@ public class PlayerAnimationImpl { radius); break; case STOP_USE_ITEM: - player.cA(); + player.clearActiveItem(); sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius); break; default: - break; + throw new UnsupportedOperationException(); } } diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/trait/BossBarTrait.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/trait/BossBarTrait.java new file mode 100644 index 000000000..37279a6ff --- /dev/null +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/trait/BossBarTrait.java @@ -0,0 +1,74 @@ +package net.citizensnpcs.nms.v1_11_R1.trait; + +import java.util.Collection; +import java.util.List; + +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarFlag; +import org.bukkit.boss.BossBar; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; + +import com.google.common.collect.Lists; + +import net.citizensnpcs.api.persistence.Persist; +import net.citizensnpcs.api.trait.Trait; +import net.citizensnpcs.api.trait.TraitName; +import net.citizensnpcs.nms.v1_11_R1.util.NMSImpl; + +@TraitName("bossbar") +public class BossBarTrait extends Trait { + @Persist("color") + private BarColor color = null; + @Persist("flags") + private List flags = Lists.newArrayList(); + @Persist("title") + private String title = null; + @Persist("visible") + private boolean visible = true; + + public BossBarTrait() { + super("bossbar"); + } + + private boolean isBoss(Entity entity) { + return entity.getType() == EntityType.ENDER_DRAGON || entity.getType() == EntityType.WITHER + || entity.getType() == EntityType.GUARDIAN; + } + + @Override + public void run() { + if (!npc.isSpawned() || !isBoss(npc.getEntity())) + return; + BossBar bar = NMSImpl.getBossBar(npc.getEntity()); + bar.setVisible(visible); + if (color != null) { + bar.setColor(color); + } + if (title != null) { + bar.setTitle(title); + } + for (BarFlag flag : BarFlag.values()) { + bar.removeFlag(flag); + } + for (BarFlag flag : flags) { + bar.addFlag(flag); + } + } + + public void setColor(BarColor color) { + this.color = color; + } + + public void setFlags(Collection flags) { + this.flags = Lists.newArrayList(flags); + } + + public void setTitle(String title) { + this.title = title; + } + + public void setVisible(boolean visible) { + this.visible = visible; + } +} diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/trait/Commands.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/trait/Commands.java index 88e996891..ab0e2a474 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/trait/Commands.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/trait/Commands.java @@ -1,19 +1,60 @@ package net.citizensnpcs.nms.v1_11_R1.trait; +import java.util.List; + +import org.bukkit.DyeColor; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarFlag; import org.bukkit.command.CommandSender; import org.bukkit.entity.EntityType; import org.bukkit.entity.Llama.Color; +import com.google.common.base.Splitter; +import com.google.common.collect.Lists; + import net.citizensnpcs.api.command.Command; import net.citizensnpcs.api.command.CommandContext; import net.citizensnpcs.api.command.Requirements; import net.citizensnpcs.api.command.exception.CommandException; +import net.citizensnpcs.api.command.exception.CommandUsageException; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.util.Messaging; import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Util; public class Commands { + @Command( + aliases = { "npc" }, + usage = "bossbar --color [color] --title [title] --visible [visible] --flags [flags]", + desc = "Edit bossbar properties", + modifiers = { "bossbar" }, + min = 1, + max = 1) + @Requirements(selected = true, ownership = true, types = { EntityType.WITHER, EntityType.ENDER_DRAGON }) + public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws CommandException { + BossBarTrait trait = npc.getTrait(BossBarTrait.class); + if (args.hasValueFlag("color")) { + BarColor color = Util.matchEnum(BarColor.values(), args.getFlag("color")); + trait.setColor(color); + } + if (args.hasValueFlag("title")) { + trait.setTitle(args.getFlag("title")); + } + if (args.hasValueFlag("visible")) { + trait.setVisible(Boolean.parseBoolean(args.getFlag("visible"))); + } + if (args.hasValueFlag("flags")) { + List flags = Lists.newArrayList(); + for (String s : Splitter.on(',').omitEmptyStrings().trimResults().split(args.getFlag("flags"))) { + BarFlag flag = Util.matchEnum(BarFlag.values(), s); + if (flag != null) { + flags.add(flag); + } + } + trait.setFlags(flags); + } + } + @Command( aliases = { "npc" }, usage = "llama (--color color) (--strength strength)", @@ -44,4 +85,37 @@ public class Commands { Messaging.send(sender, output); } } + + @Command( + aliases = { "npc" }, + usage = "shulker (--peek [peek] --color [color])", + desc = "Sets shulker modifiers.", + modifiers = { "shulker" }, + min = 1, + max = 1, + permission = "citizens.npc.shulker") + @Requirements(selected = true, ownership = true, types = { EntityType.SHULKER }) + public void shulker(CommandContext args, CommandSender sender, NPC npc) throws CommandException { + ShulkerTrait trait = npc.getTrait(ShulkerTrait.class); + boolean hasArg = false; + if (args.hasValueFlag("peek")) { + int peek = (byte) args.getFlagInteger("peek"); + trait.setPeek(peek); + Messaging.sendTr(sender, Messages.SHULKER_PEEK_SET, npc.getName(), peek); + hasArg = true; + } + if (args.hasValueFlag("color")) { + DyeColor color = Util.matchEnum(DyeColor.values(), args.getFlag("color")); + if (color == null) { + Messaging.sendErrorTr(sender, Messages.INVALID_SHULKER_COLOR, Util.listValuesPretty(DyeColor.values())); + return; + } + trait.setColor(color); + Messaging.sendTr(sender, Messages.SHULKER_COLOR_SET, npc.getName(), Util.prettyEnum(color)); + hasArg = true; + } + if (!hasArg) { + throw new CommandUsageException(); + } + } } diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/trait/ShulkerTrait.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/trait/ShulkerTrait.java new file mode 100644 index 000000000..a4e1edf3d --- /dev/null +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/trait/ShulkerTrait.java @@ -0,0 +1,50 @@ +package net.citizensnpcs.nms.v1_11_R1.trait; + +import org.bukkit.DyeColor; +import org.bukkit.entity.Shulker; + +import net.citizensnpcs.api.persistence.Persist; +import net.citizensnpcs.api.trait.Trait; +import net.citizensnpcs.api.trait.TraitName; +import net.citizensnpcs.nms.v1_11_R1.util.NMSImpl; + +@TraitName("shulkertrait") +public class ShulkerTrait extends Trait { + @Persist("color") + private DyeColor color = DyeColor.PURPLE; + private int lastPeekSet = 0; + @Persist("peek") + private int peek = 0; + + public ShulkerTrait() { + super("shulkertrait"); + } + + @Override + public void onSpawn() { + setPeek(peek); + } + + @Override + public void run() { + if (color == null) { + color = DyeColor.PURPLE; + } + if (npc.getEntity() instanceof Shulker) { + if (peek != lastPeekSet) { + NMSImpl.setShulkerPeek((Shulker) npc.getEntity(), peek); + lastPeekSet = peek; + } + NMSImpl.setShulkerColor((Shulker) npc.getEntity(), color); + } + } + + public void setColor(DyeColor color) { + this.color = color; + } + + public void setPeek(int peek) { + this.peek = peek; + lastPeekSet = -1; + } +} diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java index 7658199e8..e5f7a802e 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java @@ -152,8 +152,10 @@ import net.citizensnpcs.nms.v1_11_R1.entity.nonliving.ThrownPotionController; import net.citizensnpcs.nms.v1_11_R1.entity.nonliving.TippedArrowController; import net.citizensnpcs.nms.v1_11_R1.entity.nonliving.WitherSkullController; import net.citizensnpcs.nms.v1_11_R1.network.EmptyChannel; +import net.citizensnpcs.nms.v1_11_R1.trait.BossBarTrait; import net.citizensnpcs.nms.v1_11_R1.trait.Commands; import net.citizensnpcs.nms.v1_11_R1.trait.LlamaTrait; +import net.citizensnpcs.nms.v1_11_R1.trait.ShulkerTrait; import net.citizensnpcs.npc.EntityControllers; import net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator; import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator; @@ -319,29 +321,6 @@ public class NMSImpl implements NMSBridge { return new CitizensBlockBreaker(entity, targetBlock, config); } - @Override - public BossBar getBossBar(org.bukkit.entity.Entity entity) { - BossBattleServer bserver = null; - try { - if (entity.getType() == EntityType.WITHER) { - bserver = (BossBattleServer) WITHER_BOSS_BAR_FIELD.get(NMSImpl.getHandle(entity)); - } else if (entity.getType() == EntityType.ENDER_DRAGON) { - bserver = (BossBattleServer) ENDERDRAGON_BATTLE_BAR_FIELD - .get(ENDERDRAGON_BATTLE_FIELD.get(NMSImpl.getHandle(entity))); - } - } catch (Exception e) { - } - if (bserver == null) { - return null; - } - BossBar ret = Bukkit.createBossBar("", BarColor.BLUE, BarStyle.SEGMENTED_10); - try { - CRAFT_BOSSBAR_HANDLE_FIELD.set(ret, bserver); - } catch (Exception e) { - } - return ret; - } - @Override public BoundingBox getBoundingBox(org.bukkit.entity.Entity handle) { AxisAlignedBB bb = NMSImpl.getHandle(handle).getBoundingBox(); @@ -571,6 +550,8 @@ public class NMSImpl implements NMSBridge { @Override public void load(CommandManager manager) { + CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(BossBarTrait.class)); + CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(ShulkerTrait.class)); CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(LlamaTrait.class)); manager.register(Commands.class); } @@ -947,16 +928,6 @@ public class NMSImpl implements NMSBridge { } } - @Override - public void setShulkerColor(Shulker shulker, DyeColor color) { - ((EntityShulkerNPC) getHandle(shulker)).setColor(color); - } - - @Override - public void setShulkerPeek(Shulker shulker, int peek) { - ((EntityShulker) getHandle(shulker)).a((byte) peek); - } - @Override public void setSitting(Tameable tameable, boolean sitting) { ((EntityTameableAnimal) NMSImpl.getHandle((LivingEntity) tameable)).setSitting(sitting); @@ -1346,6 +1317,28 @@ public class NMSImpl implements NMSBridge { entity.aH += entity.aG; } + public static BossBar getBossBar(org.bukkit.entity.Entity entity) { + BossBattleServer bserver = null; + try { + if (entity.getType() == EntityType.WITHER) { + bserver = (BossBattleServer) WITHER_BOSS_BAR_FIELD.get(NMSImpl.getHandle(entity)); + } else if (entity.getType() == EntityType.ENDER_DRAGON) { + bserver = (BossBattleServer) ENDERDRAGON_BATTLE_BAR_FIELD + .get(ENDERDRAGON_BATTLE_FIELD.get(NMSImpl.getHandle(entity))); + } + } catch (Exception e) { + } + if (bserver == null) { + return null; + } + BossBar ret = Bukkit.createBossBar("", BarColor.BLUE, BarStyle.SEGMENTED_10); + try { + CRAFT_BOSSBAR_HANDLE_FIELD.set(ret, bserver); + } catch (Exception e) { + } + return ret; + } + private static EntityLiving getHandle(LivingEntity entity) { return (EntityLiving) NMSImpl.getHandle((org.bukkit.entity.Entity) entity); } @@ -1454,6 +1447,14 @@ public class NMSImpl implements NMSBridge { NMSImpl.sendPacketsNearby(from, location, Arrays.asList(packets), 64); } + public static void setShulkerColor(Shulker shulker, DyeColor color) { + ((EntityShulkerNPC) getHandle(shulker)).setColor(color); + } + + public static void setShulkerPeek(Shulker shulker, int peek) { + ((EntityShulker) getHandle(shulker)).a((byte) peek); + } + public static void setSize(Entity entity, float f, float f1, boolean justCreated) { if ((f != entity.width) || (f1 != entity.length)) { float f2 = entity.width; diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/PlayerAnimationImpl.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/PlayerAnimationImpl.java index 23160d291..28a0befcc 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/PlayerAnimationImpl.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/PlayerAnimationImpl.java @@ -110,7 +110,7 @@ public class PlayerAnimationImpl { radius); break; default: - break; + throw new UnsupportedOperationException(); } } diff --git a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/trait/BossBarTrait.java b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/trait/BossBarTrait.java new file mode 100644 index 000000000..27c0a6f51 --- /dev/null +++ b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/trait/BossBarTrait.java @@ -0,0 +1,74 @@ +package net.citizensnpcs.nms.v1_12_R1.trait; + +import java.util.Collection; +import java.util.List; + +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarFlag; +import org.bukkit.boss.BossBar; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; + +import com.google.common.collect.Lists; + +import net.citizensnpcs.api.persistence.Persist; +import net.citizensnpcs.api.trait.Trait; +import net.citizensnpcs.api.trait.TraitName; +import net.citizensnpcs.nms.v1_12_R1.util.NMSImpl; + +@TraitName("bossbar") +public class BossBarTrait extends Trait { + @Persist("color") + private BarColor color = null; + @Persist("flags") + private List flags = Lists.newArrayList(); + @Persist("title") + private String title = null; + @Persist("visible") + private boolean visible = true; + + public BossBarTrait() { + super("bossbar"); + } + + private boolean isBoss(Entity entity) { + return entity.getType() == EntityType.ENDER_DRAGON || entity.getType() == EntityType.WITHER + || entity.getType() == EntityType.GUARDIAN; + } + + @Override + public void run() { + if (!npc.isSpawned() || !isBoss(npc.getEntity())) + return; + BossBar bar = NMSImpl.getBossBar(npc.getEntity()); + bar.setVisible(visible); + if (color != null) { + bar.setColor(color); + } + if (title != null) { + bar.setTitle(title); + } + for (BarFlag flag : BarFlag.values()) { + bar.removeFlag(flag); + } + for (BarFlag flag : flags) { + bar.addFlag(flag); + } + } + + public void setColor(BarColor color) { + this.color = color; + } + + public void setFlags(Collection flags) { + this.flags = Lists.newArrayList(flags); + } + + public void setTitle(String title) { + this.title = title; + } + + public void setVisible(boolean visible) { + this.visible = visible; + } +} diff --git a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/trait/Commands.java b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/trait/Commands.java index 84d12a6ae..d81d631b8 100644 --- a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/trait/Commands.java +++ b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/trait/Commands.java @@ -1,20 +1,61 @@ package net.citizensnpcs.nms.v1_12_R1.trait; +import java.util.List; + +import org.bukkit.DyeColor; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarFlag; import org.bukkit.command.CommandSender; import org.bukkit.entity.EntityType; import org.bukkit.entity.Llama.Color; import org.bukkit.entity.Parrot.Variant; +import com.google.common.base.Splitter; +import com.google.common.collect.Lists; + import net.citizensnpcs.api.command.Command; import net.citizensnpcs.api.command.CommandContext; import net.citizensnpcs.api.command.Requirements; import net.citizensnpcs.api.command.exception.CommandException; +import net.citizensnpcs.api.command.exception.CommandUsageException; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.util.Messaging; import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Util; public class Commands { + @Command( + aliases = { "npc" }, + usage = "bossbar --color [color] --title [title] --visible [visible] --flags [flags]", + desc = "Edit bossbar properties", + modifiers = { "bossbar" }, + min = 1, + max = 1) + @Requirements(selected = true, ownership = true, types = { EntityType.WITHER, EntityType.ENDER_DRAGON }) + public void bossbar(CommandContext args, CommandSender sender, NPC npc) throws CommandException { + BossBarTrait trait = npc.getTrait(BossBarTrait.class); + if (args.hasValueFlag("color")) { + BarColor color = Util.matchEnum(BarColor.values(), args.getFlag("color")); + trait.setColor(color); + } + if (args.hasValueFlag("title")) { + trait.setTitle(args.getFlag("title")); + } + if (args.hasValueFlag("visible")) { + trait.setVisible(Boolean.parseBoolean(args.getFlag("visible"))); + } + if (args.hasValueFlag("flags")) { + List flags = Lists.newArrayList(); + for (String s : Splitter.on(',').omitEmptyStrings().trimResults().split(args.getFlag("flags"))) { + BarFlag flag = Util.matchEnum(BarFlag.values(), s); + if (flag != null) { + flags.add(flag); + } + } + trait.setFlags(flags); + } + } + @Command( aliases = { "npc" }, usage = "llama (--color color) (--strength strength)", @@ -72,4 +113,37 @@ public class Commands { Messaging.send(sender, output); } } + + @Command( + aliases = { "npc" }, + usage = "shulker (--peek [peek] --color [color])", + desc = "Sets shulker modifiers.", + modifiers = { "shulker" }, + min = 1, + max = 1, + permission = "citizens.npc.shulker") + @Requirements(selected = true, ownership = true, types = { EntityType.SHULKER }) + public void shulker(CommandContext args, CommandSender sender, NPC npc) throws CommandException { + ShulkerTrait trait = npc.getTrait(ShulkerTrait.class); + boolean hasArg = false; + if (args.hasValueFlag("peek")) { + int peek = (byte) args.getFlagInteger("peek"); + trait.setPeek(peek); + Messaging.sendTr(sender, Messages.SHULKER_PEEK_SET, npc.getName(), peek); + hasArg = true; + } + if (args.hasValueFlag("color")) { + DyeColor color = Util.matchEnum(DyeColor.values(), args.getFlag("color")); + if (color == null) { + Messaging.sendErrorTr(sender, Messages.INVALID_SHULKER_COLOR, Util.listValuesPretty(DyeColor.values())); + return; + } + trait.setColor(color); + Messaging.sendTr(sender, Messages.SHULKER_COLOR_SET, npc.getName(), Util.prettyEnum(color)); + hasArg = true; + } + if (!hasArg) { + throw new CommandUsageException(); + } + } } diff --git a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/trait/ShulkerTrait.java b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/trait/ShulkerTrait.java new file mode 100644 index 000000000..569662820 --- /dev/null +++ b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/trait/ShulkerTrait.java @@ -0,0 +1,50 @@ +package net.citizensnpcs.nms.v1_12_R1.trait; + +import org.bukkit.DyeColor; +import org.bukkit.entity.Shulker; + +import net.citizensnpcs.api.persistence.Persist; +import net.citizensnpcs.api.trait.Trait; +import net.citizensnpcs.api.trait.TraitName; +import net.citizensnpcs.nms.v1_12_R1.util.NMSImpl; + +@TraitName("shulkertrait") +public class ShulkerTrait extends Trait { + @Persist("color") + private DyeColor color = DyeColor.PURPLE; + private int lastPeekSet = 0; + @Persist("peek") + private int peek = 0; + + public ShulkerTrait() { + super("shulkertrait"); + } + + @Override + public void onSpawn() { + setPeek(peek); + } + + @Override + public void run() { + if (color == null) { + color = DyeColor.PURPLE; + } + if (npc.getEntity() instanceof Shulker) { + if (peek != lastPeekSet) { + NMSImpl.setShulkerPeek((Shulker) npc.getEntity(), peek); + lastPeekSet = peek; + } + NMSImpl.setShulkerColor((Shulker) npc.getEntity(), color); + } + } + + public void setColor(DyeColor color) { + this.color = color; + } + + public void setPeek(int peek) { + this.peek = peek; + lastPeekSet = -1; + } +} diff --git a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java index 8d4f57541..9267b5c98 100644 --- a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java +++ b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java @@ -153,9 +153,11 @@ import net.citizensnpcs.nms.v1_12_R1.entity.nonliving.ThrownPotionController; import net.citizensnpcs.nms.v1_12_R1.entity.nonliving.TippedArrowController; import net.citizensnpcs.nms.v1_12_R1.entity.nonliving.WitherSkullController; import net.citizensnpcs.nms.v1_12_R1.network.EmptyChannel; +import net.citizensnpcs.nms.v1_12_R1.trait.BossBarTrait; import net.citizensnpcs.nms.v1_12_R1.trait.Commands; import net.citizensnpcs.nms.v1_12_R1.trait.LlamaTrait; import net.citizensnpcs.nms.v1_12_R1.trait.ParrotTrait; +import net.citizensnpcs.nms.v1_12_R1.trait.ShulkerTrait; import net.citizensnpcs.npc.EntityControllers; import net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator; import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator; @@ -322,29 +324,6 @@ public class NMSImpl implements NMSBridge { return new CitizensBlockBreaker(entity, targetBlock, config); } - @Override - public BossBar getBossBar(org.bukkit.entity.Entity entity) { - BossBattleServer bserver = null; - try { - if (entity.getType() == EntityType.WITHER) { - bserver = (BossBattleServer) WITHER_BOSS_BAR_FIELD.get(NMSImpl.getHandle(entity)); - } else if (entity.getType() == EntityType.ENDER_DRAGON) { - bserver = (BossBattleServer) ENDERDRAGON_BATTLE_BAR_FIELD - .get(ENDERDRAGON_BATTLE_FIELD.get(NMSImpl.getHandle(entity))); - } - } catch (Exception e) { - } - if (bserver == null) { - return null; - } - BossBar ret = Bukkit.createBossBar("", BarColor.BLUE, BarStyle.SEGMENTED_10); - try { - CRAFT_BOSSBAR_HANDLE_FIELD.set(ret, bserver); - } catch (Exception e) { - } - return ret; - } - @Override public BoundingBox getBoundingBox(org.bukkit.entity.Entity handle) { AxisAlignedBB bb = NMSImpl.getHandle(handle).getBoundingBox(); @@ -576,6 +555,8 @@ public class NMSImpl implements NMSBridge { public void load(CommandManager manager) { CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(LlamaTrait.class)); CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(ParrotTrait.class)); + CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(BossBarTrait.class)); + CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(ShulkerTrait.class)); manager.register(Commands.class); } @@ -961,16 +942,6 @@ public class NMSImpl implements NMSBridge { } } - @Override - public void setShulkerColor(Shulker shulker, DyeColor color) { - ((EntityShulker) getHandle(shulker)).getDataWatcher().set(EntityShulker.COLOR, color.getWoolData()); - } - - @Override - public void setShulkerPeek(Shulker shulker, int peek) { - ((EntityShulker) getHandle(shulker)).a((byte) peek); - } - @Override public void setSitting(Tameable tameable, boolean sitting) { ((EntityTameableAnimal) NMSImpl.getHandle((LivingEntity) tameable)).setSitting(sitting); @@ -1359,6 +1330,28 @@ public class NMSImpl implements NMSBridge { entity.aH += entity.aG; } + public static BossBar getBossBar(org.bukkit.entity.Entity entity) { + BossBattleServer bserver = null; + try { + if (entity.getType() == EntityType.WITHER) { + bserver = (BossBattleServer) WITHER_BOSS_BAR_FIELD.get(NMSImpl.getHandle(entity)); + } else if (entity.getType() == EntityType.ENDER_DRAGON) { + bserver = (BossBattleServer) ENDERDRAGON_BATTLE_BAR_FIELD + .get(ENDERDRAGON_BATTLE_FIELD.get(NMSImpl.getHandle(entity))); + } + } catch (Exception e) { + } + if (bserver == null) { + return null; + } + BossBar ret = Bukkit.createBossBar("", BarColor.BLUE, BarStyle.SEGMENTED_10); + try { + CRAFT_BOSSBAR_HANDLE_FIELD.set(ret, bserver); + } catch (Exception e) { + } + return ret; + } + private static EntityLiving getHandle(LivingEntity entity) { return (EntityLiving) NMSImpl.getHandle((org.bukkit.entity.Entity) entity); } @@ -1467,6 +1460,14 @@ public class NMSImpl implements NMSBridge { NMSImpl.sendPacketsNearby(from, location, Arrays.asList(packets), 64); } + public static void setShulkerColor(Shulker shulker, DyeColor color) { + ((EntityShulker) getHandle(shulker)).getDataWatcher().set(EntityShulker.COLOR, color.getWoolData()); + } + + public static void setShulkerPeek(Shulker shulker, int peek) { + ((EntityShulker) getHandle(shulker)).a((byte) peek); + } + public static void setSize(Entity entity, float f, float f1, boolean justCreated) { if ((f != entity.width) || (f1 != entity.length)) { float f2 = entity.width; diff --git a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/PlayerAnimationImpl.java b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/PlayerAnimationImpl.java index 0f2b884b3..1621eeabf 100644 --- a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/PlayerAnimationImpl.java +++ b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/PlayerAnimationImpl.java @@ -110,7 +110,7 @@ public class PlayerAnimationImpl { radius); break; default: - break; + throw new UnsupportedOperationException(); } } diff --git a/v1_8_R3/pom.xml b/v1_8_R3/pom.xml new file mode 100644 index 000000000..a8916edc9 --- /dev/null +++ b/v1_8_R3/pom.xml @@ -0,0 +1,77 @@ + + + 4.0.0 + + net.citizensnpcs + citizens-parent + 2.0.22-SNAPSHOT + + citizens-v1_8_R3 + + + UTF-8 + 1.8.7-R0.1-SNAPSHOT + + + + + everything + http://repo.citizensnpcs.co + + + + + + ${project.groupId} + citizens-main + ${project.version} + jar + provided + + + org.bukkit + craftbukkit + ${craftbukkit.version} + jar + provided + + + + + clean package install + ${basedir}/src/main/java + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.3.2 + + + + org.apache.maven.plugins + maven-shade-plugin + 2.1 + + + package + + shade + + + + + + + diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/BatController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/BatController.java new file mode 100644 index 000000000..30015e28e --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/BatController.java @@ -0,0 +1,171 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftBat; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.entity.Bat; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.EntityBat; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class BatController extends MobEntityController { + public BatController() { + super(EntityBatNPC.class); + } + + @Override + public Bat getBukkitEntity() { + return (Bat) super.getBukkitEntity(); + } + + public static class BatNPC extends CraftBat implements NPCHolder { + private final CitizensNPC npc; + + public BatNPC(EntityBatNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class EntityBatNPC extends EntityBat implements NPCHolder { + private final CitizensNPC npc; + + public EntityBatNPC(World world) { + this(world, null); + } + + public EntityBatNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + setFlying(false); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) { + return super.cc(); + } + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void E() { + if (npc == null) { + super.E(); + } else { + NMSImpl.updateAI(this); + npc.update(); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new BatNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + public void setFlying(boolean flying) { + setAsleep(flying); + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/BlazeController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/BlazeController.java new file mode 100644 index 000000000..c96ba22db --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/BlazeController.java @@ -0,0 +1,162 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftBlaze; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.entity.Blaze; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.EntityBlaze; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class BlazeController extends MobEntityController { + public BlazeController() { + super(EntityBlazeNPC.class); + } + + @Override + public Blaze getBukkitEntity() { + return (Blaze) super.getBukkitEntity(); + } + + public static class BlazeNPC extends CraftBlaze implements NPCHolder { + private final CitizensNPC npc; + + public BlazeNPC(EntityBlazeNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class EntityBlazeNPC extends EntityBlaze implements NPCHolder { + private final CitizensNPC npc; + + public EntityBlazeNPC(World world) { + this(world, null); + } + + public EntityBlazeNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void E() { + if (npc != null) { + npc.update(); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new BlazeNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/CaveSpiderController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/CaveSpiderController.java new file mode 100644 index 000000000..4c4ffcc72 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/CaveSpiderController.java @@ -0,0 +1,208 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftCaveSpider; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.entity.CaveSpider; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityCaveSpider; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class CaveSpiderController extends MobEntityController { + public CaveSpiderController() { + super(EntityCaveSpiderNPC.class); + } + + @Override + public CaveSpider getBukkitEntity() { + return (CaveSpider) super.getBukkitEntity(); + } + + public static class CaveSpiderNPC extends CraftCaveSpider implements NPCHolder { + private final CitizensNPC npc; + + public CaveSpiderNPC(EntityCaveSpiderNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class EntityCaveSpiderNPC extends EntityCaveSpider implements NPCHolder { + private final CitizensNPC npc; + + public EntityCaveSpiderNPC(World world) { + this(world, null); + } + + public EntityCaveSpiderNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) { + return super.cc(); + } + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) { + return super.cc(); + } + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + super.E(); + if (npc != null) { + npc.update(); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new CaveSpiderNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + public void setSize(float f, float f1) { + if (npc == null) { + super.setSize(f, f1); + } else { + NMSImpl.setSize(this, f, f1, justCreated); + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/ChickenController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/ChickenController.java new file mode 100644 index 000000000..7c3f4e12c --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/ChickenController.java @@ -0,0 +1,216 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftChicken; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.entity.Chicken; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityChicken; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class ChickenController extends MobEntityController { + public ChickenController() { + super(EntityChickenNPC.class); + } + + @Override + public Chicken getBukkitEntity() { + return (Chicken) super.getBukkitEntity(); + } + + public static class ChickenNPC extends CraftChicken implements NPCHolder { + private final CitizensNPC npc; + + public ChickenNPC(EntityChickenNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class EntityChickenNPC extends EntityChicken implements NPCHolder { + private final CitizensNPC npc; + + public EntityChickenNPC(World world) { + this(world, null); + } + + public EntityChickenNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + public void a(boolean flag) { + float oldw = width; + float oldl = length; + super.a(flag); + if (oldw != width || oldl != length) { + this.setPosition(locX - 0.01, locY, locZ - 0.01); + this.setPosition(locX + 0.01, locY, locZ + 0.01); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + super.E(); + if (npc != null) { + npc.update(); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new ChickenNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + public void m() { + if (npc != null) { + this.bs = 100; // egg timer + } + super.m(); + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/CowController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/CowController.java new file mode 100644 index 000000000..9d5e80fb7 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/CowController.java @@ -0,0 +1,209 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftCow; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.entity.Cow; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityCow; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class CowController extends MobEntityController { + public CowController() { + super(EntityCowNPC.class); + } + + @Override + public Cow getBukkitEntity() { + return (Cow) super.getBukkitEntity(); + } + + public static class CowNPC extends CraftCow implements NPCHolder { + private final CitizensNPC npc; + + public CowNPC(EntityCowNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class EntityCowNPC extends EntityCow implements NPCHolder { + private final CitizensNPC npc; + + public EntityCowNPC(World world) { + this(world, null); + } + + public EntityCowNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + + } + } + + @Override + public void a(boolean flag) { + float oldw = width; + float oldl = length; + super.a(flag); + if (oldw != width || oldl != length) { + this.setPosition(locX - 0.01, locY, locZ - 0.01); + this.setPosition(locX + 0.01, locY, locZ + 0.01); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + super.E(); + if (npc != null) { + npc.update(); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new CowNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/CreeperController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/CreeperController.java new file mode 100644 index 000000000..2884f6758 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/CreeperController.java @@ -0,0 +1,225 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftCreeper; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.entity.Creeper; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityCreeper; +import net.minecraft.server.v1_8_R3.EntityHuman; +import net.minecraft.server.v1_8_R3.EntityLightning; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class CreeperController extends MobEntityController { + public CreeperController() { + super(EntityCreeperNPC.class); + } + + @Override + public Creeper getBukkitEntity() { + return (Creeper) super.getBukkitEntity(); + } + + public static class CreeperNPC extends CraftCreeper implements NPCHolder { + private final CitizensNPC npc; + + public CreeperNPC(EntityCreeperNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class EntityCreeperNPC extends EntityCreeper implements NPCHolder { + private boolean allowPowered; + private final CitizensNPC npc; + + public EntityCreeperNPC(World world) { + this(world, null); + } + + public EntityCreeperNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected boolean a(EntityHuman entityhuman) { + return npc == null || !npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true) ? super.a(entityhuman) : false; + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + super.E(); + if (npc != null) { + npc.update(); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) { + super.g(x, y, z); + } + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new CreeperNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + public void onLightningStrike(EntityLightning entitylightning) { + if (npc == null || allowPowered) { + super.onLightningStrike(entitylightning); + } + } + + public void setAllowPowered(boolean allowPowered) { + this.allowPowered = allowPowered; + } + + @Override + public void setSize(float f, float f1) { + if (npc == null) { + super.setSize(f, f1); + } else { + NMSImpl.setSize(this, f, f1, justCreated); + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EnderDragonController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EnderDragonController.java new file mode 100644 index 000000000..07cb4e8e5 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EnderDragonController.java @@ -0,0 +1,179 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEnderDragon; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.entity.EnderDragon; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.EntityEnderDragon; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class EnderDragonController extends MobEntityController { + public EnderDragonController() { + super(EntityEnderDragonNPC.class); + } + + @Override + public EnderDragon getBukkitEntity() { + return (EnderDragon) super.getBukkitEntity(); + } + + public static class EnderDragonNPC extends CraftEnderDragon implements NPCHolder { + private final CitizensNPC npc; + + public EnderDragonNPC(EntityEnderDragonNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class EntityEnderDragonNPC extends EntityEnderDragon implements NPCHolder { + private final CitizensNPC npc; + + public EntityEnderDragonNPC(World world) { + this(world, null); + } + + public EntityEnderDragonNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new EnderDragonNPC(this); + return super.getBukkitEntity(); + } + + private float getCorrectYaw(double tX, double tZ) { + if (locZ > tZ) + return (float) (-Math.toDegrees(Math.atan((locX - tX) / (locZ - tZ)))); + if (locZ < tZ) { + return (float) (-Math.toDegrees(Math.atan((locX - tX) / (locZ - tZ)))) + 180.0F; + } + return yaw; + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void m() { + if (npc != null) { + npc.update(); + if (motX != 0 || motY != 0 || motZ != 0) { + motX *= 0.98; + motY *= 0.98; + motZ *= 0.98; + yaw = getCorrectYaw(locX + motX, locZ + motZ); + setPosition(locX + motX, locY + motY, locZ + motZ); + } + } else { + super.m(); + } + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EndermanController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EndermanController.java new file mode 100644 index 000000000..f7d1175f4 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EndermanController.java @@ -0,0 +1,213 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEnderman; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.entity.Enderman; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityEnderman; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class EndermanController extends MobEntityController { + public EndermanController() { + super(EntityEndermanNPC.class); + } + + @Override + public Enderman getBukkitEntity() { + return (Enderman) super.getBukkitEntity(); + } + + public static class EndermanNPC extends CraftEnderman implements NPCHolder { + private final CitizensNPC npc; + + public EndermanNPC(EntityEndermanNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class EntityEndermanNPC extends EntityEnderman implements NPCHolder { + private final CitizensNPC npc; + + public EntityEndermanNPC(World world) { + this(world, null); + } + + public EntityEndermanNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + super.E(); + if (npc != null) { + npc.update(); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new EndermanNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k(double d1, double d2, double d3) { + if (npc == null) { + return super.k(d1, d2, d3); + } + return false; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + public void setSize(float f, float f1) { + if (npc == null) { + super.setSize(f, f1); + } else { + NMSImpl.setSize(this, f, f1, justCreated); + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EndermiteController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EndermiteController.java new file mode 100644 index 000000000..40f5644b6 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EndermiteController.java @@ -0,0 +1,204 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEndermite; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.entity.Endermite; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityEndermite; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class EndermiteController extends MobEntityController { + public EndermiteController() { + super(EntityEndermiteNPC.class); + } + + @Override + public Endermite getBukkitEntity() { + return (Endermite) super.getBukkitEntity(); + } + + public static class EndermiteNPC extends CraftEndermite implements NPCHolder { + private final CitizensNPC npc; + + public EndermiteNPC(EntityEndermiteNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class EntityEndermiteNPC extends EntityEndermite implements NPCHolder { + private final CitizensNPC npc; + + public EntityEndermiteNPC(World world) { + this(world, null); + } + + public EntityEndermiteNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + super.E(); + if (npc != null) + npc.update(); + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new EndermiteNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + public void setSize(float f, float f1) { + if (npc == null) { + super.setSize(f, f1); + } else { + NMSImpl.setSize(this, f, f1, justCreated); + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EntityHumanNPC.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EntityHumanNPC.java new file mode 100644 index 000000000..1d0cd019a --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/EntityHumanNPC.java @@ -0,0 +1,497 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import java.io.IOException; +import java.net.Socket; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.metadata.MetadataValue; +import org.bukkit.plugin.Plugin; +import org.bukkit.util.Vector; + +import com.google.common.base.Preconditions; +import com.mojang.authlib.GameProfile; + +import net.citizensnpcs.Settings.Setting; +import net.citizensnpcs.api.CitizensAPI; +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.MetadataStore; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.api.trait.trait.Inventory; +import net.citizensnpcs.nms.v1_8_R3.network.EmptyNetHandler; +import net.citizensnpcs.nms.v1_8_R3.network.EmptyNetworkManager; +import net.citizensnpcs.nms.v1_8_R3.network.EmptySocket; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.nms.v1_8_R3.util.PlayerControllerJump; +import net.citizensnpcs.nms.v1_8_R3.util.PlayerControllerLook; +import net.citizensnpcs.nms.v1_8_R3.util.PlayerControllerMove; +import net.citizensnpcs.nms.v1_8_R3.util.PlayerNavigation; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.npc.skin.SkinPacketTracker; +import net.citizensnpcs.npc.skin.SkinnableEntity; +import net.citizensnpcs.trait.Gravity; +import net.citizensnpcs.util.NMS; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.AttributeInstance; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.DamageSource; +import net.minecraft.server.v1_8_R3.Entity; +import net.minecraft.server.v1_8_R3.EntityPlayer; +import net.minecraft.server.v1_8_R3.EnumProtocolDirection; +import net.minecraft.server.v1_8_R3.GenericAttributes; +import net.minecraft.server.v1_8_R3.MathHelper; +import net.minecraft.server.v1_8_R3.MinecraftServer; +import net.minecraft.server.v1_8_R3.NavigationAbstract; +import net.minecraft.server.v1_8_R3.NetworkManager; +import net.minecraft.server.v1_8_R3.Packet; +import net.minecraft.server.v1_8_R3.PacketPlayOutEntityEquipment; +import net.minecraft.server.v1_8_R3.PacketPlayOutEntityHeadRotation; +import net.minecraft.server.v1_8_R3.PlayerInteractManager; +import net.minecraft.server.v1_8_R3.WorldServer; +import net.minecraft.server.v1_8_R3.WorldSettings; + +public class EntityHumanNPC extends EntityPlayer implements NPCHolder, SkinnableEntity { + private PlayerControllerJump controllerJump; + private PlayerControllerLook controllerLook; + private PlayerControllerMove controllerMove; + private int jumpTicks = 0; + private PlayerNavigation navigation; + private final CitizensNPC npc; + private final Location packetLocationCache = new Location(null, 0, 0, 0); + private final SkinPacketTracker skinTracker; + private int updateCounter = 0; + + public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile, + PlayerInteractManager playerInteractManager, NPC npc) { + super(minecraftServer, world, gameProfile, playerInteractManager); + + this.npc = (CitizensNPC) npc; + if (npc != null) { + skinTracker = new SkinPacketTracker(this); + playerInteractManager.setGameMode(WorldSettings.EnumGamemode.SURVIVAL); + initialise(minecraftServer); + } else { + skinTracker = null; + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + public boolean ae() { + return npc == null ? super.ae() : npc.data().get(NPC.COLLIDABLE_METADATA, true); + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean damageEntity(DamageSource damagesource, float f) { + // knock back velocity is cancelled and sent to client for handling when + // the entity is a player. there is no client so make this happen + // manually. + boolean damaged = super.damageEntity(damagesource, f); + if (damaged && velocityChanged) { + velocityChanged = false; + Bukkit.getScheduler().runTask(CitizensAPI.getPlugin(), new Runnable() { + @Override + public void run() { + EntityHumanNPC.this.velocityChanged = true; + } + }); + } + return damaged; + } + + @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 void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) { + super.g(x, y, z); + } + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftPlayer getBukkitEntity() { + if (npc != null && bukkitEntity == null) { + bukkitEntity = new PlayerNPC(this); + } + return super.getBukkitEntity(); + } + + public PlayerControllerJump getControllerJump() { + return controllerJump; + } + + public PlayerControllerMove getControllerMove() { + return controllerMove; + } + + public NavigationAbstract getNavigation() { + return navigation; + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public String getSkinName() { + MetadataStore meta = npc.data(); + + String skinName = meta.get(NPC.PLAYER_SKIN_UUID_METADATA); + if (skinName == null) { + skinName = ChatColor.stripColor(getName()); + } + return skinName.toLowerCase(); + } + + @Override + public SkinPacketTracker getSkinTracker() { + return skinTracker; + } + + private void initialise(MinecraftServer minecraftServer) { + Socket socket = new EmptySocket(); + NetworkManager conn = null; + try { + conn = new EmptyNetworkManager(EnumProtocolDirection.CLIENTBOUND); + playerConnection = new EmptyNetHandler(minecraftServer, conn, this); + conn.a(playerConnection); + socket.close(); + } catch (IOException e) { + // swallow + } + + AttributeInstance range = getAttributeInstance(GenericAttributes.FOLLOW_RANGE); + if (range == null) { + range = getAttributeMap().b(GenericAttributes.FOLLOW_RANGE); + } + range.setValue(Setting.DEFAULT_PATHFINDING_RANGE.asDouble()); + + controllerJump = new PlayerControllerJump(this); + controllerLook = new PlayerControllerLook(this); + controllerMove = new PlayerControllerMove(this); + navigation = new PlayerNavigation(this, world); + NMS.setStepHeight(getBukkitEntity(), 1); // the default (0) breaks step climbing + + setSkinFlags((byte) 0xFF); + } + + public boolean isNavigating() { + return npc.getNavigator().isNavigating(); + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + public void livingEntityBaseTick() { + this.ay = this.az; + this.aE = this.aF; + if (this.hurtTicks > 0) { + this.hurtTicks -= 1; + } + bi(); + this.aU = this.aT; + this.aJ = this.aI; + this.aL = this.aK; + this.lastYaw = this.yaw; + this.lastPitch = this.pitch; + } + + private void moveOnCurrentHeading() { + if (aY) { + if (onGround && jumpTicks == 0) { + bF(); + jumpTicks = 10; + } + } else { + jumpTicks = 0; + } + aZ *= 0.98F; + ba *= 0.98F; + bb *= 0.9F; + g(aZ, ba); // movement method + NMS.setHeadYaw(getBukkitEntity(), yaw); + if (jumpTicks > 0) { + jumpTicks--; + } + } + + public void setMoveDestination(double x, double y, double z, double speed) { + controllerMove.a(x, y, z, speed); + } + + public void setShouldJump() { + controllerJump.a(); + } + + @Override + public void setSkinFlags(byte flags) { + // set skin flag byte + getDataWatcher().watch(10, Byte.valueOf(flags)); + } + + @Override + public void setSkinName(String name) { + setSkinName(name, false); + } + + @Override + public void setSkinName(String name, boolean forceUpdate) { + Preconditions.checkNotNull(name); + + npc.data().setPersistent(NPC.PLAYER_SKIN_UUID_METADATA, name.toLowerCase()); + skinTracker.notifySkinChange(forceUpdate); + } + + @Override + public void setSkinPersistent(String skinName, String signature, String data) { + Preconditions.checkNotNull(skinName); + Preconditions.checkNotNull(signature); + Preconditions.checkNotNull(data); + + npc.data().setPersistent(NPC.PLAYER_SKIN_UUID_METADATA, skinName.toLowerCase()); + npc.data().setPersistent(NPC.PLAYER_SKIN_TEXTURE_PROPERTIES_SIGN_METADATA, signature); + npc.data().setPersistent(NPC.PLAYER_SKIN_TEXTURE_PROPERTIES_METADATA, data); + npc.data().setPersistent(NPC.PLAYER_SKIN_USE_LATEST, false); + npc.data().setPersistent("cached-skin-uuid-name", skinName.toLowerCase()); + skinTracker.notifySkinChange(false); + } + + public void setTargetLook(Entity target, float yawOffset, float renderOffset) { + controllerLook.a(target, yawOffset, renderOffset); + } + + public void setTargetLook(Location target) { + controllerLook.a(target.getX(), target.getY(), target.getZ(), 10, 40); + } + + @Override + public void t_() { + super.t_(); + if (npc == null) + return; + if (updateCounter + 1 > Setting.PACKET_UPDATE_DELAY.asInt()) { + updateEffects = true; + } + this.noclip = isSpectator(); + Bukkit.getServer().getPluginManager().unsubscribeFromPermission("bukkit.broadcast.user", bukkitEntity); + 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(); + } + + public void updateAI() { + controllerMove.c(); + controllerLook.a(); + controllerJump.b(); + } + + private void updatePackets(boolean navigating) { + if (updateCounter++ <= Setting.PACKET_UPDATE_DELAY.asInt()) + return; + updateCounter = 0; + Location current = getBukkitEntity().getLocation(packetLocationCache); + Packet[] packets = new Packet[navigating ? this.inventory.armor.length : this.inventory.armor.length + 1]; + if (!navigating) { + packets[this.inventory.armor.length] = new PacketPlayOutEntityHeadRotation(this, + (byte) MathHelper.d(NMSImpl.getHeadYaw(this) * 256.0F / 360.0F)); + } + for (int i = 0; i < this.inventory.armor.length; i++) { + packets[i] = new PacketPlayOutEntityEquipment(getId(), i, getEquipment(i)); + } + NMSImpl.sendPacketsNearby(getBukkitEntity(), current, packets); + } + + public void updatePathfindingRange(float pathfindingRange) { + this.navigation.setRange(pathfindingRange); + } + + public static class PlayerNPC extends CraftPlayer implements NPCHolder, SkinnableEntity { + private final CraftServer cserver; + private final CitizensNPC npc; + + private PlayerNPC(EntityHumanNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + this.cserver = (CraftServer) Bukkit.getServer(); + npc.getTrait(Inventory.class); + } + + @Override + public Player getBukkitEntity() { + return this; + } + + @Override + public EntityHumanNPC getHandle() { + return (EntityHumanNPC) this.entity; + } + + @Override + public List getMetadata(String metadataKey) { + return cserver.getEntityMetadata().getMetadata(this, metadataKey); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public String getSkinName() { + return ((SkinnableEntity) this.entity).getSkinName(); + } + + @Override + public SkinPacketTracker getSkinTracker() { + return ((SkinnableEntity) this.entity).getSkinTracker(); + } + + @Override + public boolean hasMetadata(String metadataKey) { + return cserver.getEntityMetadata().hasMetadata(this, metadataKey); + } + + @Override + public void removeMetadata(String metadataKey, Plugin owningPlugin) { + cserver.getEntityMetadata().removeMetadata(this, metadataKey, owningPlugin); + } + + @Override + public void setMetadata(String metadataKey, MetadataValue newMetadataValue) { + cserver.getEntityMetadata().setMetadata(this, metadataKey, newMetadataValue); + } + + @Override + public void setSkinFlags(byte flags) { + ((SkinnableEntity) this.entity).setSkinFlags(flags); + } + + @Override + public void setSkinName(String name) { + ((SkinnableEntity) this.entity).setSkinName(name); + } + + @Override + public void setSkinName(String skinName, boolean forceUpdate) { + ((SkinnableEntity) this.entity).setSkinName(skinName, forceUpdate); + } + + @Override + public void setSkinPersistent(String skinName, String signature, String data) { + ((SkinnableEntity) this.entity).setSkinPersistent(skinName, signature, data); + } + } + + private static final float EPSILON = 0.005F; + + private static final Location LOADED_LOCATION = new Location(null, 0, 0, 0); +} diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/GhastController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/GhastController.java new file mode 100644 index 000000000..05939875c --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/GhastController.java @@ -0,0 +1,168 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftGhast; +import org.bukkit.entity.Ghast; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.EntityGhast; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class GhastController extends MobEntityController { + public GhastController() { + super(EntityGhastNPC.class); + } + + @Override + public Ghast getBukkitEntity() { + return (Ghast) super.getBukkitEntity(); + } + + public static class EntityGhastNPC extends EntityGhast implements NPCHolder { + private final CitizensNPC npc; + + public EntityGhastNPC(World world) { + this(world, null); + } + + public EntityGhastNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + public boolean bM() { + return npc != null; + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void E() { + if (npc != null) { + npc.update(); + } + super.E(); + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new GhastNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } + + public static class GhastNPC extends CraftGhast implements NPCHolder { + private final CitizensNPC npc; + + public GhastNPC(EntityGhastNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/GiantController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/GiantController.java new file mode 100644 index 000000000..f76de74b2 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/GiantController.java @@ -0,0 +1,205 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftGiant; +import org.bukkit.entity.Giant; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityGiantZombie; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class GiantController extends MobEntityController { + public GiantController() { + super(EntityGiantNPC.class); + } + + @Override + public Giant getBukkitEntity() { + return (Giant) super.getBukkitEntity(); + } + + public static class EntityGiantNPC extends EntityGiantZombie implements NPCHolder { + private final CitizensNPC npc; + + public EntityGiantNPC(World world) { + this(world, null); + } + + public EntityGiantNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + super.E(); + if (npc != null) { + npc.update(); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new GiantNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + public void setSize(float f, float f1) { + if (npc == null) { + super.setSize(f, f1); + } else { + NMSImpl.setSize(this, f, f1, justCreated); + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } + + public static class GiantNPC extends CraftGiant implements NPCHolder { + private final CitizensNPC npc; + + public GiantNPC(EntityGiantNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/GuardianController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/GuardianController.java new file mode 100644 index 000000000..018630027 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/GuardianController.java @@ -0,0 +1,218 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftGuardian; +import org.bukkit.entity.Guardian; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityGuardian; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class GuardianController extends MobEntityController { + public GuardianController() { + super(EntityGuardianNPC.class); + } + + @Override + public Guardian getBukkitEntity() { + return (Guardian) super.getBukkitEntity(); + } + + public static class EntityGuardianNPC extends EntityGuardian implements NPCHolder { + private final CitizensNPC npc; + + public EntityGuardianNPC(World world) { + this(world, null); + } + + public EntityGuardianNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new GuardianNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + public void m() { + if (npc == null) { + super.m(); + } else { + npc.update(); + } + } + + @Override + public void setElder(boolean flag) { + float oldw = width; + float oldl = length; + super.setElder(flag); + if (oldw != width || oldl != length) { + this.setPosition(locX - 0.01, locY, locZ - 0.01); + this.setPosition(locX + 0.01, locY, locZ + 0.01); + } + } + + @Override + public void setSize(float f, float f1) { + if (npc == null) { + super.setSize(f, f1); + } else { + NMSImpl.setSize(this, f, f1, justCreated); + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } + + public static class GuardianNPC extends CraftGuardian implements NPCHolder { + private final CitizensNPC npc; + + public GuardianNPC(EntityGuardianNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/HorseController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/HorseController.java new file mode 100644 index 000000000..3214a3ea7 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/HorseController.java @@ -0,0 +1,228 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftHorse; +import org.bukkit.entity.Horse; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.trait.HorseModifiers; +import net.citizensnpcs.util.NMS; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityHorse; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class HorseController extends MobEntityController { + public HorseController() { + super(EntityHorseNPC.class); + } + + @Override + public Horse getBukkitEntity() { + return (Horse) super.getBukkitEntity(); + } + + @Override + public void spawn(Location at, NPC npc) { + npc.getTrait(HorseModifiers.class); + super.spawn(at, npc); + } + + public static class EntityHorseNPC extends EntityHorse implements NPCHolder { + private final CitizensNPC npc; + + public EntityHorseNPC(World world) { + this(world, null); + } + + public EntityHorseNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + ((Horse) getBukkitEntity()).setDomestication(((Horse) getBukkitEntity()).getMaxDomestication()); + } + } + + @Override + public void a(boolean flag) { + float oldw = width; + float oldl = length; + super.a(flag); + if (oldw != width || oldl != length) { + this.setPosition(locX - 0.01, locY, locZ - 0.01); + this.setPosition(locX + 0.01, locY, locZ + 0.01); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean cp() { + if (npc == null) + return super.cp(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + return super.cp() && !protectedDefault; + } + + @Override + public boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + if (npc == null) { + super.E(); + } else { + NMS.setStepHeight(getBukkitEntity(), 1); + npc.update(); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new HorseNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } + + public static class HorseNPC extends CraftHorse implements NPCHolder { + private final CitizensNPC npc; + + public HorseNPC(EntityHorseNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/HumanController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/HumanController.java new file mode 100644 index 000000000..71128f317 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/HumanController.java @@ -0,0 +1,142 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import java.util.UUID; +import java.util.regex.Pattern; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.Scoreboard; +import org.bukkit.scoreboard.Team; + +import com.mojang.authlib.GameProfile; + +import net.citizensnpcs.Settings.Setting; +import net.citizensnpcs.api.CitizensAPI; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.api.util.Colorizer; +import net.citizensnpcs.npc.AbstractEntityController; +import net.citizensnpcs.npc.skin.Skin; +import net.citizensnpcs.npc.skin.SkinnableEntity; +import net.citizensnpcs.util.NMS; +import net.minecraft.server.v1_8_R3.PlayerInteractManager; +import net.minecraft.server.v1_8_R3.WorldServer; + +public class HumanController extends AbstractEntityController { + public HumanController() { + super(); + } + + @Override + protected Entity createEntity(final Location at, final NPC npc) { + final WorldServer nmsWorld = ((CraftWorld) at.getWorld()).getHandle(); + String coloredName = Colorizer.parseColors(npc.getFullName()); + + String name = coloredName, prefix = null, suffix = null; + if (coloredName.length() > 16) { + prefix = coloredName.substring(0, 16); + if (coloredName.length() > 30) { + int len = 30; + name = coloredName.substring(16, 30); + if (NON_ALPHABET_MATCHER.matcher(name).matches()) { + if (coloredName.length() >= 32) { + len = 32; + name = coloredName.substring(16, 32); + } else if (coloredName.length() == 31) { + len = 31; + name = coloredName.substring(16, 31); + } + } else { + name = ChatColor.RESET + name; + } + suffix = coloredName.substring(len); + } else { + name = coloredName.substring(16); + if (!NON_ALPHABET_MATCHER.matcher(name).matches()) { + name = ChatColor.RESET + name; + } + if (name.length() > 16) { + suffix = name.substring(16); + name = name.substring(0, 16); + } + } + coloredName = coloredName.substring(0, 16); + } + + final String prefixCapture = prefix, suffixCapture = suffix; + + UUID uuid = npc.getUniqueId(); + if (uuid.version() == 4) { // clear version + long msb = uuid.getMostSignificantBits(); + msb &= ~0x0000000000004000L; + msb |= 0x0000000000002000L; + uuid = new UUID(msb, uuid.getLeastSignificantBits()); + } + + final GameProfile profile = new GameProfile(uuid, name); + + final EntityHumanNPC handle = new EntityHumanNPC(nmsWorld.getServer().getServer(), nmsWorld, profile, + new PlayerInteractManager(nmsWorld), npc); + + Skin skin = handle.getSkinTracker().getSkin(); + if (skin != null) { + skin.apply(handle); + } + + Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() { + @Override + public void run() { + if (getBukkitEntity() == null || !getBukkitEntity().isValid()) + return; + boolean removeFromPlayerList = npc.data().get("removefromplayerlist", + Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()); + NMS.addOrRemoveFromPlayerList(getBukkitEntity(), + npc.data().get("removefromplayerlist", removeFromPlayerList)); + + if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { + Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard(); + String teamName = profile.getId().toString().substring(0, 16); + + Team team = scoreboard.getTeam(teamName); + if (team == null) { + team = scoreboard.registerNewTeam(teamName); + if (prefixCapture != null) { + team.setPrefix(prefixCapture); + } + if (suffixCapture != null) { + team.setSuffix(suffixCapture); + } + } + team.addPlayer(handle.getBukkitEntity()); + + handle.getNPC().data().set(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, teamName); + } + } + }, 20); + + handle.getBukkitEntity().setSleepingIgnored(true); + + return handle.getBukkitEntity(); + } + + @Override + public Player getBukkitEntity() { + return (Player) super.getBukkitEntity(); + } + + @Override + public void remove() { + Player entity = getBukkitEntity(); + if (entity != null) { + NMS.removeFromWorld(entity); + SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null; + npc.getSkinTracker().onRemoveNPC(); + } + super.remove(); + } + + private static Pattern NON_ALPHABET_MATCHER = Pattern.compile(".*[^A-Za-z0-9_].*"); +} diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/IronGolemController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/IronGolemController.java new file mode 100644 index 000000000..a70b1a8ab --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/IronGolemController.java @@ -0,0 +1,205 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftIronGolem; +import org.bukkit.entity.IronGolem; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityIronGolem; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class IronGolemController extends MobEntityController { + public IronGolemController() { + super(EntityIronGolemNPC.class); + } + + @Override + public IronGolem getBukkitEntity() { + return (IronGolem) super.getBukkitEntity(); + } + + public static class EntityIronGolemNPC extends EntityIronGolem implements NPCHolder { + private final CitizensNPC npc; + + public EntityIronGolemNPC(World world) { + this(world, null); + } + + public EntityIronGolemNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + super.E(); + if (npc != null) { + npc.update(); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new IronGolemNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + public void setSize(float f, float f1) { + if (npc == null) { + super.setSize(f, f1); + } else { + NMSImpl.setSize(this, f, f1, justCreated); + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } + + public static class IronGolemNPC extends CraftIronGolem implements NPCHolder { + private final CitizensNPC npc; + + public IronGolemNPC(EntityIronGolemNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/MagmaCubeController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/MagmaCubeController.java new file mode 100644 index 000000000..60d5d28c3 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/MagmaCubeController.java @@ -0,0 +1,216 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftMagmaCube; +import org.bukkit.entity.MagmaCube; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.nms.v1_8_R3.util.PlayerControllerMove; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityHuman; +import net.minecraft.server.v1_8_R3.EntityMagmaCube; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class MagmaCubeController extends MobEntityController { + public MagmaCubeController() { + super(EntityMagmaCubeNPC.class); + } + + @Override + public MagmaCube getBukkitEntity() { + return (MagmaCube) super.getBukkitEntity(); + } + + public static class EntityMagmaCubeNPC extends EntityMagmaCube implements NPCHolder { + private final CitizensNPC npc; + + public EntityMagmaCubeNPC(World world) { + this(world, null); + } + + public EntityMagmaCubeNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + setSize(3); + NMSImpl.clearGoals(goalSelector, targetSelector); + this.moveController = new PlayerControllerMove(this); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 d(EntityHuman human) { + if (npc == null) { + super.d(human); + } + } + + @Override + public boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new MagmaCubeNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + public void m() { + super.m(); + if (npc != null) { + npc.update(); + } + } + + @Override + public void setSize(float f, float f1) { + if (npc == null) { + super.setSize(f, f1); + } else { + NMSImpl.setSize(this, f, f1, justCreated); + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } + + public static class MagmaCubeNPC extends CraftMagmaCube implements NPCHolder { + private final CitizensNPC npc; + + public MagmaCubeNPC(EntityMagmaCubeNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/MobEntityController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/MobEntityController.java new file mode 100644 index 000000000..2206b2b38 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/MobEntityController.java @@ -0,0 +1,61 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import java.lang.reflect.Constructor; +import java.util.Map; + +import org.bukkit.Location; +import org.bukkit.block.BlockFace; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.entity.Entity; + +import com.google.common.collect.Maps; + +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.npc.AbstractEntityController; +import net.minecraft.server.v1_8_R3.World; + +public abstract class MobEntityController extends AbstractEntityController { + private final Constructor constructor; + + protected MobEntityController(Class clazz) { + super(clazz); + this.constructor = getConstructor(clazz); + } + + @Override + protected Entity createEntity(Location at, NPC npc) { + net.minecraft.server.v1_8_R3.Entity entity = createEntityFromClass(((CraftWorld) at.getWorld()).getHandle(), + npc); + entity.setPositionRotation(at.getX(), at.getY(), at.getZ(), at.getYaw(), at.getPitch()); + + // entity.onGround isn't updated right away - we approximate here so + // that things like pathfinding still work *immediately* after spawn. + org.bukkit.Material beneath = at.getBlock().getRelative(BlockFace.DOWN).getType(); + if (beneath.isBlock()) { + entity.onGround = true; + } + return entity.getBukkitEntity(); + } + + private net.minecraft.server.v1_8_R3.Entity createEntityFromClass(Object... args) { + try { + return (net.minecraft.server.v1_8_R3.Entity) constructor.newInstance(args); + } catch (Exception ex) { + ex.printStackTrace(); + return null; + } + } + + private static Constructor getConstructor(Class clazz) { + Constructor constructor = CONSTRUCTOR_CACHE.get(clazz); + if (constructor != null) + return constructor; + try { + return clazz.getConstructor(World.class, NPC.class); + } catch (Exception ex) { + throw new IllegalStateException("unable to find an entity constructor"); + } + } + + private static final Map, Constructor> CONSTRUCTOR_CACHE = Maps.newHashMap(); +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/MushroomCowController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/MushroomCowController.java new file mode 100644 index 000000000..42a3a5f0c --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/MushroomCowController.java @@ -0,0 +1,207 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftMushroomCow; +import org.bukkit.entity.MushroomCow; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityMushroomCow; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class MushroomCowController extends MobEntityController { + + public MushroomCowController() { + super(EntityMushroomCowNPC.class); + } + + @Override + public MushroomCow getBukkitEntity() { + return (MushroomCow) super.getBukkitEntity(); + } + + public static class EntityMushroomCowNPC extends EntityMushroomCow implements NPCHolder { + private final CitizensNPC npc; + + public EntityMushroomCowNPC(World world) { + this(world, null); + } + + public EntityMushroomCowNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + public void a(boolean flag) { + float oldw = width; + float oldl = length; + super.a(flag); + if (oldw != width || oldl != length) { + this.setPosition(locX - 0.01, locY, locZ - 0.01); + this.setPosition(locX + 0.01, locY, locZ + 0.01); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + super.E(); + if (npc != null) + npc.update(); + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new MushroomCowNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } + + public static class MushroomCowNPC extends CraftMushroomCow implements NPCHolder { + private final CitizensNPC npc; + + public MushroomCowNPC(EntityMushroomCowNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/OcelotController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/OcelotController.java new file mode 100644 index 000000000..c9ed00421 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/OcelotController.java @@ -0,0 +1,214 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftOcelot; +import org.bukkit.entity.Ocelot; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityOcelot; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class OcelotController extends MobEntityController { + public OcelotController() { + super(EntityOcelotNPC.class); + } + + @Override + public Ocelot getBukkitEntity() { + return (Ocelot) super.getBukkitEntity(); + } + + public static class EntityOcelotNPC extends EntityOcelot implements NPCHolder { + private final CitizensNPC npc; + + public EntityOcelotNPC(World world) { + this(world, null); + } + + public EntityOcelotNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + public void a(boolean flag) { + float oldw = width; + float oldl = length; + super.a(flag); + if (oldw != width || oldl != length) { + this.setPosition(locX - 0.01, locY, locZ - 0.01); + this.setPosition(locX + 0.01, locY, locZ + 0.01); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + protected void cm() { + if (npc == null) { + super.cm(); + } + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + super.E(); + if (npc != null) + npc.update(); + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new OcelotNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + + } + + public static class OcelotNPC extends CraftOcelot implements NPCHolder { + private final CitizensNPC npc; + + public OcelotNPC(EntityOcelotNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/PigController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/PigController.java new file mode 100644 index 000000000..87c998e46 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/PigController.java @@ -0,0 +1,224 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPig; +import org.bukkit.entity.Pig; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityLightning; +import net.minecraft.server.v1_8_R3.EntityPig; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class PigController extends MobEntityController { + public PigController() { + super(EntityPigNPC.class); + } + + @Override + public Pig getBukkitEntity() { + return (Pig) super.getBukkitEntity(); + } + + public static class EntityPigNPC extends EntityPig implements NPCHolder { + private final CitizensNPC npc; + + public EntityPigNPC(World world) { + this(world, null); + } + + public EntityPigNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + public void a(boolean flag) { + float oldw = width; + float oldl = length; + super.a(flag); + if (oldw != width || oldl != length) { + this.setPosition(locX - 0.01, locY, locZ - 0.01); + this.setPosition(locX + 0.01, locY, locZ + 0.01); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean bW() { + if (npc == null) { + return super.bW(); + } + return false; + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + super.E(); + if (npc != null) { + npc.update(); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new PigNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + public void onLightningStrike(EntityLightning entitylightning) { + if (npc == null) { + super.onLightningStrike(entitylightning); + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } + + public static class PigNPC extends CraftPig implements NPCHolder { + private final CitizensNPC npc; + + public PigNPC(EntityPigNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/PigZombieController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/PigZombieController.java new file mode 100644 index 000000000..66fe189de --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/PigZombieController.java @@ -0,0 +1,197 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPigZombie; +import org.bukkit.entity.PigZombie; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityPigZombie; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class PigZombieController extends MobEntityController { + + public PigZombieController() { + super(EntityPigZombieNPC.class); + } + + @Override + public PigZombie getBukkitEntity() { + return (PigZombie) super.getBukkitEntity(); + } + + public static class EntityPigZombieNPC extends EntityPigZombie implements NPCHolder { + private final CitizensNPC npc; + + public EntityPigZombieNPC(World world) { + this(world, null); + } + + public EntityPigZombieNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + super.E(); + if (npc != null) + npc.update(); + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) { + super.g(x, y, z); + } + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new PigZombieNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } + + public static class PigZombieNPC extends CraftPigZombie implements NPCHolder { + private final CitizensNPC npc; + + public PigZombieNPC(EntityPigZombieNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/RabbitController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/RabbitController.java new file mode 100644 index 000000000..b53fb9f9e --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/RabbitController.java @@ -0,0 +1,226 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftRabbit; +import org.bukkit.entity.Rabbit; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityLiving; +import net.minecraft.server.v1_8_R3.EntityRabbit; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class RabbitController extends MobEntityController { + public RabbitController() { + super(EntityRabbitNPC.class); + } + + @Override + public Rabbit getBukkitEntity() { + return (Rabbit) super.getBukkitEntity(); + } + + public static class EntityRabbitNPC extends EntityRabbit implements NPCHolder { + private final CitizensNPC npc; + + public EntityRabbitNPC(World world) { + this(world, null); + } + + public EntityRabbitNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + public void a(boolean flag) { + float oldw = width; + float oldl = length; + super.a(flag); + if (oldw != width || oldl != length) { + this.setPosition(locX - 0.01, locY, locZ - 0.01); + this.setPosition(locX + 0.01, locY, locZ + 0.01); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + if (npc != null) { + super.E(); + this.aY = npc.getNavigator().isNavigating(); + npc.update(); + } else { + super.E(); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new RabbitNPC(this); + return super.getBukkitEntity(); + } + + @Override + public EntityLiving getGoalTarget() { + return npc != null ? null : super.getGoalTarget(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + public void setRabbitType(int i) { + if (npc != null) { + this.datawatcher.watch(18, Byte.valueOf((byte) i)); + return; + } + super.setRabbitType(i); + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } + + public static class RabbitNPC extends CraftRabbit implements NPCHolder { + private final CitizensNPC npc; + + public RabbitNPC(EntityRabbitNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SheepController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SheepController.java new file mode 100644 index 000000000..d0d2a0ff1 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SheepController.java @@ -0,0 +1,206 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftSheep; +import org.bukkit.entity.Sheep; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntitySheep; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class SheepController extends MobEntityController { + public SheepController() { + super(EntitySheepNPC.class); + } + + @Override + public Sheep getBukkitEntity() { + return (Sheep) super.getBukkitEntity(); + } + + public static class EntitySheepNPC extends EntitySheep implements NPCHolder { + private final CitizensNPC npc; + + public EntitySheepNPC(World world) { + this(world, null); + } + + public EntitySheepNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + public void a(boolean flag) { + float oldw = width; + float oldl = length; + super.a(flag); + if (oldw != width || oldl != length) { + this.setPosition(locX - 0.01, locY, locZ - 0.01); + this.setPosition(locX + 0.01, locY, locZ + 0.01); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + super.E(); + if (npc != null) + npc.update(); + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new SheepNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } + + public static class SheepNPC extends CraftSheep implements NPCHolder { + private final CitizensNPC npc; + + public SheepNPC(EntitySheepNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SilverfishController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SilverfishController.java new file mode 100644 index 000000000..45f5eda48 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SilverfishController.java @@ -0,0 +1,204 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftSilverfish; +import org.bukkit.entity.Silverfish; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntitySilverfish; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class SilverfishController extends MobEntityController { + public SilverfishController() { + super(EntitySilverfishNPC.class); + } + + @Override + public Silverfish getBukkitEntity() { + return (Silverfish) super.getBukkitEntity(); + } + + public static class EntitySilverfishNPC extends EntitySilverfish implements NPCHolder { + private final CitizensNPC npc; + + public EntitySilverfishNPC(World world) { + this(world, null); + } + + public EntitySilverfishNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + super.E(); + if (npc != null) + npc.update(); + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new SilverfishNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + public void setSize(float f, float f1) { + if (npc == null) { + super.setSize(f, f1); + } else { + NMSImpl.setSize(this, f, f1, justCreated); + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } + + public static class SilverfishNPC extends CraftSilverfish implements NPCHolder { + private final CitizensNPC npc; + + public SilverfishNPC(EntitySilverfishNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SkeletonController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SkeletonController.java new file mode 100644 index 000000000..ea35e385b --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SkeletonController.java @@ -0,0 +1,205 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftSkeleton; +import org.bukkit.entity.Skeleton; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntitySkeleton; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class SkeletonController extends MobEntityController { + public SkeletonController() { + super(EntitySkeletonNPC.class); + } + + @Override + public Skeleton getBukkitEntity() { + return (Skeleton) super.getBukkitEntity(); + } + + public static class EntitySkeletonNPC extends EntitySkeleton implements NPCHolder { + private final CitizensNPC npc; + + public EntitySkeletonNPC(World world) { + this(world, null); + } + + public EntitySkeletonNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + super.E(); + if (npc != null) { + npc.update(); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new SkeletonNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + public void setSize(float f, float f1) { + if (npc == null) { + super.setSize(f, f1); + } else { + NMSImpl.setSize(this, f, f1, justCreated); + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } + + public static class SkeletonNPC extends CraftSkeleton implements NPCHolder { + private final CitizensNPC npc; + + public SkeletonNPC(EntitySkeletonNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SlimeController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SlimeController.java new file mode 100644 index 000000000..98de31431 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SlimeController.java @@ -0,0 +1,217 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftSlime; +import org.bukkit.entity.Slime; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.nms.v1_8_R3.util.PlayerControllerMove; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityHuman; +import net.minecraft.server.v1_8_R3.EntitySlime; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class SlimeController extends MobEntityController { + public SlimeController() { + super(EntitySlimeNPC.class); + } + + @Override + public Slime getBukkitEntity() { + return (Slime) super.getBukkitEntity(); + } + + public static class EntitySlimeNPC extends EntitySlime implements NPCHolder { + private final CitizensNPC npc; + + public EntitySlimeNPC(World world) { + this(world, null); + } + + public EntitySlimeNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + setSize(3); + NMSImpl.clearGoals(goalSelector, targetSelector); + this.moveController = new PlayerControllerMove(this); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 d(EntityHuman human) { + if (npc == null) { + super.d(human); + } + } + + @Override + public boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new SlimeNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + public void m() { + super.m(); + if (npc != null) { + npc.update(); + } + } + + @Override + public void setSize(float f, float f1) { + if (npc == null) { + super.setSize(f, f1); + } else { + NMSImpl.setSize(this, f, f1, justCreated); + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } + + public static class SlimeNPC extends CraftSlime implements NPCHolder { + private final CitizensNPC npc; + + public SlimeNPC(EntitySlimeNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SnowmanController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SnowmanController.java new file mode 100644 index 000000000..866b2a065 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SnowmanController.java @@ -0,0 +1,217 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftSnowman; +import org.bukkit.entity.Snowman; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntitySnowman; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class SnowmanController extends MobEntityController { + public SnowmanController() { + super(EntitySnowmanNPC.class); + } + + @Override + public Snowman getBukkitEntity() { + return (Snowman) super.getBukkitEntity(); + } + + public static class EntitySnowmanNPC extends EntitySnowman implements NPCHolder { + private final CitizensNPC npc; + + public EntitySnowmanNPC(World world) { + this(world, null); + } + + public EntitySnowmanNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + super.E(); + if (npc != null) { + npc.update(); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new SnowmanNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + public void m() { + boolean allowsGriefing = this.world.getGameRules().getBoolean("mobGriefing"); + if (npc != null) { + this.world.getGameRules().set("mobGriefing", "false"); + } + super.m(); + if (npc != null) { + this.world.getGameRules().set("mobGriefing", Boolean.toString(allowsGriefing)); + } + } + + @Override + public void setSize(float f, float f1) { + if (npc == null) { + super.setSize(f, f1); + } else { + NMSImpl.setSize(this, f, f1, justCreated); + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } + + public static class SnowmanNPC extends CraftSnowman implements NPCHolder { + private final CitizensNPC npc; + + public SnowmanNPC(EntitySnowmanNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SpiderController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SpiderController.java new file mode 100644 index 000000000..436528116 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SpiderController.java @@ -0,0 +1,205 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftSpider; +import org.bukkit.entity.Spider; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntitySpider; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class SpiderController extends MobEntityController { + public SpiderController() { + super(EntitySpiderNPC.class); + } + + @Override + public Spider getBukkitEntity() { + return (Spider) super.getBukkitEntity(); + } + + public static class EntitySpiderNPC extends EntitySpider implements NPCHolder { + private final CitizensNPC npc; + + public EntitySpiderNPC(World world) { + this(world, null); + } + + public EntitySpiderNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + super.E(); + if (npc != null) + npc.update(); + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new SpiderNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + public void setSize(float f, float f1) { + if (npc == null) { + super.setSize(f, f1); + } else { + NMSImpl.setSize(this, f, f1, justCreated); + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + + } + + public static class SpiderNPC extends CraftSpider implements NPCHolder { + private final CitizensNPC npc; + + public SpiderNPC(EntitySpiderNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SquidController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SquidController.java new file mode 100644 index 000000000..6cdcb9dcd --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/SquidController.java @@ -0,0 +1,197 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftSquid; +import org.bukkit.entity.Squid; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntitySquid; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class SquidController extends MobEntityController { + public SquidController() { + super(EntitySquidNPC.class); + } + + @Override + public Squid getBukkitEntity() { + return (Squid) super.getBukkitEntity(); + } + + public static class EntitySquidNPC extends EntitySquid implements NPCHolder { + private final CitizensNPC npc; + + public EntitySquidNPC(World world) { + this(world, null); + } + + public EntitySquidNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new SquidNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + public void setSize(float f, float f1) { + if (npc == null) { + super.setSize(f, f1); + } else { + NMSImpl.setSize(this, f, f1, justCreated); + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } + + public static class SquidNPC extends CraftSquid implements NPCHolder { + private final CitizensNPC npc; + + public SquidNPC(EntitySquidNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/VillagerController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/VillagerController.java new file mode 100644 index 000000000..3a5d15844 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/VillagerController.java @@ -0,0 +1,236 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftVillager; +import org.bukkit.entity.Villager; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityHuman; +import net.minecraft.server.v1_8_R3.EntityVillager; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class VillagerController extends MobEntityController { + public VillagerController() { + super(EntityVillagerNPC.class); + } + + @Override + public Villager getBukkitEntity() { + return (Villager) super.getBukkitEntity(); + } + + public static class EntityVillagerNPC extends EntityVillager implements NPCHolder { + private boolean blockingATrade; + private boolean blockTrades = true; + private final CitizensNPC npc; + + public EntityVillagerNPC(World world) { + this(world, null); + } + + public EntityVillagerNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + public void a(boolean flag) { + float oldw = width; + float oldl = length; + super.a(flag); + if (oldw != width || oldl != length) { + this.setPosition(locX - 0.01, locY, locZ - 0.01); + this.setPosition(locX + 0.01, locY, locZ + 0.01); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + public boolean a(EntityHuman entityhuman) { + if (npc != null && blockTrades) { + blockingATrade = true; + } + return super.a(entityhuman); + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public boolean co() { + if (blockingATrade) { + blockingATrade = false; + return true; + } + return super.co(); + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + super.E(); + if (npc != null) { + npc.update(); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new VillagerNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + public boolean isBlockingTrades() { + return blockTrades; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + public void setBlockTrades(boolean blocked) { + this.blockTrades = blocked; + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } + + public static class VillagerNPC extends CraftVillager implements NPCHolder { + private final CitizensNPC npc; + + public VillagerNPC(EntityVillagerNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/WitchController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/WitchController.java new file mode 100644 index 000000000..70f8a8fdd --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/WitchController.java @@ -0,0 +1,204 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftWitch; +import org.bukkit.entity.Witch; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityWitch; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class WitchController extends MobEntityController { + public WitchController() { + super(EntityWitchNPC.class); + } + + @Override + public Witch getBukkitEntity() { + return (Witch) super.getBukkitEntity(); + } + + public static class EntityWitchNPC extends EntityWitch implements NPCHolder { + private final CitizensNPC npc; + + public EntityWitchNPC(World world) { + this(world, null); + } + + public EntityWitchNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + super.E(); + if (npc != null) + npc.update(); + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new WitchNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + public void setSize(float f, float f1) { + if (npc == null) { + super.setSize(f, f1); + } else { + NMSImpl.setSize(this, f, f1, justCreated); + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } + + public static class WitchNPC extends CraftWitch implements NPCHolder { + private final CitizensNPC npc; + + public WitchNPC(EntityWitchNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/WitherController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/WitherController.java new file mode 100644 index 000000000..12b954fe2 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/WitherController.java @@ -0,0 +1,168 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftWither; +import org.bukkit.entity.Wither; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.EntityWither; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class WitherController extends MobEntityController { + public WitherController() { + super(EntityWitherNPC.class); + } + + @Override + public Wither getBukkitEntity() { + return (Wither) super.getBukkitEntity(); + } + + public static class EntityWitherNPC extends EntityWither implements NPCHolder { + private final CitizensNPC npc; + + public EntityWitherNPC(World world) { + this(world, null); + } + + public EntityWitherNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + protected void E() { + if (npc == null) { + super.E(); + return; + } + npc.update(); + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new WitherNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public int s(int i) { + return npc == null ? super.s(i) : 0; + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } + + public static class WitherNPC extends CraftWither implements NPCHolder { + private final CitizensNPC npc; + + public WitherNPC(EntityWitherNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/WolfController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/WolfController.java new file mode 100644 index 000000000..9b2e998cf --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/WolfController.java @@ -0,0 +1,223 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftWolf; +import org.bukkit.entity.Wolf; +import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityLiving; +import net.minecraft.server.v1_8_R3.EntityWolf; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class WolfController extends MobEntityController { + public WolfController() { + super(EntityWolfNPC.class); + } + + @Override + public Wolf getBukkitEntity() { + return (Wolf) super.getBukkitEntity(); + } + + public static class EntityWolfNPC extends EntityWolf implements NPCHolder { + private final CitizensNPC npc; + + public EntityWolfNPC(World world) { + this(world, null); + } + + public EntityWolfNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + public void a(boolean flag) { + float oldw = width; + float oldl = length; + super.a(flag); + if (oldw != width || oldl != length) { + this.setPosition(locX - 0.01, locY, locZ - 0.01); + this.setPosition(locX + 0.01, locY, locZ + 0.01); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + super.E(); + if (npc != null) { + npc.update(); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new WolfNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + public void setGoalTarget(EntityLiving entityliving, EntityTargetEvent.TargetReason reason, boolean fire) { + if (npc == null || this.equals(entityliving)) { + super.setGoalTarget(entityliving, reason, fire); + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } + + public static class WolfNPC extends CraftWolf implements NPCHolder { + private final CitizensNPC npc; + + public WolfNPC(EntityWolfNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public void setSitting(boolean sitting) { + getHandle().setSitting(sitting); + } + + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/ZombieController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/ZombieController.java new file mode 100644 index 000000000..c33b12d62 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/ZombieController.java @@ -0,0 +1,196 @@ +package net.citizensnpcs.nms.v1_8_R3.entity; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftZombie; +import org.bukkit.entity.Zombie; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCEnderTeleportEvent; +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityZombie; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class ZombieController extends MobEntityController { + public ZombieController() { + super(EntityZombieNPC.class); + } + + @Override + public Zombie getBukkitEntity() { + return (Zombie) super.getBukkitEntity(); + } + + public static class EntityZombieNPC extends EntityZombie implements NPCHolder { + private final CitizensNPC npc; + + public EntityZombieNPC(World world) { + this(world, null); + } + + public EntityZombieNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + if (npc != null) { + NMSImpl.clearGoals(goalSelector, targetSelector); + } + } + + @Override + protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) { + if (npc == null || !npc.isFlyable()) { + super.a(d0, flag, block, blockposition); + } + } + + @Override + protected String bo() { + return NMSImpl.getSoundEffect(npc, super.bo(), NPC.HURT_SOUND_METADATA); + } + + @Override + protected String bp() { + return NMSImpl.getSoundEffect(npc, super.bp(), NPC.DEATH_SOUND_METADATA); + } + + @Override + public boolean cc() { + if (npc == null) + return super.cc(); + boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true); + if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault)) + return super.cc(); + if (super.cc()) { + unleash(true, false); // clearLeash with client update + } + return false; // shouldLeash + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + protected void D() { + if (npc == null) { + super.D(); + } + } + + @Override + public void e(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.e(f, f1); + } + } + + @Override + public void E() { + super.E(); + if (npc != null) { + npc.update(); + } + } + + @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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 g(float f, float f1) { + if (npc == null || !npc.isFlyable()) { + super.g(f, f1); + } else { + NMSImpl.flyingMoveLogic(this, f, f1); + } + } + + @Override + public CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) + bukkitEntity = new ZombieNPC(this); + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean k_() { + if (npc == null || !npc.isFlyable()) { + return super.k_(); + } else { + return false; + } + } + + @Override + protected String z() { + return NMSImpl.getSoundEffect(npc, super.z(), NPC.AMBIENT_SOUND_METADATA); + } + } + + public static class ZombieNPC extends CraftZombie implements NPCHolder { + private final CitizensNPC npc; + + public ZombieNPC(EntityZombieNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/ArmorStandController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/ArmorStandController.java new file mode 100644 index 000000000..d8d01238b --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/ArmorStandController.java @@ -0,0 +1,139 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftArmorStand; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.EntityArmorStand; +import net.minecraft.server.v1_8_R3.EntityHuman; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.Vec3D; +import net.minecraft.server.v1_8_R3.World; + +public class ArmorStandController extends MobEntityController { + public ArmorStandController() { + super(EntityArmorStandNPC.class); + } + + @Override + public ArmorStand getBukkitEntity() { + return (ArmorStand) super.getBukkitEntity(); + } + + public static class ArmorStandNPC extends CraftArmorStand implements NPCHolder { + private final CitizensNPC npc; + + public ArmorStandNPC(EntityArmorStandNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class EntityArmorStandNPC extends EntityArmorStand implements NPCHolder { + private final CitizensNPC npc; + + public EntityArmorStandNPC(World world) { + this(world, null); + } + + public EntityArmorStandNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public boolean a(EntityHuman entityhuman, Vec3D vec3d) { + if (npc == null) { + return super.a(entityhuman, vec3d); + } + PlayerInteractEntityEvent event = new PlayerInteractEntityEvent((Player) entityhuman.getBukkitEntity(), + getBukkitEntity()); + Bukkit.getPluginManager().callEvent(event); + return !event.isCancelled(); + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + public void g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new ArmorStandNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public void t_() { + super.t_(); + if (npc != null) { + npc.update(); + } + } + + @Override + public void setSize(float f, float f1) { + if (npc == null) { + super.setSize(f, f1); + } else { + NMSImpl.setSize(this, f, f1, justCreated); + } + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/BoatController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/BoatController.java new file mode 100644 index 000000000..d4a3a312b --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/BoatController.java @@ -0,0 +1,125 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftBoat; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.entity.Boat; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.EntityBoat; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class BoatController extends MobEntityController { + public BoatController() { + super(EntityBoatNPC.class); + } + + @Override + public Boat getBukkitEntity() { + return (Boat) super.getBukkitEntity(); + } + + public static class BoatNPC extends CraftBoat implements NPCHolder { + private final CitizensNPC npc; + + public BoatNPC(EntityBoatNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class EntityBoatNPC extends EntityBoat implements NPCHolder { + private final CitizensNPC npc; + + public EntityBoatNPC(World world) { + this(world, null); + } + + public EntityBoatNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + public void g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new BoatNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + 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 t_() { + if (npc != null) { + npc.update(); + } else { + super.t_(); + } + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/EggController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/EggController.java new file mode 100644 index 000000000..7c803ed7f --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/EggController.java @@ -0,0 +1,134 @@ +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.EntityEgg; +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.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEgg; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.entity.Egg; +import org.bukkit.entity.Entity; +import org.bukkit.util.Vector; + +public class EggController extends AbstractEntityController { + public EggController() { + super(EntityEggNPC.class); + } + + @Override + protected Entity createEntity(Location at, NPC npc) { + WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); + final EntityEggNPC handle = new EntityEggNPC(ws, npc, at.getX(), at.getY(), at.getZ()); + return handle.getBukkitEntity(); + } + + @Override + public Egg getBukkitEntity() { + return (Egg) super.getBukkitEntity(); + } + + public static class EggNPC extends CraftEgg implements NPCHolder { + private final CitizensNPC npc; + + public EggNPC(EntityEggNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class EntityEggNPC extends EntityEgg implements NPCHolder { + private final CitizensNPC npc; + + public EntityEggNPC(World world) { + this(world, null); + } + + public EntityEggNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + public EntityEggNPC(World world, NPC npc, double d0, double d1, double d2) { + super(world, d0, d1, d2); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new EggNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public void t_() { + if (npc != null) { + npc.update(); + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) { + super.t_(); + } + } else { + super.t_(); + } + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/EnderCrystalController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/EnderCrystalController.java new file mode 100644 index 000000000..59fb147cd --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/EnderCrystalController.java @@ -0,0 +1,115 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.EntityEnderCrystal; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEnderCrystal; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.entity.EnderCrystal; +import org.bukkit.util.Vector; + +public class EnderCrystalController extends MobEntityController { + public EnderCrystalController() { + super(EntityEnderCrystalNPC.class); + } + + @Override + public EnderCrystal getBukkitEntity() { + return (EnderCrystal) super.getBukkitEntity(); + } + + public static class EnderCrystalNPC extends CraftEnderCrystal implements NPCHolder { + private final CitizensNPC npc; + + public EnderCrystalNPC(EntityEnderCrystalNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class EntityEnderCrystalNPC extends EntityEnderCrystal implements NPCHolder { + private final CitizensNPC npc; + + public EntityEnderCrystalNPC(World world) { + this(world, null); + } + + @Override + public boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + public EntityEnderCrystalNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new EnderCrystalNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public void t_() { + if (npc != null) { + npc.update(); + } else { + super.t_(); + } + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/EnderPearlController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/EnderPearlController.java new file mode 100644 index 000000000..e6af5489d --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/EnderPearlController.java @@ -0,0 +1,118 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEnderPearl; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.entity.EnderPearl; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.EntityEnderPearl; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class EnderPearlController extends MobEntityController { + public EnderPearlController() { + super(EntityEnderPearlNPC.class); + } + + @Override + public EnderPearl getBukkitEntity() { + return (EnderPearl) super.getBukkitEntity(); + } + + public static class EnderPearlNPC extends CraftEnderPearl implements NPCHolder { + private final CitizensNPC npc; + + public EnderPearlNPC(EntityEnderPearlNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class EntityEnderPearlNPC extends EntityEnderPearl implements NPCHolder { + private final CitizensNPC npc; + + public EntityEnderPearlNPC(World world) { + this(world, null); + } + + public EntityEnderPearlNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + public void g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new EnderPearlNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public void t_() { + if (npc != null) { + npc.update(); + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) { + super.t_(); + } + } else { + super.t_(); + } + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/EnderSignalController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/EnderSignalController.java new file mode 100644 index 000000000..b691b13a3 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/EnderSignalController.java @@ -0,0 +1,115 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.EntityEnderSignal; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEnderSignal; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.entity.EnderSignal; +import org.bukkit.util.Vector; + +public class EnderSignalController extends MobEntityController { + public EnderSignalController() { + super(EntityEnderSignalNPC.class); + } + + @Override + public EnderSignal getBukkitEntity() { + return (EnderSignal) super.getBukkitEntity(); + } + + public static class EnderSignalNPC extends CraftEnderSignal implements NPCHolder { + private final CitizensNPC npc; + + public EnderSignalNPC(EntityEnderSignalNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class EntityEnderSignalNPC extends EntityEnderSignal implements NPCHolder { + private final CitizensNPC npc; + + public EntityEnderSignalNPC(World world) { + this(world, null); + } + + @Override + public boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + public EntityEnderSignalNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new EnderSignalNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public void t_() { + if (npc != null) { + npc.update(); + } else { + super.t_(); + } + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/ExperienceOrbController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/ExperienceOrbController.java new file mode 100644 index 000000000..e1bdf4aa4 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/ExperienceOrbController.java @@ -0,0 +1,115 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.EntityExperienceOrb; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftExperienceOrb; +import org.bukkit.entity.ExperienceOrb; +import org.bukkit.util.Vector; + +public class ExperienceOrbController extends MobEntityController { + public ExperienceOrbController() { + super(EntityExperienceOrbNPC.class); + } + + @Override + public ExperienceOrb getBukkitEntity() { + return (ExperienceOrb) super.getBukkitEntity(); + } + + public static class EntityExperienceOrbNPC extends EntityExperienceOrb implements NPCHolder { + private final CitizensNPC npc; + + public EntityExperienceOrbNPC(World world) { + this(world, null); + } + + public EntityExperienceOrbNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + public void g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new ExperienceOrbNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public void t_() { + if (npc != null) { + npc.update(); + } else { + super.t_(); + } + } + } + + public static class ExperienceOrbNPC extends CraftExperienceOrb implements NPCHolder { + private final CitizensNPC npc; + + public ExperienceOrbNPC(EntityExperienceOrbNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/FallingBlockController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/FallingBlockController.java new file mode 100644 index 000000000..ff7d499d5 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/FallingBlockController.java @@ -0,0 +1,170 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftFallingSand; +import org.bukkit.craftbukkit.v1_8_R3.util.CraftMagicNumbers; +import org.bukkit.entity.Entity; +import org.bukkit.entity.FallingBlock; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +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.Block; +import net.minecraft.server.v1_8_R3.Blocks; +import net.minecraft.server.v1_8_R3.EntityFallingBlock; +import net.minecraft.server.v1_8_R3.IBlockData; +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 FallingBlockController extends AbstractEntityController { + public FallingBlockController() { + super(EntityFallingBlockNPC.class); + } + + @Override + protected Entity createEntity(Location at, NPC npc) { + WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); + Block id = Blocks.STONE; + int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0)); + if (npc.data().has("falling-block-id") || npc.data().has(NPC.ITEM_ID_METADATA)) { + id = CraftMagicNumbers.getBlock(Material.getMaterial( + npc.data(). get(NPC.ITEM_ID_METADATA, npc.data(). get("falling-block-id")))); + } + final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(), + id.fromLegacyData(data)); + return handle.getBukkitEntity(); + } + + @Override + public FallingBlock getBukkitEntity() { + return (FallingBlock) super.getBukkitEntity(); + } + + public static class EntityFallingBlockNPC extends EntityFallingBlock implements NPCHolder { + private final CitizensNPC npc; + + public EntityFallingBlockNPC(World world) { + this(world, null); + } + + public EntityFallingBlockNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + public EntityFallingBlockNPC(World world, NPC npc, double d0, double d1, double d2, IBlockData data) { + super(world, d0, d1, d2, data); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + public void g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new FallingBlockNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + 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 t_() { + if (npc != null) { + npc.update(); + if (Math.abs(motX) > EPSILON || Math.abs(motY) > EPSILON || Math.abs(motZ) > EPSILON) { + motX *= 0.98; + motY *= 0.98; + motZ *= 0.98; + move(motX, motY, motZ); + } + } else { + super.t_(); + } + } + + private static final double EPSILON = 0.001; + } + + public static class FallingBlockNPC extends CraftFallingSand implements NPCHolder { + private final CitizensNPC npc; + + public FallingBlockNPC(EntityFallingBlockNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + + public void setType(Material material, int data) { + 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()); + } + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/FireworkController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/FireworkController.java new file mode 100644 index 000000000..c11ba10f4 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/FireworkController.java @@ -0,0 +1,115 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.EntityFireworks; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftFirework; +import org.bukkit.entity.Firework; +import org.bukkit.util.Vector; + +public class FireworkController extends MobEntityController { + public FireworkController() { + super(EntityFireworkNPC.class); + } + + @Override + public Firework getBukkitEntity() { + return (Firework) super.getBukkitEntity(); + } + + public static class EntityFireworkNPC extends EntityFireworks implements NPCHolder { + private final CitizensNPC npc; + + public EntityFireworkNPC(World world) { + this(world, null); + } + + public EntityFireworkNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new FireworkNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public void t_() { + if (npc != null) { + npc.update(); + } else { + super.t_(); + } + } + } + + public static class FireworkNPC extends CraftFirework implements NPCHolder { + private final CitizensNPC npc; + + public FireworkNPC(EntityFireworkNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/FishingHookController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/FishingHookController.java new file mode 100644 index 000000000..4f88600a6 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/FishingHookController.java @@ -0,0 +1,115 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftFish; +import org.bukkit.entity.FishHook; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.EntityFishingHook; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class FishingHookController extends MobEntityController { + public FishingHookController() { + super(EntityFishingHookNPC.class); + } + + @Override + public FishHook getBukkitEntity() { + return (FishHook) super.getBukkitEntity(); + } + + public static class EntityFishingHookNPC extends EntityFishingHook implements NPCHolder { + private final CitizensNPC npc; + + public EntityFishingHookNPC(World world) { + this(world, null); + } + + public EntityFishingHookNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + public void g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new FishingHookNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public void t_() { + if (npc != null) { + npc.update(); + } else { + super.t_(); + } + } + } + + public static class FishingHookNPC extends CraftFish implements NPCHolder { + private final CitizensNPC npc; + + public FishingHookNPC(EntityFishingHookNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/ItemController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/ItemController.java new file mode 100644 index 000000000..df52ee1a6 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/ItemController.java @@ -0,0 +1,153 @@ +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; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftItem; +import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; +import org.bukkit.util.Vector; + +public class ItemController extends AbstractEntityController { + public ItemController() { + super(EntityItemNPC.class); + } + + @Override + protected Entity createEntity(Location at, NPC npc) { + WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); + Material id = Material.STONE; + int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0)); + if (npc.data().has(NPC.ITEM_ID_METADATA)) { + id = Material.getMaterial(npc.data(). get(NPC.ITEM_ID_METADATA)); + } + final EntityItemNPC handle = new EntityItemNPC(ws, npc, at.getX(), at.getY(), at.getZ(), + CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id, 1, (short) data))); + return handle.getBukkitEntity(); + } + + @Override + public Item getBukkitEntity() { + return (Item) super.getBukkitEntity(); + } + + public static class EntityItemNPC extends EntityItem implements NPCHolder { + private final CitizensNPC npc; + + public EntityItemNPC(World world) { + super(world); + this.npc = null; + } + + public EntityItemNPC(World world, NPC npc, double x, double y, double z, ItemStack stack) { + super(world, x, y, z, stack); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 d(EntityHuman entityhuman) { + if (npc == null) { + super.d(entityhuman); + } + } + + @Override + public boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + public void g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new ItemNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public void t_() { + if (npc != null) { + npc.update(); + } else { + super.t_(); + } + } + } + + public static class ItemNPC extends CraftItem implements NPCHolder { + private final CitizensNPC npc; + + public ItemNPC(EntityItemNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + + public void setType(Material material, int data) { + 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()); + } + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/ItemFrameController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/ItemFrameController.java new file mode 100644 index 000000000..f505a0680 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/ItemFrameController.java @@ -0,0 +1,150 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftItemFrame; +import org.bukkit.entity.Entity; +import org.bukkit.entity.ItemFrame; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityItemFrame; +import net.minecraft.server.v1_8_R3.EnumDirection; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class ItemFrameController extends MobEntityController { + public ItemFrameController() { + super(EntityItemFrameNPC.class); + } + + @Override + protected Entity createEntity(Location at, NPC npc) { + Entity e = super.createEntity(at, npc); + EntityItemFrame item = (EntityItemFrame) ((CraftEntity) e).getHandle(); + item.setDirection(EnumDirection.EAST); + item.blockPosition = new BlockPosition(at.getX(), at.getY(), at.getZ()); + return e; + } + + @Override + public ItemFrame getBukkitEntity() { + return (ItemFrame) super.getBukkitEntity(); + } + + public static class EntityItemFrameNPC extends EntityItemFrame implements NPCHolder { + private final CitizensNPC npc; + + public EntityItemFrameNPC(World world) { + this(world, null); + } + + public EntityItemFrameNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + public void g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new ItemFrameNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public boolean survives() { + return npc == null || !npc.isProtected() ? super.survives() : true; + } + + @Override + public void t_() { + if (npc != null) { + npc.update(); + } else { + super.t_(); + } + } + } + + public static class ItemFrameNPC extends CraftItemFrame implements NPCHolder { + private final CitizensNPC npc; + + public ItemFrameNPC(EntityItemFrameNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + Material id = Material.STONE; + int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0)); + if (npc.data().has(NPC.ITEM_ID_METADATA)) { + id = Material.getMaterial(npc.data(). get(NPC.ITEM_ID_METADATA)); + } + getItem().setType(id); + getItem().setDurability((short) data); + } + + @Override + public NPC getNPC() { + return npc; + } + + public void setType(Material material, int data) { + 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()); + } + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/LargeFireballController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/LargeFireballController.java new file mode 100644 index 000000000..34b8598ce --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/LargeFireballController.java @@ -0,0 +1,128 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLargeFireball; +import org.bukkit.entity.LargeFireball; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.EntityLargeFireball; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class LargeFireballController extends MobEntityController { + public LargeFireballController() { + super(EntityLargeFireballNPC.class); + } + + @Override + public LargeFireball getBukkitEntity() { + return (LargeFireball) super.getBukkitEntity(); + } + + public static class EntityLargeFireballNPC extends EntityLargeFireball implements NPCHolder { + private final CitizensNPC npc; + + public EntityLargeFireballNPC(World world) { + this(world, null); + } + + public EntityLargeFireballNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + public void g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new LargeFireballNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + 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 t_() { + if (npc != null) { + npc.update(); + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) { + super.t_(); + } + } else { + super.t_(); + } + } + } + + public static class LargeFireballNPC extends CraftLargeFireball implements NPCHolder { + private final CitizensNPC npc; + + public LargeFireballNPC(EntityLargeFireballNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/LeashController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/LeashController.java new file mode 100644 index 000000000..537f05afa --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/LeashController.java @@ -0,0 +1,120 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.EntityLeash; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLeash; +import org.bukkit.entity.LeashHitch; +import org.bukkit.util.Vector; + +public class LeashController extends MobEntityController { + public LeashController() { + super(EntityLeashNPC.class); + } + + @Override + public LeashHitch getBukkitEntity() { + return (LeashHitch) super.getBukkitEntity(); + } + + public static class EntityLeashNPC extends EntityLeash implements NPCHolder { + private final CitizensNPC npc; + + public EntityLeashNPC(World world) { + this(world, null); + } + + public EntityLeashNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + public void g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new LeashNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public void t_() { + if (npc != null) { + npc.update(); + } else { + super.t_(); + } + } + + @Override + public boolean survives() { + return npc == null || !npc.isProtected() ? super.survives() : true; + } + } + + public static class LeashNPC extends CraftLeash implements NPCHolder { + private final CitizensNPC npc; + + public LeashNPC(EntityLeashNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartChestController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartChestController.java new file mode 100644 index 000000000..2f4606803 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartChestController.java @@ -0,0 +1,124 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftMinecartChest; +import org.bukkit.entity.Minecart; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.DamageSource; +import net.minecraft.server.v1_8_R3.EntityMinecartChest; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class MinecartChestController extends MobEntityController { + public MinecartChestController() { + super(EntityMinecartChestNPC.class); + } + + @Override + public Minecart getBukkitEntity() { + return (Minecart) super.getBukkitEntity(); + } + + public static class EntityMinecartChestNPC extends EntityMinecartChest implements NPCHolder { + private final CitizensNPC npc; + + public EntityMinecartChestNPC(World world) { + this(world, null); + } + + public EntityMinecartChestNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + public boolean damageEntity(DamageSource damagesource, float f) { + if (npc == null || !npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + return super.damageEntity(damagesource, f); + return false; + } + + @Override + public void g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new MinecartChestNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public void t_() { + super.t_(); + if (npc != null) { + npc.update(); + NMSImpl.minecartItemLogic(this); + } + } + } + + public static class MinecartChestNPC extends CraftMinecartChest implements NPCHolder { + private final CitizensNPC npc; + + public MinecartChestNPC(EntityMinecartChestNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartCommandController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartCommandController.java new file mode 100644 index 000000000..0d6afbdb2 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartCommandController.java @@ -0,0 +1,124 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftMinecartCommand; +import org.bukkit.entity.Minecart; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.DamageSource; +import net.minecraft.server.v1_8_R3.EntityMinecartCommandBlock; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class MinecartCommandController extends MobEntityController { + public MinecartCommandController() { + super(EntityMinecartCommandNPC.class); + } + + @Override + public Minecart getBukkitEntity() { + return (Minecart) super.getBukkitEntity(); + } + + public static class EntityMinecartCommandNPC extends EntityMinecartCommandBlock implements NPCHolder { + private final CitizensNPC npc; + + public EntityMinecartCommandNPC(World world) { + this(world, null); + } + + public EntityMinecartCommandNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + public boolean damageEntity(DamageSource damagesource, float f) { + if (npc == null || !npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + return super.damageEntity(damagesource, f); + return false; + } + + @Override + public void g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new MinecartCommandNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public void t_() { + super.t_(); + if (npc != null) { + npc.update(); + NMSImpl.minecartItemLogic(this); + } + } + } + + public static class MinecartCommandNPC extends CraftMinecartCommand implements NPCHolder { + private final CitizensNPC npc; + + public MinecartCommandNPC(EntityMinecartCommandNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartFurnaceController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartFurnaceController.java new file mode 100644 index 000000000..75dca6952 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartFurnaceController.java @@ -0,0 +1,124 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftMinecartFurnace; +import org.bukkit.entity.Minecart; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.DamageSource; +import net.minecraft.server.v1_8_R3.EntityMinecartFurnace; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class MinecartFurnaceController extends MobEntityController { + public MinecartFurnaceController() { + super(EntityMinecartFurnaceNPC.class); + } + + @Override + public Minecart getBukkitEntity() { + return (Minecart) super.getBukkitEntity(); + } + + public static class EntityMinecartFurnaceNPC extends EntityMinecartFurnace implements NPCHolder { + private final CitizensNPC npc; + + public EntityMinecartFurnaceNPC(World world) { + this(world, null); + } + + public EntityMinecartFurnaceNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + public boolean damageEntity(DamageSource damagesource, float f) { + if (npc == null || !npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + return super.damageEntity(damagesource, f); + return false; + } + + @Override + public void g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new MinecartFurnaceNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public void t_() { + super.t_(); + if (npc != null) { + npc.update(); + NMSImpl.minecartItemLogic(this); + } + } + } + + public static class MinecartFurnaceNPC extends CraftMinecartFurnace implements NPCHolder { + private final CitizensNPC npc; + + public MinecartFurnaceNPC(EntityMinecartFurnaceNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartHopperController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartHopperController.java new file mode 100644 index 000000000..ac5aa25fa --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartHopperController.java @@ -0,0 +1,98 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import org.bukkit.entity.Minecart; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.DamageSource; +import net.minecraft.server.v1_8_R3.EntityMinecartHopper; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class MinecartHopperController extends MobEntityController { + public MinecartHopperController() { + super(EntityMinecartHopperNPC.class); + } + + @Override + public Minecart getBukkitEntity() { + return (Minecart) super.getBukkitEntity(); + } + + public static class EntityMinecartHopperNPC extends EntityMinecartHopper implements NPCHolder { + private final CitizensNPC npc; + + public EntityMinecartHopperNPC(World world) { + this(world, null); + } + + public EntityMinecartHopperNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + public boolean damageEntity(DamageSource damagesource, float f) { + if (npc == null || !npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + return super.damageEntity(damagesource, f); + return false; + } + + @Override + public void g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 NPC getNPC() { + return npc; + } + + @Override + public void t_() { + super.t_(); + if (npc != null) { + npc.update(); + NMSImpl.minecartItemLogic(this); + } + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartRideableController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartRideableController.java new file mode 100644 index 000000000..eac20393e --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartRideableController.java @@ -0,0 +1,124 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftMinecartRideable; +import org.bukkit.entity.Minecart; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.DamageSource; +import net.minecraft.server.v1_8_R3.EntityMinecartRideable; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class MinecartRideableController extends MobEntityController { + public MinecartRideableController() { + super(EntityMinecartRideableNPC.class); + } + + @Override + public Minecart getBukkitEntity() { + return (Minecart) super.getBukkitEntity(); + } + + public static class EntityMinecartRideableNPC extends EntityMinecartRideable implements NPCHolder { + private final CitizensNPC npc; + + public EntityMinecartRideableNPC(World world) { + this(world, null); + } + + public EntityMinecartRideableNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + public boolean damageEntity(DamageSource damagesource, float f) { + if (npc == null || !npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + return super.damageEntity(damagesource, f); + return false; + } + + @Override + public void g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new MinecartRideableNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public void t_() { + super.t_(); + if (npc != null) { + npc.update(); + NMSImpl.minecartItemLogic(this); + } + } + } + + public static class MinecartRideableNPC extends CraftMinecartRideable implements NPCHolder { + private final CitizensNPC npc; + + public MinecartRideableNPC(EntityMinecartRideableNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartSpawnerController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartSpawnerController.java new file mode 100644 index 000000000..6747e61b2 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartSpawnerController.java @@ -0,0 +1,98 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import org.bukkit.entity.Minecart; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.DamageSource; +import net.minecraft.server.v1_8_R3.EntityMinecartMobSpawner; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class MinecartSpawnerController extends MobEntityController { + public MinecartSpawnerController() { + super(EntityMinecartSpawnerNPC.class); + } + + @Override + public Minecart getBukkitEntity() { + return (Minecart) super.getBukkitEntity(); + } + + public static class EntityMinecartSpawnerNPC extends EntityMinecartMobSpawner implements NPCHolder { + private final CitizensNPC npc; + + public EntityMinecartSpawnerNPC(World world) { + this(world, null); + } + + public EntityMinecartSpawnerNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + public boolean damageEntity(DamageSource damagesource, float f) { + if (npc == null || !npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + return super.damageEntity(damagesource, f); + return false; + } + + @Override + public void g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 NPC getNPC() { + return npc; + } + + @Override + public void t_() { + super.t_(); + if (npc != null) { + npc.update(); + NMSImpl.minecartItemLogic(this); + } + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartTNTController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartTNTController.java new file mode 100644 index 000000000..81e68cbf0 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/MinecartTNTController.java @@ -0,0 +1,98 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import org.bukkit.entity.Minecart; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.DamageSource; +import net.minecraft.server.v1_8_R3.EntityMinecartTNT; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class MinecartTNTController extends MobEntityController { + public MinecartTNTController() { + super(EntityMinecartTNTNPC.class); + } + + @Override + public Minecart getBukkitEntity() { + return (Minecart) super.getBukkitEntity(); + } + + public static class EntityMinecartTNTNPC extends EntityMinecartTNT implements NPCHolder { + private final CitizensNPC npc; + + public EntityMinecartTNTNPC(World world) { + this(world, null); + } + + public EntityMinecartTNTNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + public boolean damageEntity(DamageSource damagesource, float f) { + if (npc == null || !npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + return super.damageEntity(damagesource, f); + return false; + } + + @Override + public void g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 NPC getNPC() { + return npc; + } + + @Override + public void t_() { + super.t_(); + if (npc != null) { + npc.update(); + NMSImpl.minecartItemLogic(this); + } + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/PaintingController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/PaintingController.java new file mode 100644 index 000000000..b72ec359a --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/PaintingController.java @@ -0,0 +1,120 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.EntityPainting; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPainting; +import org.bukkit.entity.Painting; +import org.bukkit.util.Vector; + +public class PaintingController extends MobEntityController { + public PaintingController() { + super(EntityPaintingNPC.class); + } + + @Override + public Painting getBukkitEntity() { + return (Painting) super.getBukkitEntity(); + } + + public static class EntityPaintingNPC extends EntityPainting implements NPCHolder { + private final CitizensNPC npc; + + public EntityPaintingNPC(World world) { + this(world, null); + } + + public EntityPaintingNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new PaintingNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public void t_() { + if (npc != null) { + npc.update(); + } else { + super.t_(); + } + } + + @Override + public boolean survives() { + return npc == null || !npc.isProtected() ? super.survives() : true; + } + } + + public static class PaintingNPC extends CraftPainting implements NPCHolder { + private final CitizensNPC npc; + + public PaintingNPC(EntityPaintingNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/SmallFireballController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/SmallFireballController.java new file mode 100644 index 000000000..a7b660bc6 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/SmallFireballController.java @@ -0,0 +1,118 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftSmallFireball; +import org.bukkit.entity.SmallFireball; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.EntitySmallFireball; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class SmallFireballController extends MobEntityController { + public SmallFireballController() { + super(EntitySmallFireballNPC.class); + } + + @Override + public SmallFireball getBukkitEntity() { + return (SmallFireball) super.getBukkitEntity(); + } + + public static class EntitySmallFireballNPC extends EntitySmallFireball implements NPCHolder { + private final CitizensNPC npc; + + public EntitySmallFireballNPC(World world) { + this(world, null); + } + + public EntitySmallFireballNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + public void g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new SmallFireballNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public void t_() { + if (npc != null) { + npc.update(); + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) { + super.t_(); + } + } else { + super.t_(); + } + } + } + + public static class SmallFireballNPC extends CraftSmallFireball implements NPCHolder { + private final CitizensNPC npc; + + public SmallFireballNPC(EntitySmallFireballNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/SnowballController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/SnowballController.java new file mode 100644 index 000000000..0c65fc7d2 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/SnowballController.java @@ -0,0 +1,115 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.EntitySnowball; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftSnowball; +import org.bukkit.entity.Snowball; +import org.bukkit.util.Vector; + +public class SnowballController extends MobEntityController { + public SnowballController() { + super(EntitySnowballNPC.class); + } + + @Override + public Snowball getBukkitEntity() { + return (Snowball) super.getBukkitEntity(); + } + + public static class SnowballNPC extends CraftSnowball implements NPCHolder { + private final CitizensNPC npc; + + public SnowballNPC(EntitySnowballNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } + + public static class EntitySnowballNPC extends EntitySnowball implements NPCHolder { + private final CitizensNPC npc; + + public EntitySnowballNPC(World world) { + this(world, null); + } + + @Override + public boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + public EntitySnowballNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new SnowballNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public void t_() { + if (npc != null) { + npc.update(); + } else { + super.t_(); + } + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/TNTPrimedController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/TNTPrimedController.java new file mode 100644 index 000000000..35efb984f --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/TNTPrimedController.java @@ -0,0 +1,115 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.EntityTNTPrimed; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftTNTPrimed; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.util.Vector; + +public class TNTPrimedController extends MobEntityController { + public TNTPrimedController() { + super(EntityTNTPrimedNPC.class); + } + + @Override + public TNTPrimed getBukkitEntity() { + return (TNTPrimed) super.getBukkitEntity(); + } + + public static class EntityTNTPrimedNPC extends EntityTNTPrimed implements NPCHolder { + private final CitizensNPC npc; + + public EntityTNTPrimedNPC(World world) { + this(world, null); + } + + @Override + public boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + public EntityTNTPrimedNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new TNTPrimedNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public void t_() { + if (npc != null) { + npc.update(); + } else { + super.t_(); + } + } + } + + public static class TNTPrimedNPC extends CraftTNTPrimed implements NPCHolder { + private final CitizensNPC npc; + + public TNTPrimedNPC(EntityTNTPrimedNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/ThrownExpBottleController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/ThrownExpBottleController.java new file mode 100644 index 000000000..61e31fdc3 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/ThrownExpBottleController.java @@ -0,0 +1,118 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftThrownExpBottle; +import org.bukkit.entity.ThrownExpBottle; +import org.bukkit.util.Vector; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.EntityThrownExpBottle; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +public class ThrownExpBottleController extends MobEntityController { + public ThrownExpBottleController() { + super(EntityThrownExpBottleNPC.class); + } + + @Override + public ThrownExpBottle getBukkitEntity() { + return (ThrownExpBottle) super.getBukkitEntity(); + } + + public static class EntityThrownExpBottleNPC extends EntityThrownExpBottle implements NPCHolder { + private final CitizensNPC npc; + + public EntityThrownExpBottleNPC(World world) { + this(world, null); + } + + public EntityThrownExpBottleNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + @Override + public void g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new ThrownExpBottleNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public void t_() { + if (npc != null) { + npc.update(); + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) { + super.t_(); + } + } else { + super.t_(); + } + } + } + + public static class ThrownExpBottleNPC extends CraftThrownExpBottle implements NPCHolder { + private final CitizensNPC npc; + + public ThrownExpBottleNPC(EntityThrownExpBottleNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/WitherSkullController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/WitherSkullController.java new file mode 100644 index 000000000..c892c8250 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/WitherSkullController.java @@ -0,0 +1,115 @@ +package net.citizensnpcs.nms.v1_8_R3.entity.nonliving; + +import net.citizensnpcs.api.event.NPCPushEvent; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.nms.v1_8_R3.entity.MobEntityController; +import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.EntityWitherSkull; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.World; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftWitherSkull; +import org.bukkit.entity.WitherSkull; +import org.bukkit.util.Vector; + +public class WitherSkullController extends MobEntityController { + public WitherSkullController() { + super(EntityWitherSkullNPC.class); + } + + @Override + public WitherSkull getBukkitEntity() { + return (WitherSkull) super.getBukkitEntity(); + } + + public static class EntityWitherSkullNPC extends EntityWitherSkull implements NPCHolder { + private final CitizensNPC npc; + + public EntityWitherSkullNPC(World world) { + this(world, null); + } + + @Override + public boolean d(NBTTagCompound save) { + return npc == null ? super.d(save) : false; + } + + public EntityWitherSkullNPC(World world, NPC npc) { + super(world); + this.npc = (CitizensNPC) npc; + } + + @Override + public void collide(net.minecraft.server.v1_8_R3.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 g(double x, double y, double z) { + if (npc == null) { + super.g(x, y, z); + return; + } + if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) { + if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) + super.g(x, y, z); + return; + } + Vector vector = new Vector(x, y, z); + NPCPushEvent event = Util.callPushEvent(npc, vector); + if (!event.isCancelled()) { + vector = event.getCollisionVector(); + super.g(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 CraftEntity getBukkitEntity() { + if (npc != null && !(bukkitEntity instanceof NPCHolder)) { + bukkitEntity = new WitherSkullNPC(this); + } + return super.getBukkitEntity(); + } + + @Override + public NPC getNPC() { + return npc; + } + + @Override + public void t_() { + if (npc != null) { + npc.update(); + } else { + super.t_(); + } + } + } + + public static class WitherSkullNPC extends CraftWitherSkull implements NPCHolder { + private final CitizensNPC npc; + + public WitherSkullNPC(EntityWitherSkullNPC entity) { + super((CraftServer) Bukkit.getServer(), entity); + this.npc = entity.npc; + } + + @Override + public NPC getNPC() { + return npc; + } + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/network/EmptyChannel.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/network/EmptyChannel.java new file mode 100644 index 000000000..a800ad095 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/network/EmptyChannel.java @@ -0,0 +1,80 @@ +package net.citizensnpcs.nms.v1_8_R3.network; + +import io.netty.channel.AbstractChannel; +import io.netty.channel.Channel; +import io.netty.channel.ChannelConfig; +import io.netty.channel.ChannelMetadata; +import io.netty.channel.ChannelOutboundBuffer; +import io.netty.channel.DefaultChannelConfig; +import io.netty.channel.EventLoop; + +import java.net.SocketAddress; + +public class EmptyChannel extends AbstractChannel { + private final ChannelConfig config = new DefaultChannelConfig(this); + + public EmptyChannel(Channel parent) { + super(parent); + } + + @Override + public ChannelConfig config() { + config.setAutoRead(true); + return config; + } + + @Override + protected void doBeginRead() throws Exception { + } + + @Override + protected void doBind(SocketAddress arg0) throws Exception { + } + + @Override + protected void doClose() throws Exception { + } + + @Override + protected void doDisconnect() throws Exception { + } + + @Override + protected void doWrite(ChannelOutboundBuffer arg0) throws Exception { + } + + @Override + public boolean isActive() { + return false; + } + + @Override + protected boolean isCompatible(EventLoop arg0) { + return true; + } + + @Override + public boolean isOpen() { + return false; + } + + @Override + protected SocketAddress localAddress0() { + return null; + } + + @Override + public ChannelMetadata metadata() { + return null; + } + + @Override + protected AbstractUnsafe newUnsafe() { + return null; + } + + @Override + protected SocketAddress remoteAddress0() { + return null; + } +} diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/network/EmptyNetHandler.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/network/EmptyNetHandler.java new file mode 100644 index 000000000..3c3422cba --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/network/EmptyNetHandler.java @@ -0,0 +1,17 @@ +package net.citizensnpcs.nms.v1_8_R3.network; + +import net.minecraft.server.v1_8_R3.EntityPlayer; +import net.minecraft.server.v1_8_R3.MinecraftServer; +import net.minecraft.server.v1_8_R3.NetworkManager; +import net.minecraft.server.v1_8_R3.Packet; +import net.minecraft.server.v1_8_R3.PlayerConnection; + +public class EmptyNetHandler extends PlayerConnection { + public EmptyNetHandler(MinecraftServer minecraftServer, NetworkManager networkManager, EntityPlayer entityPlayer) { + super(minecraftServer, networkManager, entityPlayer); + } + + @Override + public void sendPacket(Packet packet) { + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/network/EmptyNetworkManager.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/network/EmptyNetworkManager.java new file mode 100644 index 000000000..52ece4127 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/network/EmptyNetworkManager.java @@ -0,0 +1,19 @@ +package net.citizensnpcs.nms.v1_8_R3.network; + +import java.io.IOException; + +import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; +import net.minecraft.server.v1_8_R3.EnumProtocolDirection; +import net.minecraft.server.v1_8_R3.NetworkManager; + +public class EmptyNetworkManager extends NetworkManager { + public EmptyNetworkManager(EnumProtocolDirection flag) throws IOException { + super(flag); + NMSImpl.initNetworkManager(this); + } + + @Override + public boolean g() { + return true; + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/network/EmptySocket.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/network/EmptySocket.java new file mode 100644 index 000000000..636f26202 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/network/EmptySocket.java @@ -0,0 +1,21 @@ +package net.citizensnpcs.nms.v1_8_R3.network; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; + +public class EmptySocket extends Socket { + @Override + public InputStream getInputStream() { + return new ByteArrayInputStream(EMPTY); + } + + @Override + public OutputStream getOutputStream() { + return new ByteArrayOutputStream(10); + } + + private static final byte[] EMPTY = new byte[50]; +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/CitizensBlockBreaker.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/CitizensBlockBreaker.java new file mode 100644 index 000000000..8023db8f3 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/CitizensBlockBreaker.java @@ -0,0 +1,173 @@ +package net.citizensnpcs.nms.v1_8_R3.util; + +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; +import org.bukkit.entity.Player; + +import net.citizensnpcs.api.ai.tree.BehaviorStatus; +import net.citizensnpcs.api.npc.BlockBreaker; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.util.PlayerAnimation; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.Blocks; +import net.minecraft.server.v1_8_R3.EnchantmentManager; +import net.minecraft.server.v1_8_R3.Entity; +import net.minecraft.server.v1_8_R3.EntityLiving; +import net.minecraft.server.v1_8_R3.EntityPlayer; +import net.minecraft.server.v1_8_R3.IBlockData; +import net.minecraft.server.v1_8_R3.ItemStack; +import net.minecraft.server.v1_8_R3.Material; +import net.minecraft.server.v1_8_R3.MobEffectList; + +public class CitizensBlockBreaker extends BlockBreaker { + private final BlockBreakerConfiguration configuration; + private int currentDamage; + private int currentTick; + private final Entity entity; + private boolean isDigging = true; + private final Location location; + private int startDigTick; + private final int x, y, z; + + public CitizensBlockBreaker(org.bukkit.entity.Entity entity, org.bukkit.block.Block target, + BlockBreakerConfiguration config) { + this.entity = ((CraftEntity) entity).getHandle(); + this.x = target.getX(); + this.y = target.getY(); + this.z = target.getZ(); + this.location = target.getLocation(); + this.startDigTick = (int) (System.currentTimeMillis() / 50); + this.configuration = config; + } + + private double distanceSquared() { + return Math.pow(entity.locX - x, 2) + Math.pow(entity.locY - y, 2) + Math.pow(entity.locZ - z, 2); + } + + private net.minecraft.server.v1_8_R3.ItemStack getCurrentItem() { + return configuration.item() != null ? CraftItemStack.asNMSCopy(configuration.item()) + : entity instanceof EntityLiving ? ((EntityLiving) entity).getEquipment(0) : null; + } + + private float getStrength(Block block) { + float base = block.g(null, new BlockPosition(0, 0, 0)); + return base < 0.0F ? 0.0F : (!isDestroyable(block) ? 1.0F / base / 100.0F : strengthMod(block) / base / 30.0F); + } + + private boolean isDestroyable(Block block) { + if (block.getMaterial().isAlwaysDestroyable()) { + return true; + } else { + ItemStack current = getCurrentItem(); + return current != null ? current.b(block) : false; + } + } + + @Override + public void reset() { + if (configuration.callback() != null) { + configuration.callback().run(); + } + isDigging = false; + setBlockDamage(currentDamage = -1); + } + + @Override + public BehaviorStatus run() { + if (entity.dead) { + return BehaviorStatus.FAILURE; + } + if (!isDigging) { + return BehaviorStatus.SUCCESS; + } + currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit + if (configuration.radiusSquared() > 0 && distanceSquared() >= configuration.radiusSquared()) { + startDigTick = currentTick; + if (entity instanceof NPCHolder) { + NPC npc = ((NPCHolder) entity).getNPC(); + if (npc != null && !npc.getNavigator().isNavigating()) { + npc.getNavigator() + .setTarget(entity.world.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0)); + } + } + return BehaviorStatus.RUNNING; + } + Util.faceLocation(entity.getBukkitEntity(), location); + if (entity instanceof EntityPlayer) { + PlayerAnimation.ARM_SWING.play((Player) entity.getBukkitEntity()); + } + IBlockData block = entity.world.getType(new BlockPosition(x, y, z)); + if (block == null || block == Blocks.AIR) { + return BehaviorStatus.SUCCESS; + } else { + int tickDifference = currentTick - startDigTick; + float damage = getStrength(block.getBlock()) * (tickDifference + 1) * configuration.blockStrengthModifier(); + if (damage >= 1F) { + entity.world.getWorld().getBlockAt(x, y, z) + .breakNaturally(CraftItemStack.asCraftMirror(getCurrentItem())); + return BehaviorStatus.SUCCESS; + } + int modifiedDamage = (int) (damage * 10.0F); + if (modifiedDamage != currentDamage) { + setBlockDamage(modifiedDamage); + currentDamage = modifiedDamage; + } + } + return BehaviorStatus.RUNNING; + } + + private void setBlockDamage(int modifiedDamage) { + entity.world.c(entity.getId(), new BlockPosition(x, y, z), modifiedDamage); + } + + @Override + public boolean shouldExecute() { + return entity.world.getType(new BlockPosition(x, y, z)).getBlock() != Blocks.AIR; + } + + private float strengthMod(Block block) { + ItemStack itemstack = getCurrentItem(); + float f = itemstack.a(block); + if (entity instanceof EntityLiving) { + EntityLiving handle = (EntityLiving) entity; + if (f > 1.0F) { + int i = EnchantmentManager.getDigSpeedEnchantmentLevel(handle); + if (i > 0) { + f += i * i + 1; + } + } + if (handle.hasEffect(MobEffectList.FASTER_DIG)) { + f *= (1.0F + (handle.getEffect(MobEffectList.FASTER_DIG).getAmplifier() + 1) * 0.2F); + } + if (handle.hasEffect(MobEffectList.SLOWER_DIG)) { + float f1 = 1.0F; + switch (handle.getEffect(MobEffectList.SLOWER_DIG).getAmplifier()) { + case 0: + f1 = 0.3F; + break; + case 1: + f1 = 0.09F; + break; + case 2: + f1 = 0.0027F; + break; + case 3: + default: + f1 = 8.1E-4F; + } + f *= f1; + } + if ((handle.a(Material.WATER)) && (!EnchantmentManager.j(handle))) { + f /= 5.0F; + } + } + if (!entity.onGround) { + f /= 5.0F; + } + return f; + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java new file mode 100644 index 000000000..2edc72145 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java @@ -0,0 +1,1314 @@ +package net.citizensnpcs.nms.v1_8_R3.util; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.net.SocketAddress; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.EnumSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.Set; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.CraftSound; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftWither; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.FishHook; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Tameable; +import org.bukkit.entity.Wither; +import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; +import org.bukkit.inventory.meta.SkullMeta; +import org.bukkit.plugin.PluginLoadOrder; +import org.bukkit.util.Vector; + +import com.google.common.base.Function; +import com.google.common.base.Preconditions; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.GameProfileRepository; +import com.mojang.authlib.HttpAuthenticationService; +import com.mojang.authlib.minecraft.MinecraftSessionService; +import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService; +import com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService; +import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse; +import com.mojang.util.UUIDTypeAdapter; + +import net.citizensnpcs.Settings.Setting; +import net.citizensnpcs.api.ai.NavigatorParameters; +import net.citizensnpcs.api.ai.event.CancelReason; +import net.citizensnpcs.api.command.CommandManager; +import net.citizensnpcs.api.command.exception.CommandException; +import net.citizensnpcs.api.npc.BlockBreaker; +import net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.api.npc.NPCRegistry; +import net.citizensnpcs.api.util.Messaging; +import net.citizensnpcs.nms.v1_8_R3.entity.BatController; +import net.citizensnpcs.nms.v1_8_R3.entity.BlazeController; +import net.citizensnpcs.nms.v1_8_R3.entity.CaveSpiderController; +import net.citizensnpcs.nms.v1_8_R3.entity.ChickenController; +import net.citizensnpcs.nms.v1_8_R3.entity.CowController; +import net.citizensnpcs.nms.v1_8_R3.entity.CreeperController; +import net.citizensnpcs.nms.v1_8_R3.entity.EnderDragonController; +import net.citizensnpcs.nms.v1_8_R3.entity.EndermanController; +import net.citizensnpcs.nms.v1_8_R3.entity.EndermiteController; +import net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC; +import net.citizensnpcs.nms.v1_8_R3.entity.GhastController; +import net.citizensnpcs.nms.v1_8_R3.entity.GiantController; +import net.citizensnpcs.nms.v1_8_R3.entity.GuardianController; +import net.citizensnpcs.nms.v1_8_R3.entity.HorseController; +import net.citizensnpcs.nms.v1_8_R3.entity.HumanController; +import net.citizensnpcs.nms.v1_8_R3.entity.IronGolemController; +import net.citizensnpcs.nms.v1_8_R3.entity.MagmaCubeController; +import net.citizensnpcs.nms.v1_8_R3.entity.MushroomCowController; +import net.citizensnpcs.nms.v1_8_R3.entity.OcelotController; +import net.citizensnpcs.nms.v1_8_R3.entity.PigController; +import net.citizensnpcs.nms.v1_8_R3.entity.PigZombieController; +import net.citizensnpcs.nms.v1_8_R3.entity.RabbitController; +import net.citizensnpcs.nms.v1_8_R3.entity.SheepController; +import net.citizensnpcs.nms.v1_8_R3.entity.SilverfishController; +import net.citizensnpcs.nms.v1_8_R3.entity.SkeletonController; +import net.citizensnpcs.nms.v1_8_R3.entity.SlimeController; +import net.citizensnpcs.nms.v1_8_R3.entity.SnowmanController; +import net.citizensnpcs.nms.v1_8_R3.entity.SpiderController; +import net.citizensnpcs.nms.v1_8_R3.entity.SquidController; +import net.citizensnpcs.nms.v1_8_R3.entity.VillagerController; +import net.citizensnpcs.nms.v1_8_R3.entity.WitchController; +import net.citizensnpcs.nms.v1_8_R3.entity.WitherController; +import net.citizensnpcs.nms.v1_8_R3.entity.WolfController; +import net.citizensnpcs.nms.v1_8_R3.entity.ZombieController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.ArmorStandController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.BoatController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.EggController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.EnderCrystalController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.EnderPearlController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.EnderSignalController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.FallingBlockController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.FireworkController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.FishingHookController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.ItemController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.ItemFrameController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.LargeFireballController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.LeashController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.MinecartChestController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.MinecartCommandController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.MinecartFurnaceController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.MinecartHopperController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.MinecartRideableController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.MinecartTNTController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.PaintingController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.SmallFireballController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.SnowballController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.TNTPrimedController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.ThrownExpBottleController; +import net.citizensnpcs.nms.v1_8_R3.entity.nonliving.WitherSkullController; +import net.citizensnpcs.nms.v1_8_R3.network.EmptyChannel; +import net.citizensnpcs.npc.EntityControllers; +import net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator; +import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.npc.skin.SkinnableEntity; +import net.citizensnpcs.util.BoundingBox; +import net.citizensnpcs.util.Messages; +import net.citizensnpcs.util.NMS; +import net.citizensnpcs.util.NMSBridge; +import net.citizensnpcs.util.PlayerAnimation; +import net.citizensnpcs.util.PlayerUpdateTask; +import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.AttributeInstance; +import net.minecraft.server.v1_8_R3.AxisAlignedBB; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.ControllerJump; +import net.minecraft.server.v1_8_R3.CrashReport; +import net.minecraft.server.v1_8_R3.CrashReportSystemDetails; +import net.minecraft.server.v1_8_R3.DamageSource; +import net.minecraft.server.v1_8_R3.EnchantmentManager; +import net.minecraft.server.v1_8_R3.Entity; +import net.minecraft.server.v1_8_R3.EntityEnderDragon; +import net.minecraft.server.v1_8_R3.EntityFishingHook; +import net.minecraft.server.v1_8_R3.EntityHorse; +import net.minecraft.server.v1_8_R3.EntityHuman; +import net.minecraft.server.v1_8_R3.EntityInsentient; +import net.minecraft.server.v1_8_R3.EntityLiving; +import net.minecraft.server.v1_8_R3.EntityMinecartAbstract; +import net.minecraft.server.v1_8_R3.EntityPlayer; +import net.minecraft.server.v1_8_R3.EntityTameableAnimal; +import net.minecraft.server.v1_8_R3.EntityTracker; +import net.minecraft.server.v1_8_R3.EntityTrackerEntry; +import net.minecraft.server.v1_8_R3.EntityTypes; +import net.minecraft.server.v1_8_R3.EntityWither; +import net.minecraft.server.v1_8_R3.GenericAttributes; +import net.minecraft.server.v1_8_R3.MathHelper; +import net.minecraft.server.v1_8_R3.NavigationAbstract; +import net.minecraft.server.v1_8_R3.NetworkManager; +import net.minecraft.server.v1_8_R3.Packet; +import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport; +import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo; +import net.minecraft.server.v1_8_R3.PathEntity; +import net.minecraft.server.v1_8_R3.PathPoint; +import net.minecraft.server.v1_8_R3.PathfinderGoalSelector; +import net.minecraft.server.v1_8_R3.ReportedException; +import net.minecraft.server.v1_8_R3.WorldServer; + +@SuppressWarnings("unchecked") +public class NMSImpl implements NMSBridge { + public NMSImpl() { + loadEntityTypes(); + } + + @Override + public boolean addEntityToWorld(org.bukkit.entity.Entity entity, SpawnReason custom) { + return getHandle(entity).world.addEntity(getHandle(entity), custom); + } + + @Override + public void addOrRemoveFromPlayerList(org.bukkit.entity.Entity entity, boolean remove) { + if (entity == null) + return; + EntityHuman handle = (EntityHuman) getHandle(entity); + if (handle.world == null) + return; + if (remove) { + handle.world.players.remove(handle); + } else if (!handle.world.players.contains(handle)) { + handle.world.players.add(handle); + } + PlayerUpdateTask.addOrRemove(entity, remove); + } + + @Override + public void attack(LivingEntity attacker, LivingEntity btarget) { + EntityLiving handle = getHandle(attacker); + EntityLiving target = getHandle(btarget); + if (handle instanceof EntityPlayer) { + EntityPlayer humanHandle = (EntityPlayer) handle; + humanHandle.attack(target); + PlayerAnimation.ARM_SWING.play(humanHandle.getBukkitEntity()); + return; + } + AttributeInstance attackDamage = handle.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE); + float f = (float) (attackDamage == null ? 1 : attackDamage.getValue()); + int i = 0; + + if (target instanceof EntityLiving) { + f += EnchantmentManager.a(handle.bA(), target.getMonsterType()); + i += EnchantmentManager.a(handle); + } + + boolean flag = target.damageEntity(DamageSource.mobAttack(handle), f); + + if (!flag) + return; + if (i > 0) { + target.g(-Math.sin(handle.yaw * Math.PI / 180.0F) * i * 0.5F, 0.1D, + Math.cos(handle.yaw * Math.PI / 180.0F) * i * 0.5F); + handle.motX *= 0.6D; + handle.motZ *= 0.6D; + } + + int fireAspectLevel = EnchantmentManager.getFireAspectEnchantmentLevel(handle); + + if (fireAspectLevel > 0) { + target.setOnFire(fireAspectLevel * 4); + } + } + + @Override + public GameProfile fillProfileProperties(GameProfile profile, boolean requireSecure) throws Exception { + if (Bukkit.isPrimaryThread()) + throw new IllegalStateException("NMS.fillProfileProperties cannot be invoked from the main thread."); + + MinecraftSessionService sessionService = ((CraftServer) Bukkit.getServer()).getServer().aD(); + + if (!(sessionService instanceof YggdrasilMinecraftSessionService)) { + return sessionService.fillProfileProperties(profile, requireSecure); + } + YggdrasilAuthenticationService auth = ((YggdrasilMinecraftSessionService) sessionService) + .getAuthenticationService(); + + URL url = HttpAuthenticationService + .constantURL(getAuthServerBaseUrl() + UUIDTypeAdapter.fromUUID(profile.getId())); + + url = HttpAuthenticationService.concatenateURL(url, "unsigned=" + !requireSecure); + + MinecraftProfilePropertiesResponse response = (MinecraftProfilePropertiesResponse) MAKE_REQUEST.invoke(auth, + url, null, MinecraftProfilePropertiesResponse.class); + if (response == null) + return profile; + + GameProfile result = new GameProfile(response.getId(), response.getName()); + result.getProperties().putAll(response.getProperties()); + profile.getProperties().putAll(response.getProperties()); + + return result; + } + + public String getAuthServerBaseUrl() { + return Setting.AUTH_SERVER_URL.asString(); + } + + @Override + public BlockBreaker getBlockBreaker(org.bukkit.entity.Entity entity, org.bukkit.block.Block targetBlock, + BlockBreakerConfiguration config) { + return new CitizensBlockBreaker(entity, targetBlock, config); + } + + @Override + public BoundingBox getBoundingBox(org.bukkit.entity.Entity handle) { + AxisAlignedBB bb = NMSImpl.getHandle(handle).getBoundingBox(); + return new BoundingBox(bb.a, bb.b, bb.c, bb.d, bb.e, bb.f); + } + + private float getDragonYaw(Entity handle, double tX, double tZ) { + if (handle.locZ > tZ) + return (float) (-Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ)))); + if (handle.locZ < tZ) { + return (float) (-Math.toDegrees(Math.atan((handle.locX - tX) / (handle.locZ - tZ)))) + 180.0F; + } + return handle.yaw; + } + + @Override + public GameProfileRepository getGameProfileRepository() { + return ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository(); + } + + @Override + public float getHeadYaw(org.bukkit.entity.Entity entity) { + if (!(entity instanceof LivingEntity)) { + return entity.getLocation().getYaw(); + } + return getHandle((LivingEntity) entity).aK; + } + + @Override + public float getHorizontalMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); + return handle.ba; + } + + @Override + public NPC getNPC(org.bukkit.entity.Entity entity) { + return getHandle(entity) instanceof NPCHolder ? ((NPCHolder) getHandle(entity)).getNPC() : null; + } + + @Override + public List getPassengers(org.bukkit.entity.Entity entity) { + Entity passenger = NMSImpl.getHandle(entity).passenger; + if (passenger == null) + return Collections.emptyList(); + return Lists. newArrayList(passenger.getBukkitEntity()); + } + + @Override + public GameProfile getProfile(SkullMeta meta) { + if (SKULL_PROFILE_FIELD == null) { + try { + SKULL_PROFILE_FIELD = meta.getClass().getDeclaredField("profile"); + SKULL_PROFILE_FIELD.setAccessible(true); + } catch (Exception e) { + return null; + } + } + try { + return (GameProfile) SKULL_PROFILE_FIELD.get(meta); + } catch (Exception e) { + return null; + } + } + + @Override + public String getSound(String flag) throws CommandException { + try { + String ret = CraftSound.getSound(Sound.valueOf(flag.toUpperCase())); + if (ret == null) + throw new CommandException(Messages.INVALID_SOUND); + return ret; + } catch (Exception e) { + throw new CommandException(Messages.INVALID_SOUND); + } + } + + @Override + public float getSpeedFor(NPC npc) { + if (!npc.isSpawned() || !(npc.getEntity() instanceof LivingEntity)) + return DEFAULT_SPEED; + EntityLiving handle = NMSImpl.getHandle((LivingEntity) npc.getEntity()); + if (handle == null) + return DEFAULT_SPEED; + return DEFAULT_SPEED; + // return (float) + // handle.getAttributeInstance(GenericAttributes.d).getValue(); + } + + @Override + public float getStepHeight(org.bukkit.entity.Entity entity) { + return NMSImpl.getHandle(entity).S; + } + + @Override + public MCNavigator getTargetNavigator(org.bukkit.entity.Entity entity, Iterable dest, + final NavigatorParameters params) { + final PathEntity path = new PathEntity( + Iterables.toArray(Iterables.transform(dest, new Function() { + @Override + public PathPoint apply(Vector input) { + return new PathPoint(input.getBlockX(), input.getBlockY(), input.getBlockZ()); + } + }), PathPoint.class)); + return getTargetNavigator(entity, params, new Function() { + @Override + public Boolean apply(NavigationAbstract input) { + return input.a(path, params.speed()); + } + }); + } + + @Override + public MCNavigator getTargetNavigator(final org.bukkit.entity.Entity entity, final Location dest, + final NavigatorParameters params) { + return getTargetNavigator(entity, params, new Function() { + @Override + public Boolean apply(NavigationAbstract input) { + return input.a(dest.getX(), dest.getY(), dest.getZ(), params.speed()); + } + }); + } + + private MCNavigator getTargetNavigator(final org.bukkit.entity.Entity entity, final NavigatorParameters params, + final Function function) { + net.minecraft.server.v1_8_R3.Entity raw = getHandle(entity); + raw.onGround = true; + // not sure of a better way around this - if onGround is false, then + // navigation won't execute, and calling entity.move doesn't + // entirely fix the problem. + final NavigationAbstract navigation = NMSImpl.getNavigation(entity); + return new MCNavigator() { + float lastSpeed; + CancelReason reason; + + @Override + public CancelReason getCancelReason() { + return reason; + } + + @Override + public Iterable getPath() { + return new NavigationIterable(navigation); + } + + @Override + public void stop() { + stopNavigation(navigation); + } + + @Override + public boolean update() { + if (params.speed() != lastSpeed) { + if (Messaging.isDebugging()) { + Messaging.debug( + "Repathfinding " + ((NPCHolder) entity).getNPC().getId() + " due to speed change"); + } + Entity handle = getHandle(entity); + float oldWidth = handle.width; + if (handle instanceof EntityHorse) { + handle.width = Math.min(0.99f, oldWidth); + } + if (!function.apply(navigation)) { + reason = CancelReason.STUCK; + } + handle.width = oldWidth; // minecraft requires that an entity fit onto both blocks if width >= 1f, + // but we'd prefer to make it just fit on 1 so hack around it a bit. + lastSpeed = params.speed(); + } + navigation.a(params.speed()); + return NMSImpl.isNavigationFinished(navigation); + } + }; + } + + @Override + public TargetNavigator getTargetNavigator(org.bukkit.entity.Entity entity, org.bukkit.entity.Entity target, + NavigatorParameters parameters) { + NavigationAbstract navigation = getNavigation(entity); + return navigation == null ? null : new NavigationFieldWrapper(navigation, target, parameters); + } + + @Override + public org.bukkit.entity.Entity getVehicle(org.bukkit.entity.Entity entity) { + Entity handle = NMSImpl.getHandle(entity); + if (handle == null) { + return null; + } + Entity e = handle.vehicle; + return (e == handle || e == null) ? null : e.getBukkitEntity(); + } + + @Override + public float getVerticalMovement(org.bukkit.entity.Entity entity) { + if (!entity.getType().isAlive()) + return Float.NaN; + EntityLiving handle = NMSImpl.getHandle((LivingEntity) entity); + return handle.aZ; + } + + @Override + public boolean isOnGround(org.bukkit.entity.Entity entity) { + return NMSImpl.getHandle(entity).onGround; + } + + @Override + public void load(CommandManager commands) { + } + + private void loadEntityTypes() { + EntityControllers.setEntityControllerForType(EntityType.ARMOR_STAND, ArmorStandController.class); + EntityControllers.setEntityControllerForType(EntityType.BAT, BatController.class); + EntityControllers.setEntityControllerForType(EntityType.BLAZE, BlazeController.class); + EntityControllers.setEntityControllerForType(EntityType.BOAT, BoatController.class); + EntityControllers.setEntityControllerForType(EntityType.CAVE_SPIDER, CaveSpiderController.class); + EntityControllers.setEntityControllerForType(EntityType.CHICKEN, ChickenController.class); + EntityControllers.setEntityControllerForType(EntityType.COW, CowController.class); + EntityControllers.setEntityControllerForType(EntityType.CREEPER, CreeperController.class); + EntityControllers.setEntityControllerForType(EntityType.DROPPED_ITEM, ItemController.class); + EntityControllers.setEntityControllerForType(EntityType.EGG, EggController.class); + EntityControllers.setEntityControllerForType(EntityType.ENDER_CRYSTAL, EnderCrystalController.class); + EntityControllers.setEntityControllerForType(EntityType.ENDER_DRAGON, EnderDragonController.class); + EntityControllers.setEntityControllerForType(EntityType.ENDER_PEARL, EnderPearlController.class); + EntityControllers.setEntityControllerForType(EntityType.ENDER_SIGNAL, EnderSignalController.class); + EntityControllers.setEntityControllerForType(EntityType.ENDERMAN, EndermanController.class); + EntityControllers.setEntityControllerForType(EntityType.ENDERMITE, EndermiteController.class); + EntityControllers.setEntityControllerForType(EntityType.FALLING_BLOCK, FallingBlockController.class); + EntityControllers.setEntityControllerForType(EntityType.FIREWORK, FireworkController.class); + EntityControllers.setEntityControllerForType(EntityType.FIREBALL, LargeFireballController.class); + EntityControllers.setEntityControllerForType(EntityType.FISHING_HOOK, FishingHookController.class); + EntityControllers.setEntityControllerForType(EntityType.GHAST, GhastController.class); + EntityControllers.setEntityControllerForType(EntityType.GIANT, GiantController.class); + EntityControllers.setEntityControllerForType(EntityType.GUARDIAN, GuardianController.class); + EntityControllers.setEntityControllerForType(EntityType.HORSE, HorseController.class); + EntityControllers.setEntityControllerForType(EntityType.IRON_GOLEM, IronGolemController.class); + EntityControllers.setEntityControllerForType(EntityType.ITEM_FRAME, ItemFrameController.class); + EntityControllers.setEntityControllerForType(EntityType.LEASH_HITCH, LeashController.class); + EntityControllers.setEntityControllerForType(EntityType.MAGMA_CUBE, MagmaCubeController.class); + EntityControllers.setEntityControllerForType(EntityType.MINECART, MinecartRideableController.class); + EntityControllers.setEntityControllerForType(EntityType.MINECART_CHEST, MinecartChestController.class); + EntityControllers.setEntityControllerForType(EntityType.MINECART_COMMAND, MinecartCommandController.class); + EntityControllers.setEntityControllerForType(EntityType.MINECART_FURNACE, MinecartFurnaceController.class); + EntityControllers.setEntityControllerForType(EntityType.MINECART_HOPPER, MinecartHopperController.class); + EntityControllers.setEntityControllerForType(EntityType.MINECART_TNT, MinecartTNTController.class); + EntityControllers.setEntityControllerForType(EntityType.MUSHROOM_COW, MushroomCowController.class); + EntityControllers.setEntityControllerForType(EntityType.OCELOT, OcelotController.class); + EntityControllers.setEntityControllerForType(EntityType.PAINTING, PaintingController.class); + EntityControllers.setEntityControllerForType(EntityType.PIG, PigController.class); + EntityControllers.setEntityControllerForType(EntityType.PIG_ZOMBIE, PigZombieController.class); + EntityControllers.setEntityControllerForType(EntityType.PLAYER, HumanController.class); + EntityControllers.setEntityControllerForType(EntityType.RABBIT, RabbitController.class); + EntityControllers.setEntityControllerForType(EntityType.SHEEP, SheepController.class); + EntityControllers.setEntityControllerForType(EntityType.SILVERFISH, SilverfishController.class); + EntityControllers.setEntityControllerForType(EntityType.SKELETON, SkeletonController.class); + EntityControllers.setEntityControllerForType(EntityType.SLIME, SlimeController.class); + EntityControllers.setEntityControllerForType(EntityType.SMALL_FIREBALL, SmallFireballController.class); + EntityControllers.setEntityControllerForType(EntityType.SNOWBALL, SnowballController.class); + EntityControllers.setEntityControllerForType(EntityType.SNOWMAN, SnowmanController.class); + EntityControllers.setEntityControllerForType(EntityType.SPIDER, SpiderController.class); + EntityControllers.setEntityControllerForType(EntityType.SQUID, SquidController.class); + EntityControllers.setEntityControllerForType(EntityType.THROWN_EXP_BOTTLE, ThrownExpBottleController.class); + EntityControllers.setEntityControllerForType(EntityType.PRIMED_TNT, TNTPrimedController.class); + EntityControllers.setEntityControllerForType(EntityType.VILLAGER, VillagerController.class); + EntityControllers.setEntityControllerForType(EntityType.WOLF, WolfController.class); + EntityControllers.setEntityControllerForType(EntityType.WITCH, WitchController.class); + EntityControllers.setEntityControllerForType(EntityType.WITHER, WitherController.class); + EntityControllers.setEntityControllerForType(EntityType.WITHER_SKULL, WitherSkullController.class); + EntityControllers.setEntityControllerForType(EntityType.ZOMBIE, ZombieController.class); + } + + @Override + public void loadPlugins() { + ((CraftServer) Bukkit.getServer()).enablePlugins(PluginLoadOrder.POSTWORLD); + } + + @Override + public void look(org.bukkit.entity.Entity entity, float yaw, float pitch) { + Entity handle = NMSImpl.getHandle(entity); + if (handle == null) + return; + yaw = Util.clampYaw(yaw); + handle.yaw = yaw; + setHeadYaw(entity, yaw); + handle.pitch = pitch; + } + + @Override + public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, boolean immediate) { + Entity handle = NMSImpl.getHandle(entity); + if (immediate || headOnly || BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType()) + || (!(handle instanceof EntityInsentient) && !(handle instanceof EntityHumanNPC))) { + Location fromLocation = entity.getLocation(FROM_LOCATION); + double xDiff, yDiff, zDiff; + xDiff = to.getX() - fromLocation.getX(); + yDiff = to.getY() - fromLocation.getY(); + zDiff = to.getZ() - fromLocation.getZ(); + + double distanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff); + double distanceY = Math.sqrt(distanceXZ * distanceXZ + yDiff * yDiff); + + double yaw = Math.toDegrees(Math.acos(xDiff / distanceXZ)); + double pitch = Math.toDegrees(Math.acos(yDiff / distanceY)) - 90; + if (zDiff < 0.0) + yaw += Math.abs(180 - yaw) * 2; + if (handle instanceof EntityEnderDragon) { + yaw = getDragonYaw(handle, to.getX(), to.getZ()); + } else { + yaw = yaw - 90; + } + if (headOnly) { + setHeadYaw(entity, (float) yaw); + } else { + look(entity, (float) yaw, (float) pitch); + } + return; + } + if (handle instanceof EntityInsentient) { + ((EntityInsentient) handle).getControllerLook().a(to.getX(), to.getY(), to.getZ(), 10, + ((EntityInsentient) handle).bQ()); + while (((EntityInsentient) handle).aK >= 180F) { + ((EntityInsentient) handle).aK -= 360F; + } + while (((EntityInsentient) handle).aK < -180F) { + ((EntityInsentient) handle).aK += 360F; + } + } else if (handle instanceof EntityHumanNPC) { + ((EntityHumanNPC) handle).setTargetLook(to); + } + } + + @Override + public void look(org.bukkit.entity.Entity from, org.bukkit.entity.Entity to) { + Entity handle = NMSImpl.getHandle(from), target = NMSImpl.getHandle(to); + if (BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType())) { + if (to instanceof LivingEntity) { + look(from, ((LivingEntity) to).getEyeLocation(), false, true); + } else { + look(from, to.getLocation(), false, true); + } + } else if (handle instanceof EntityInsentient) { + ((EntityInsentient) handle).getControllerLook().a(target, 10, ((EntityInsentient) handle).bQ()); + while (((EntityLiving) handle).aK >= 180F) { + ((EntityLiving) handle).aK -= 360F; + } + while (((EntityLiving) handle).aK < -180F) { + ((EntityLiving) handle).aK += 360F; + } + } else if (handle instanceof EntityHumanNPC) { + ((EntityHumanNPC) handle).setTargetLook(target, 10F, 40F); + } + } + + @Override + public void mount(org.bukkit.entity.Entity entity, org.bukkit.entity.Entity passenger) { + if (NMSImpl.getHandle(passenger) == null) + return; + NMSImpl.getHandle(passenger).mount(NMSImpl.getHandle(entity)); + } + + @Override + public void openHorseScreen(Tameable horse, Player equipper) { + EntityLiving handle = NMSImpl.getHandle((LivingEntity) horse); + EntityLiving equipperHandle = NMSImpl.getHandle(equipper); + if (handle == null || equipperHandle == null) + return; + boolean wasTamed = horse.isTamed(); + horse.setTamed(true); + ((EntityHorse) handle).g((EntityHuman) equipperHandle); + horse.setTamed(wasTamed); + } + + @Override + public void playAnimation(PlayerAnimation animation, Player player, int radius) { + PlayerAnimationImpl.play(animation, player, radius); + } + + @Override + public void registerEntityClass(Class clazz) { + if (ENTITY_CLASS_TO_INT == null || ENTITY_CLASS_TO_INT.containsKey(clazz)) + return; + Class search = clazz; + while ((search = search.getSuperclass()) != null && Entity.class.isAssignableFrom(search)) { + if (!ENTITY_CLASS_TO_INT.containsKey(search)) + continue; + int code = ENTITY_CLASS_TO_INT.get(search); + ENTITY_CLASS_TO_INT.put(clazz, code); + ENTITY_CLASS_TO_NAME.put(clazz, ENTITY_CLASS_TO_NAME.get(search)); + return; + } + throw new IllegalArgumentException("unable to find valid entity superclass for class " + clazz.toString()); + } + + @Override + public void removeFromServerPlayerList(Player player) { + EntityPlayer handle = (EntityPlayer) NMSImpl.getHandle(player); + ((CraftServer) Bukkit.getServer()).getHandle().players.remove(handle); + } + + @Override + public void removeFromWorld(org.bukkit.entity.Entity entity) { + Preconditions.checkNotNull(entity); + + Entity nmsEntity = ((CraftEntity) entity).getHandle(); + nmsEntity.world.removeEntity(nmsEntity); + } + + @Override + public void removeHookIfNecessary(NPCRegistry npcRegistry, FishHook entity) { + EntityFishingHook hook = (EntityFishingHook) NMSImpl.getHandle(entity); + if (hook.hooked == null) + return; + NPC npc = npcRegistry.getNPC(hook.hooked.getBukkitEntity()); + if (npc == null) + return; + if (npc.isProtected()) { + hook.hooked = null; + hook.die(); + } + } + + @Override + public void replaceTrackerEntry(Player player) { + WorldServer server = (WorldServer) NMSImpl.getHandle(player).getWorld(); + EntityTrackerEntry entry = server.getTracker().trackedEntities.get(player.getEntityId()); + if (entry == null) + return; + PlayerlistTrackerEntry replace = new PlayerlistTrackerEntry(entry); + server.getTracker().trackedEntities.a(player.getEntityId(), replace); + if (TRACKED_ENTITY_SET != null) { + try { + Set set = (Set) TRACKED_ENTITY_SET.get(server.getTracker()); + set.remove(entry); + set.add(replace); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + } + + @Override + public void sendPositionUpdate(Player excluding, org.bukkit.entity.Entity from, Location storedLocation) { + sendPacketNearby(excluding, storedLocation, new PacketPlayOutEntityTeleport(getHandle(from))); + } + + @Override + public void sendTabListAdd(Player recipient, Player listPlayer) { + Preconditions.checkNotNull(recipient); + Preconditions.checkNotNull(listPlayer); + + EntityPlayer entity = ((CraftPlayer) listPlayer).getHandle(); + + NMSImpl.sendPacket(recipient, + new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entity)); + } + + @Override + public void sendTabListRemove(Player recipient, Collection skinnableNPCs) { + Preconditions.checkNotNull(recipient); + Preconditions.checkNotNull(skinnableNPCs); + + EntityPlayer[] entities = new EntityPlayer[skinnableNPCs.size()]; + int i = 0; + for (SkinnableEntity skinnable : skinnableNPCs) { + entities[i] = (EntityPlayer) skinnable; + i++; + } + + NMSImpl.sendPacket(recipient, + new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entities)); + } + + @Override + public void sendTabListRemove(Player recipient, Player listPlayer) { + Preconditions.checkNotNull(recipient); + Preconditions.checkNotNull(listPlayer); + + EntityPlayer entity = ((CraftPlayer) listPlayer).getHandle(); + + NMSImpl.sendPacket(recipient, + new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entity)); + } + + @Override + public void setDestination(org.bukkit.entity.Entity entity, double x, double y, double z, float speed) { + Entity handle = NMSImpl.getHandle(entity); + if (handle == null) + return; + if (handle instanceof EntityInsentient) { + ((EntityInsentient) handle).getControllerMove().a(x, y, z, speed); + } else if (handle instanceof EntityHumanNPC) { + ((EntityHumanNPC) handle).setMoveDestination(x, y, z, speed); + } + } + + @Override + public void setDummyAdvancement(Player entity) { + } + + @Override + public void setHeadYaw(org.bukkit.entity.Entity entity, float yaw) { + if (!(entity instanceof LivingEntity)) + return; + EntityLiving handle = (EntityLiving) getHandle(entity); + yaw = Util.clampYaw(yaw); + handle.aJ = yaw; + if (!(handle instanceof EntityHuman)) + handle.aI = yaw; + handle.aK = yaw; + } + + @Override + public void setKnockbackResistance(LivingEntity entity, double d) { + EntityLiving handle = NMSImpl.getHandle(entity); + handle.getAttributeInstance(GenericAttributes.c).setValue(d); + } + + @Override + public void setNavigationTarget(org.bukkit.entity.Entity handle, org.bukkit.entity.Entity target, float speed) { + NMSImpl.getNavigation(handle).a(NMSImpl.getHandle(target), speed); + } + + @Override + public void setProfile(SkullMeta meta, GameProfile profile) { + if (SKULL_PROFILE_FIELD == null) { + try { + SKULL_PROFILE_FIELD = meta.getClass().getDeclaredField("profile"); + SKULL_PROFILE_FIELD.setAccessible(true); + } catch (Exception e) { + return; + } + } + try { + SKULL_PROFILE_FIELD.set(meta, profile); + } catch (Exception e) { + } + } + + @Override + public void setShouldJump(org.bukkit.entity.Entity entity) { + Entity handle = NMSImpl.getHandle(entity); + if (handle == null) + return; + if (handle instanceof EntityInsentient) { + ControllerJump controller = ((EntityInsentient) handle).getControllerJump(); + controller.a(); + } else if (handle instanceof EntityHumanNPC) { + ((EntityHumanNPC) handle).setShouldJump(); + } + } + + @Override + public void setSitting(Tameable tameable, boolean sitting) { + ((EntityTameableAnimal) NMSImpl.getHandle((LivingEntity) tameable)).setSitting(sitting); + } + + @Override + public void setStepHeight(org.bukkit.entity.Entity entity, float height) { + NMSImpl.getHandle(entity).S = height; + } + + @Override + public void setVerticalMovement(org.bukkit.entity.Entity bukkitEntity, double d) { + if (!bukkitEntity.getType().isAlive()) + return; + EntityLiving handle = NMSImpl.getHandle((LivingEntity) bukkitEntity); + handle.aZ = (float) d; + } + + @Override + public void setWitherCharged(Wither wither, boolean charged) { + EntityWither handle = ((CraftWither) wither).getHandle(); + handle.r(charged ? 20 : 0); + } + + @Override + public boolean shouldJump(org.bukkit.entity.Entity entity) { + if (JUMP_FIELD == null || !(entity instanceof LivingEntity)) + return false; + try { + return JUMP_FIELD.getBoolean(NMSImpl.getHandle(entity)); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return false; + } + + @Override + public void shutdown() { + } + + @Override + public boolean tick(org.bukkit.entity.Entity next) { + Entity entity = NMSImpl.getHandle(next); + if (!entity.dead) { + try { + entity.world.g(entity); + } catch (Throwable throwable) { + CrashReport crashreport = CrashReport.a(throwable, "Ticking player"); + CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Player being ticked"); + + entity.appendEntityCrashDetails(crashreportsystemdetails); + throw new ReportedException(crashreport); + } + } + boolean removeFromPlayerList = ((NPCHolder) entity).getNPC().data().get("removefromplayerlist", + Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()); + if (entity.dead) { + entity.world.removeEntity(entity); + return true; + } else if (!removeFromPlayerList) { + if (!entity.world.players.contains(entity)) { + entity.world.players.add((EntityHuman) entity); + } + return true; + } else { + entity.world.players.remove(entity); + } + + return false; + } + + @Override + public void trySwim(org.bukkit.entity.Entity entity) { + trySwim(entity, 0.04F); + } + + @Override + public void trySwim(org.bukkit.entity.Entity entity, float power) { + Entity handle = NMSImpl.getHandle(entity); + if (handle == null) + return; + if (RANDOM.nextFloat() < 0.8F && (handle.W() || handle.ab())) { + handle.motY += power; + } + } + + @Override + public void updateNavigationWorld(org.bukkit.entity.Entity entity, World world) { + if (NAVIGATION_WORLD_FIELD == null) + return; + Entity en = NMSImpl.getHandle(entity); + if (en == null || !(en instanceof EntityInsentient)) + return; + EntityInsentient handle = (EntityInsentient) en; + WorldServer worldHandle = ((CraftWorld) world).getHandle(); + try { + NAVIGATION_WORLD_FIELD.set(handle.getNavigation(), worldHandle); + } catch (Exception e) { + Messaging.logTr(Messages.ERROR_UPDATING_NAVIGATION_WORLD, e.getMessage()); + } + } + + @Override + public void updatePathfindingRange(NPC npc, float pathfindingRange) { + if (!npc.isSpawned() || !npc.getEntity().getType().isAlive()) + return; + EntityLiving en = NMSImpl.getHandle((LivingEntity) npc.getEntity()); + if (!(en instanceof EntityInsentient)) { + if (en instanceof EntityHumanNPC) { + ((EntityHumanNPC) en).updatePathfindingRange(pathfindingRange); + } + return; + } + if (PATHFINDING_RANGE == null) + return; + EntityInsentient handle = (EntityInsentient) en; + NavigationAbstract navigation = handle.getNavigation(); + try { + AttributeInstance inst = (AttributeInstance) PATHFINDING_RANGE.get(navigation); + inst.setValue(pathfindingRange); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + + private static class NavigationFieldWrapper implements TargetNavigator { + private final NavigationAbstract navigation; + private final NavigatorParameters parameters; + private final org.bukkit.entity.Entity target; + + private NavigationFieldWrapper(NavigationAbstract navigation, org.bukkit.entity.Entity target, + NavigatorParameters parameters) { + this.navigation = navigation; + this.target = target; + this.parameters = parameters; + } + + @Override + public Iterable getPath() { + return new NavigationIterable(navigation); + } + + @Override + public void setPath() { + Location location = parameters.entityTargetLocationMapper().apply(target); + if (location == null) { + throw new IllegalStateException("mapper should not return null"); + } + navigation.a(location.getX(), location.getY(), location.getZ(), parameters.speed()); + } + + @Override + public void stop() { + stopNavigation(navigation); + } + + @Override + public void update() { + updateNavigation(navigation); + }; + } + + private static class NavigationIterable implements Iterable { + private final NavigationAbstract navigation; + + public NavigationIterable(NavigationAbstract nav) { + this.navigation = nav; + } + + @Override + public Iterator iterator() { + final int npoints = navigation.j() == null ? 0 : navigation.j().d(); + return new Iterator() { + PathPoint curr = npoints > 0 ? navigation.j().a(0) : null; + int i = 0; + + @Override + public boolean hasNext() { + return curr != null; + } + + @Override + public Vector next() { + PathPoint old = curr; + curr = i + 1 < npoints ? navigation.j().a(++i) : null; + return new Vector(old.a, old.b, old.c); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + } + + public static void clearGoals(PathfinderGoalSelector... goalSelectors) { + if (GOAL_FIELD == null || goalSelectors == null) + return; + for (PathfinderGoalSelector selector : goalSelectors) { + try { + Collection list = (Collection) GOAL_FIELD.get(selector); + list.clear(); + } catch (Exception e) { + Messaging.logTr(Messages.ERROR_CLEARING_GOALS, e.getLocalizedMessage()); + } + } + } + + public static void flyingMoveLogic(EntityLiving entity, float f, float f1) { + if (entity.bM()) { + if ((entity.V())) { + double d0 = entity.locY; + float f3 = 0.8F; + float f4 = 0.02F; + float f2 = EnchantmentManager.b(entity); + if (f2 > 3.0F) { + f2 = 3.0F; + } + if (!entity.onGround) { + f2 *= 0.5F; + } + if (f2 > 0.0F) { + f3 += (0.54600006F - f3) * f2 / 3.0F; + f4 += (entity.bI() * 1.0F - f4) * f2 / 3.0F; + } + entity.a(f, f1, f4); + entity.move(entity.motX, entity.motY, entity.motZ); + entity.motX *= f3; + entity.motY *= 0.800000011920929D; + entity.motZ *= f3; + entity.motY -= 0.02D; + if ((entity.positionChanged) + && (entity.c(entity.motX, entity.motY + 0.6000000238418579D - entity.locY + d0, entity.motZ))) { + entity.motY = 0.30000001192092896D; + } + } else if ((entity.ab())) { + double d0 = entity.locY; + entity.a(f, f1, 0.02F); + entity.move(entity.motX, entity.motY, entity.motZ); + entity.motX *= 0.5D; + entity.motY *= 0.5D; + entity.motZ *= 0.5D; + entity.motY -= 0.02D; + if ((entity.positionChanged) + && (entity.c(entity.motX, entity.motY + 0.6000000238418579D - entity.locY + d0, entity.motZ))) { + entity.motY = 0.30000001192092896D; + } + } else { + float f5 = 0.91F; + if (entity.onGround) { + f5 = entity.world + .getType(new BlockPosition(MathHelper.floor(entity.locX), + MathHelper.floor(entity.getBoundingBox().b) - 1, MathHelper.floor(entity.locZ))) + .getBlock().frictionFactor * 0.91F; + } + float f6 = 0.16277136F / (f5 * f5 * f5); + float f3; + if (entity.onGround) { + f3 = entity.bI() * f6; + } else { + f3 = entity.aM; + } + entity.a(f, f1, f3); + f5 = 0.91F; + if (entity.onGround) { + f5 = entity.world + .getType(new BlockPosition(MathHelper.floor(entity.locX), + MathHelper.floor(entity.getBoundingBox().b) - 1, MathHelper.floor(entity.locZ))) + .getBlock().frictionFactor * 0.91F; + } + if (entity.k_()) { + float f4 = 0.15F; + entity.motX = MathHelper.a(entity.motX, -f4, f4); + entity.motZ = MathHelper.a(entity.motZ, -f4, f4); + entity.fallDistance = 0.0F; + if (entity.motY < -0.15D) { + entity.motY = -0.15D; + } + boolean flag = (entity.isSneaking()) && ((entity instanceof EntityHuman)); + if ((flag) && (entity.motY < 0.0D)) { + entity.motY = 0.0D; + } + } + entity.move(entity.motX, entity.motY, entity.motZ); + if ((entity.positionChanged) && (entity.k_())) { + entity.motY = 0.2D; + } + if ((entity.world.isClientSide) && ((!entity.world + .isLoaded(new BlockPosition((int) entity.locX, 0, (int) entity.locZ))) + || (!entity.world + .getChunkAtWorldCoords(new BlockPosition((int) entity.locX, 0, (int) entity.locZ)) + .o()))) { + if (entity.locY > 0.0D) { + entity.motY = -0.1D; + } else { + entity.motY = 0.0D; + } + } else { + entity.motY -= 0.08D; + } + entity.motY *= 0.9800000190734863D; + entity.motX *= f5; + entity.motZ *= f5; + } + } + entity.aA = entity.aB; + double d0 = entity.locX - entity.lastX; + double d1 = entity.locZ - entity.lastZ; + + float f2 = MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0F; + if (f2 > 1.0F) { + f2 = 1.0F; + } + entity.aB += (f2 - entity.aB) * 0.4F; + entity.aC += entity.aB; + } + + private static EntityLiving getHandle(LivingEntity entity) { + return (EntityLiving) NMSImpl.getHandle((org.bukkit.entity.Entity) entity); + } + + public static Entity getHandle(org.bukkit.entity.Entity entity) { + if (!(entity instanceof CraftEntity)) + return null; + return ((CraftEntity) entity).getHandle(); + } + + public static float getHeadYaw(EntityLiving handle) { + return handle.aJ; + } + + public static NavigationAbstract getNavigation(org.bukkit.entity.Entity entity) { + Entity handle = getHandle(entity); + return handle instanceof EntityInsentient ? ((EntityInsentient) handle).getNavigation() + : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getNavigation() : null; + } + + public static String getSoundEffect(NPC npc, String snd, String meta) { + return npc == null || !npc.data().has(meta) ? snd : npc.data().get(meta, snd == null ? "" : snd.toString()); + } + + public static void initNetworkManager(NetworkManager network) { + if (NETWORK_ADDRESS == null) + return; + try { + network.channel = new EmptyChannel(null); + NETWORK_ADDRESS.set(network, new SocketAddress() { + private static final long serialVersionUID = 8207338859896320185L; + }); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + + public static boolean isNavigationFinished(NavigationAbstract navigation) { + return navigation.m(); + } + + @SuppressWarnings("deprecation") + public static void minecartItemLogic(EntityMinecartAbstract minecart) { + NPC npc = ((NPCHolder) minecart).getNPC(); + if (npc == null) + return; + Material mat = Material.getMaterial(npc.data().get(NPC.MINECART_ITEM_METADATA, "")); + int data = npc.data().get(NPC.MINECART_ITEM_DATA_METADATA, 0); + int offset = npc.data().get(NPC.MINECART_OFFSET_METADATA, 0); + minecart.a(mat != null); + if (mat != null) { + minecart.setDisplayBlock(Block.getById(mat.getId()).fromLegacyData(data)); + } + minecart.SetDisplayBlockOffset(offset); + } + + public static void sendPacket(Player player, Packet packet) { + if (packet == null) + return; + ((EntityPlayer) NMSImpl.getHandle(player)).playerConnection.sendPacket(packet); + } + + public static void sendPacketNearby(Player from, Location location, Packet packet) { + sendPacketNearby(from, location, packet, 64); + } + + public static void sendPacketNearby(Player from, Location location, Packet packet, double radius) { + List> list = new ArrayList>(); + list.add(packet); + sendPacketsNearby(from, location, list, radius); + } + + public static void sendPacketsNearby(Player from, Location location, Collection> packets, double radius) { + radius *= radius; + final org.bukkit.World world = location.getWorld(); + for (Player ply : Bukkit.getServer().getOnlinePlayers()) { + if (ply == null || world != ply.getWorld() || (from != null && !ply.canSee(from))) { + continue; + } + if (location.distanceSquared(ply.getLocation(PACKET_CACHE_LOCATION)) > radius) { + continue; + } + for (Packet packet : packets) { + NMSImpl.sendPacket(ply, packet); + } + } + } + + public static void sendPacketsNearby(Player from, Location location, Packet... packets) { + NMSImpl.sendPacketsNearby(from, location, Arrays.asList(packets), 64); + } + + public static void setSize(Entity entity, float f, float f1, boolean justCreated) { + if ((f != entity.width) || (f1 != entity.length)) { + float f2 = entity.width; + + entity.width = f; + entity.length = f1; + entity.a(new AxisAlignedBB(entity.getBoundingBox().a, entity.getBoundingBox().b, entity.getBoundingBox().c, + entity.getBoundingBox().a + entity.width, entity.getBoundingBox().b + entity.length, + entity.getBoundingBox().c + entity.width)); + if ((entity.width > f2) && (!justCreated) && (!entity.world.isClientSide)) + entity.move((f2 - entity.width) / 2, 0.0D, (f2 - entity.width) / 2); + } + } + + public static void stopNavigation(NavigationAbstract navigation) { + navigation.n(); + } + + public static void updateAI(EntityLiving entity) { + if (entity instanceof EntityInsentient) { + EntityInsentient handle = (EntityInsentient) entity; + handle.getEntitySenses().a(); + NMSImpl.updateNavigation(handle.getNavigation()); + handle.getControllerMove().c(); + handle.getControllerLook().a(); + handle.getControllerJump().b(); + } else if (entity instanceof EntityHumanNPC) { + ((EntityHumanNPC) entity).updateAI(); + } + } + + public static void updateNavigation(NavigationAbstract navigation) { + navigation.k(); + } + + private static final Set BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.SILVERFISH, EntityType.ENDERMITE, + EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.MAGMA_CUBE, EntityType.HORSE, + EntityType.GHAST); + private static final float DEFAULT_SPEED = 1F; + private static Map, Integer> ENTITY_CLASS_TO_INT; + private static Map, String> ENTITY_CLASS_TO_NAME; + private static final Location FROM_LOCATION = new Location(null, 0, 0, 0); + public static Field GOAL_FIELD = NMS.getField(PathfinderGoalSelector.class, "b"); + private static final Field JUMP_FIELD = NMS.getField(EntityLiving.class, "aY"); + private static Method MAKE_REQUEST; + private static Field NAVIGATION_WORLD_FIELD = NMS.getField(NavigationAbstract.class, "c"); + public static Field NETWORK_ADDRESS = NMS.getField(NetworkManager.class, "l"); + public static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0); + private static Field PATHFINDING_RANGE = NMS.getField(NavigationAbstract.class, "a"); + private static final Random RANDOM = Util.getFastRandom(); + private static Field SKULL_PROFILE_FIELD; + private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c"); + + static { + try { + Field field = NMS.getField(EntityTypes.class, "f"); + ENTITY_CLASS_TO_INT = (Map, Integer>) field.get(null); + field = NMS.getField(EntityTypes.class, "d"); + ENTITY_CLASS_TO_NAME = (Map, String>) field.get(null); + } catch (Exception e) { + Messaging.logTr(Messages.ERROR_GETTING_ID_MAPPING, e.getMessage()); + } + + try { + MAKE_REQUEST = YggdrasilAuthenticationService.class.getDeclaredMethod("makeRequest", URL.class, + Object.class, Class.class); + MAKE_REQUEST.setAccessible(true); + } catch (Exception ex) { + ex.printStackTrace(); + } + } +} diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerAnimationImpl.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerAnimationImpl.java new file mode 100644 index 000000000..9f9fdb722 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerAnimationImpl.java @@ -0,0 +1,119 @@ +package net.citizensnpcs.nms.v1_8_R3.util; + +import java.util.EnumMap; + +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.scheduler.BukkitRunnable; + +import com.google.common.collect.Maps; + +import net.citizensnpcs.api.CitizensAPI; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.npc.ai.NPCHolder; +import net.citizensnpcs.trait.ArmorStandTrait; +import net.citizensnpcs.util.NMS; +import net.citizensnpcs.util.PlayerAnimation; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityPlayer; +import net.minecraft.server.v1_8_R3.Packet; +import net.minecraft.server.v1_8_R3.PacketPlayOutAnimation; +import net.minecraft.server.v1_8_R3.PacketPlayOutBed; +import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata; + +public class PlayerAnimationImpl { + public static void play(PlayerAnimation animation, Player bplayer, int radius) { + // TODO: this is pretty gross + final EntityPlayer player = (EntityPlayer) NMSImpl.getHandle(bplayer); + if (DEFAULTS.containsKey(animation)) { + playDefaultAnimation(player, radius, DEFAULTS.get(animation)); + return; + } + switch (animation) { + case SIT: + player.getBukkitEntity().setMetadata("citizens.sitting", + new FixedMetadataValue(CitizensAPI.getPlugin(), true)); + final NPC holder = CitizensAPI.getNPCRegistry().createNPC(EntityType.ARMOR_STAND, ""); + holder.spawn(player.getBukkitEntity().getLocation()); + ArmorStandTrait trait = holder.getTrait(ArmorStandTrait.class); + trait.setGravity(false); + trait.setHasArms(false); + trait.setHasBaseplate(false); + trait.setSmall(true); + trait.setMarker(true); + trait.setVisible(false); + holder.getTrait(ArmorStandTrait.class).setVisible(false); + holder.data().set(NPC.NAMEPLATE_VISIBLE_METADATA, false); + holder.data().set(NPC.DEFAULT_PROTECTED_METADATA, true); + new BukkitRunnable() { + @Override + public void cancel() { + super.cancel(); + holder.destroy(); + } + + @Override + public void run() { + if (player.dead || !player.valid + || !player.getBukkitEntity().getMetadata("citizens.sitting").get(0).asBoolean()) { + cancel(); + return; + } + if (player instanceof NPCHolder && !((NPCHolder) player).getNPC().isSpawned()) { + cancel(); + return; + } + if (!NMS.getPassengers(holder.getEntity()).contains(player.getBukkitEntity())) { + NMS.mount(holder.getEntity(), player.getBukkitEntity()); + } + } + }.runTaskTimer(CitizensAPI.getPlugin(), 0, 1); + break; + case SLEEP: + PacketPlayOutBed packet = new PacketPlayOutBed(player, + new BlockPosition((int) player.locX, (int) player.locY, (int) player.locZ)); + sendPacketNearby(packet, player, radius); + break; + case SNEAK: + player.getBukkitEntity().setSneaking(true); + sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, + radius); + break; + case STOP_SITTING: + player.getBukkitEntity().setMetadata("citizens.sitting", + new FixedMetadataValue(CitizensAPI.getPlugin(), false)); + NMS.mount(player.getBukkitEntity(), null); + break; + case STOP_SLEEPING: + playDefaultAnimation(player, radius, 2); + break; + case STOP_SNEAKING: + player.getBukkitEntity().setSneaking(false); + sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, + radius); + break; + default: + throw new UnsupportedOperationException(); + } + } + + protected static void playDefaultAnimation(EntityPlayer player, int radius, int code) { + PacketPlayOutAnimation packet = new PacketPlayOutAnimation(player, code); + sendPacketNearby(packet, player, radius); + } + + protected static void sendPacketNearby(Packet packet, EntityPlayer player, int radius) { + NMSImpl.sendPacketNearby(player.getBukkitEntity(), player.getBukkitEntity().getLocation(), packet, radius); + } + + private static EnumMap DEFAULTS = Maps.newEnumMap(PlayerAnimation.class); + static { + DEFAULTS.put(PlayerAnimation.ARM_SWING, 0); + DEFAULTS.put(PlayerAnimation.HURT, 1); + DEFAULTS.put(PlayerAnimation.EAT_FOOD, 2); + DEFAULTS.put(PlayerAnimation.ARM_SWING_OFFHAND, 3); + DEFAULTS.put(PlayerAnimation.CRIT, 4); + DEFAULTS.put(PlayerAnimation.MAGIC_CRIT, 5); + } +} diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerControllerJump.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerControllerJump.java new file mode 100644 index 000000000..9ab9e16af --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerControllerJump.java @@ -0,0 +1,21 @@ +package net.citizensnpcs.nms.v1_8_R3.util; + +import net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC; + +public class PlayerControllerJump { + private final EntityHumanNPC a; + private boolean b; + + public PlayerControllerJump(EntityHumanNPC entityinsentient) { + this.a = entityinsentient; + } + + public void a() { + this.b = true; + } + + public void b() { + this.a.i(this.b); + this.b = false; + } +} diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerControllerLook.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerControllerLook.java new file mode 100644 index 000000000..3df02e12e --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerControllerLook.java @@ -0,0 +1,110 @@ +package net.citizensnpcs.nms.v1_8_R3.util; + +import net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC; +import net.minecraft.server.v1_8_R3.Entity; +import net.minecraft.server.v1_8_R3.EntityLiving; +import net.minecraft.server.v1_8_R3.MathHelper; + +public class PlayerControllerLook { + private final EntityHumanNPC a; + private float b; + private float c; + private boolean d; + private double e; + private double f; + private double g; + + public PlayerControllerLook(EntityHumanNPC entityinsentient) { + this.a = entityinsentient; + } + + public void a() { + if (!NMSImpl.isNavigationFinished(this.a.getNavigation())) + return; + this.a.pitch = 0.0F; + if (this.d) { + this.d = false; + + double d1 = this.e - this.a.locX; + double d2 = this.f - (this.a.locY + this.a.getHeadHeight()); + double d3 = this.g - this.a.locZ; + double d4 = MathHelper.sqrt(d1 * d1 + d3 * d3); + + float f1 = (float) (MathHelper.b(d3, d1) * 57.2957763671875D) - 90.0F; + float f2 = (float) -(MathHelper.b(d2, d4) * 57.2957763671875D); + this.a.pitch = a(this.a.pitch, f2, this.c); + this.a.aK = a(this.a.aK, f1, this.b); + this.a.yaw = this.a.aK; + while (this.a.aK >= 180F) { + this.a.aK -= 360F; + } + while (this.a.aK < -180F) { + this.a.aK += 360F; + } + } else { + // this.a.aQ = a(this.a.aQ, this.a.aO, 10.0F); + } + float f3 = MathHelper.g(this.a.aK - this.a.aI); + if (!this.a.getNavigation().m()) { + if (f3 < -75.0F) { + this.a.aK = (this.a.aI - 75.0F); + } + if (f3 > 75.0F) { + this.a.aK = (this.a.aI + 75.0F); + } + } + } + + public void a(double d0, double d1, double d2, float f, float f1) { + this.e = d0; + this.f = d1; + this.g = d2; + this.b = f; + this.c = f1; + this.d = true; + } + + public void a(Entity entity, float f, float f1) { + this.e = entity.locX; + if ((entity instanceof EntityLiving)) + this.f = (entity.locY + entity.getHeadHeight()); + else { + this.f = ((entity.getBoundingBox().b + entity.getBoundingBox().e) / 2.0D); + } + + this.g = entity.locZ; + this.b = f; + this.c = f1; + this.d = true; + } + + private float a(float f, float f1, float f2) { + float f3 = MathHelper.g(f1 - f); + + if (f3 > f2) { + f3 = f2; + } + + if (f3 < -f2) { + f3 = -f2; + } + + return f + f3; + } + + public boolean b() { + return this.d; + } + + public double e() { + return this.e; + } + + public double f() { + return this.f; + } + + public double g() { + return this.g; + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerControllerMove.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerControllerMove.java new file mode 100644 index 000000000..19cb6dba4 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerControllerMove.java @@ -0,0 +1,134 @@ +package net.citizensnpcs.nms.v1_8_R3.util; + +import java.util.Random; + +import net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC; +import net.citizensnpcs.util.NMS; +import net.minecraft.server.v1_8_R3.AttributeInstance; +import net.minecraft.server.v1_8_R3.ControllerMove; +import net.minecraft.server.v1_8_R3.EntityInsentient; +import net.minecraft.server.v1_8_R3.EntityLiving; +import net.minecraft.server.v1_8_R3.EntitySlime; +import net.minecraft.server.v1_8_R3.GenericAttributes; +import net.minecraft.server.v1_8_R3.MathHelper; + +public class PlayerControllerMove extends ControllerMove { + protected EntityLiving a; + protected double b; + protected double c; + protected double d; + protected double e; + protected boolean f; + private int h; + + public PlayerControllerMove(EntityLiving entityinsentient) { + super(entityinsentient instanceof EntityInsentient ? (EntityInsentient) entityinsentient + : new EntitySlime(entityinsentient.world)); + this.a = entityinsentient; + this.b = entityinsentient.locX; + this.c = entityinsentient.locY; + this.d = entityinsentient.locZ; + } + + @Override + public boolean a() { + return this.f; + } + + @Override + public void a(double d0, double d1, double d2, double d3) { + this.b = d0; + this.c = d1; + this.d = d2; + this.e = d3; + this.f = true; + } + + @Override + protected float a(float f, float f1, float f2) { + float f3 = MathHelper.g(f1 - f); + + if (f3 > f2) { + f3 = f2; + } + + if (f3 < -f2) { + f3 = -f2; + } + + float f4 = f + f3; + + if (f4 < 0.0F) + f4 += 360.0F; + else if (f4 > 360.0F) { + f4 -= 360.0F; + } + + return f4; + } + + @Override + public double b() { + return this.e; + } + + @Override + public void c() { + this.a.ba = 0F; + if (this.f) { + this.f = false; + int i = MathHelper.floor(this.a.getBoundingBox().b + 0.5D); + double d0 = this.b - this.a.locX; + double d1 = this.d - this.a.locZ; + double d2 = this.c - i; + double d3 = d0 * d0 + d2 * d2 + d1 * d1; + if (d3 < 2.500000277905201E-007D) + return; + float f = (float) Math.toDegrees(Math.atan2(d1, d0)) - 90.0F; + this.a.yaw = a(this.a.yaw, f, 90.0F); + NMS.setHeadYaw(a.getBukkitEntity(), this.a.yaw); + AttributeInstance speed = this.a.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED); + speed.setValue(0.1D * this.e); + float movement = (float) (this.e * speed.getValue()) * 10; + this.a.ba = movement; + if (shouldSlimeJump() || ((d2 > 0.0D) && (d0 * d0 + d1 * d1 < 1.0D))) { + this.h = cg(); + this.h /= 3; + if (this.a instanceof EntityHumanNPC) { + ((EntityHumanNPC) this.a).getControllerJump().a(); + } else { + ((EntityInsentient) this.a).getControllerJump().a(); + } + } + } + } + + protected int cg() { + return new Random().nextInt(20) + 10; + } + + @Override + public double d() { + return this.b; + } + + @Override + public double e() { + return this.c; + } + + @Override + public double f() { + return this.d; + } + + private boolean shouldSlimeJump() { + if (!(this.a instanceof EntitySlime)) { + return false; + } + if (this.h-- <= 0) { + return true; + } + return false; + } +} \ No newline at end of file diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerNavigation.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerNavigation.java new file mode 100644 index 000000000..a75f15884 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerNavigation.java @@ -0,0 +1,431 @@ +package net.citizensnpcs.nms.v1_8_R3.util; + +import java.util.List; + +import net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC; +import net.minecraft.server.v1_8_R3.AttributeInstance; +import net.minecraft.server.v1_8_R3.AxisAlignedBB; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.Blocks; +import net.minecraft.server.v1_8_R3.ChunkCache; +import net.minecraft.server.v1_8_R3.Entity; +import net.minecraft.server.v1_8_R3.EntityInsentient; +import net.minecraft.server.v1_8_R3.GenericAttributes; +import net.minecraft.server.v1_8_R3.Material; +import net.minecraft.server.v1_8_R3.MathHelper; +import net.minecraft.server.v1_8_R3.NavigationAbstract; +import net.minecraft.server.v1_8_R3.PathEntity; +import net.minecraft.server.v1_8_R3.PathPoint; +import net.minecraft.server.v1_8_R3.Pathfinder; +import net.minecraft.server.v1_8_R3.Vec3D; +import net.minecraft.server.v1_8_R3.World; + +public class PlayerNavigation extends NavigationAbstract { + private final AttributeInstance a; + protected EntityHumanNPC b; + protected World c; + protected PathEntity d; + protected double e; + private int f; + private boolean fb; + private int g; + private Vec3D h = new Vec3D(0.0D, 0.0D, 0.0D); + private float i = 1.0F; + private final PlayerPathfinder j; + private final PlayerPathfinderNormal s; + + public PlayerNavigation(EntityHumanNPC entityinsentient, World world) { + super(getDummyInsentient(entityinsentient, world), world); + this.b = entityinsentient; + this.c = world; + this.a = entityinsentient.getAttributeInstance(GenericAttributes.FOLLOW_RANGE); + this.a.setValue(24); + + this.s = new PlayerPathfinderNormal(); + this.s.a(true); + this.j = new PlayerPathfinder(this.s); + // this.b.C().a(this); + } + + @Override + protected Pathfinder a() { + return null; + } + + @Override + public PathEntity a(BlockPosition paramBlockPosition) { + if (!b()) { + return null; + } + float f1 = i(); + this.c.methodProfiler.a("pathfind"); + BlockPosition localBlockPosition = new BlockPosition(this.b); + int k = (int) (f1 + 8.0F); + + ChunkCache localChunkCache = new ChunkCache(this.c, localBlockPosition.a(-k, -k, -k), + localBlockPosition.a(k, k, k), 0); + PathEntity localPathEntity = this.j.a(localChunkCache, this.b, paramBlockPosition, f1); + this.c.methodProfiler.b(); + return localPathEntity; + } + + public void a(boolean paramBoolean) { + this.s.c(paramBoolean); + } + + @Override + public void a(double paramDouble) { + this.e = paramDouble; + } + + @Override + public boolean a(double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4) { + PathEntity localPathEntity = a(MathHelper.floor(paramDouble1), (int) paramDouble2, + MathHelper.floor(paramDouble3)); + return a(localPathEntity, paramDouble4); + } + + @Override + public PathEntity a(Entity paramEntity) { + if (!b()) { + return null; + } + float f1 = i(); + this.c.methodProfiler.a("pathfind"); + BlockPosition localBlockPosition = new BlockPosition(this.b).up(); + int k = (int) (f1 + 16.0F); + + ChunkCache localChunkCache = new ChunkCache(this.c, localBlockPosition.a(-k, -k, -k), + localBlockPosition.a(k, k, k), 0); + PathEntity localPathEntity = this.j.a(localChunkCache, this.b, paramEntity, f1); + this.c.methodProfiler.b(); + return localPathEntity; + } + + @Override + public boolean a(Entity paramEntity, double paramDouble) { + PathEntity localPathEntity = a(paramEntity); + if (localPathEntity != null) { + return a(localPathEntity, paramDouble); + } + return false; + } + + @Override + public void a(float paramFloat) { + this.i = paramFloat; + } + + private boolean a(int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5, int paramInt6, + Vec3D paramVec3D, double paramDouble1, double paramDouble2) { + int i = paramInt1 - paramInt4 / 2; + int j = paramInt3 - paramInt6 / 2; + if (!b(i, paramInt2, j, paramInt4, paramInt5, paramInt6, paramVec3D, paramDouble1, paramDouble2)) { + return false; + } + for (int k = i; k < i + paramInt4; k++) { + for (int m = j; m < j + paramInt6; m++) { + double d1 = k + 0.5D - paramVec3D.a; + double d2 = m + 0.5D - paramVec3D.c; + if (d1 * paramDouble1 + d2 * paramDouble2 >= 0.0D) { + Block localBlock = this.c.getType(new BlockPosition(k, paramInt2 - 1, m)).getBlock(); + Material localMaterial = localBlock.getMaterial(); + if (localMaterial == Material.AIR) { + return false; + } + if ((localMaterial == Material.WATER) && (!this.b.V())) { + return false; + } + if (localMaterial == Material.LAVA) { + return false; + } + } + } + } + return true; + } + + @Override + public boolean a(PathEntity paramPathEntity, double paramDouble) { + if (paramPathEntity == null) { + this.d = null; + return false; + } + if (!paramPathEntity.a(this.d)) { + this.d = paramPathEntity; + } + d(); + if (this.d.d() == 0) { + return false; + } + this.e = paramDouble; + Vec3D localVec3D = c(); + this.g = this.f; + this.h = localVec3D; + return true; + } + + @Override + protected void a(Vec3D paramVec3D) { + if (this.f - this.g > 100) { + if (paramVec3D.distanceSquared(this.h) < 2.25D) { + n(); + } + this.g = this.f; + this.h = paramVec3D; + } + } + + @Override + protected boolean a(Vec3D paramVec3D1, Vec3D paramVec3D2, int paramInt1, int paramInt2, int paramInt3) { + int i = MathHelper.floor(paramVec3D1.a); + int j = MathHelper.floor(paramVec3D1.c); + + double d1 = paramVec3D2.a - paramVec3D1.a; + double d2 = paramVec3D2.c - paramVec3D1.c; + double d3 = d1 * d1 + d2 * d2; + if (d3 < 1.0E-8D) { + return false; + } + double d4 = 1.0D / Math.sqrt(d3); + d1 *= d4; + d2 *= d4; + + paramInt1 += 2; + paramInt3 += 2; + if (!a(i, (int) paramVec3D1.b, j, paramInt1, paramInt2, paramInt3, paramVec3D1, d1, d2)) { + return false; + } + paramInt1 -= 2; + paramInt3 -= 2; + + double d5 = 1.0D / Math.abs(d1); + double d6 = 1.0D / Math.abs(d2); + + double d7 = i * 1 - paramVec3D1.a; + double d8 = j * 1 - paramVec3D1.c; + if (d1 >= 0.0D) { + d7 += 1.0D; + } + if (d2 >= 0.0D) { + d8 += 1.0D; + } + d7 /= d1; + d8 /= d2; + + int k = d1 < 0.0D ? -1 : 1; + int m = d2 < 0.0D ? -1 : 1; + int n = MathHelper.floor(paramVec3D2.a); + int i1 = MathHelper.floor(paramVec3D2.c); + int i2 = n - i; + int i3 = i1 - j; + while ((i2 * k > 0) || (i3 * m > 0)) { + if (d7 < d8) { + d7 += d5; + i += k; + i2 = n - i; + } else { + d8 += d6; + j += m; + i3 = i1 - j; + } + if (!a(i, (int) paramVec3D1.b, j, paramInt1, paramInt2, paramInt3, paramVec3D1, d1, d2)) { + return false; + } + } + return true; + } + + @Override + protected boolean b() { + return (this.b.onGround) || ((h()) && (o())) || ((this.b.au())); + } + + public void b(boolean paramBoolean) { + this.s.b(paramBoolean); + } + + private boolean b(int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5, int paramInt6, + Vec3D paramVec3D, double paramDouble1, double paramDouble2) { + for (BlockPosition localBlockPosition : BlockPosition.a(new BlockPosition(paramInt1, paramInt2, paramInt3), + new BlockPosition(paramInt1 + paramInt4 - 1, paramInt2 + paramInt5 - 1, paramInt3 + paramInt6 - 1))) { + double d1 = localBlockPosition.getX() + 0.5D - paramVec3D.a; + double d2 = localBlockPosition.getZ() + 0.5D - paramVec3D.c; + if (d1 * paramDouble1 + d2 * paramDouble2 >= 0.0D) { + Block localBlock = this.c.getType(localBlockPosition).getBlock(); + if (!localBlock.b(this.c, localBlockPosition)) { + return false; + } + } + } + return true; + } + + @Override + protected Vec3D c() { + return new Vec3D(this.b.locX, p(), this.b.locZ); + } + + public void c(boolean paramBoolean) { + this.s.a(paramBoolean); + } + + @Override + protected void d() { + super.d(); + if (this.fb) { + if (this.c.i(new BlockPosition(MathHelper.floor(this.b.locX), (int) (this.b.getBoundingBox().b + 0.5D), + MathHelper.floor(this.b.locZ)))) { + return; + } + for (int i = 0; i < this.d.d(); i++) { + PathPoint localPathPoint = this.d.a(i); + if (this.c.i(new BlockPosition(localPathPoint.a, localPathPoint.b, localPathPoint.c))) { + this.d.b(i - 1); + return; + } + } + } + } + + public void d(boolean paramBoolean) { + this.s.d(paramBoolean); + } + + public boolean e() { + return this.s.e(); + } + + public void e(boolean paramBoolean) { + this.fb = paramBoolean; + } + + public boolean g() { + return this.s.b(); + } + + public boolean h() { + return this.s.d(); + } + + @Override + public float i() { + return (float) this.a.getValue(); + } + + @Override + public PathEntity j() { + return this.d; + } + + @Override + public void k() { + this.f += 1; + if (m()) { + return; + } + if (b()) { + l(); + } else if ((this.d != null) && (this.d.e() < this.d.d())) { + Vec3D localVec3D = c(); + Vec3D localObject = this.d.a(this.b, this.d.e()); + if ((localVec3D.b > localObject.b) && (!this.b.onGround) + && (MathHelper.floor(localVec3D.a) == MathHelper.floor(localObject.a)) + && (MathHelper.floor(localVec3D.c) == MathHelper.floor(localObject.c))) { + this.d.c(this.d.e() + 1); + } + } + if (m()) { + return; + } + Vec3D localVec3D = this.d.a(this.b); + if (localVec3D == null) { + return; + } + Object localObject = new AxisAlignedBB(localVec3D.a, localVec3D.b, localVec3D.c, localVec3D.a, localVec3D.b, + localVec3D.c).grow(0.5D, 0.5D, 0.5D); + List localList = this.c.getCubes(this.b, ((AxisAlignedBB) localObject).a(0.0D, -1.0D, 0.0D)); + double d1 = -1.0D; + localObject = ((AxisAlignedBB) localObject).c(0.0D, 1.0D, 0.0D); + for (AxisAlignedBB localAxisAlignedBB : localList) { + d1 = localAxisAlignedBB.b((AxisAlignedBB) localObject, d1); + } + this.b.getControllerMove().a(localVec3D.a, localVec3D.b + d1, localVec3D.c, this.e); + } + + @Override + protected void l() { + Vec3D localVec3D1 = c(); + + int k = this.d.d(); + for (int m = this.d.e(); m < this.d.d(); m++) { + if (this.d.a(m).b != (int) localVec3D1.b) { + k = m; + break; + } + } + float f1 = this.b.width * this.b.width * this.i; + for (int n = this.d.e(); n < k; n++) { + Vec3D localVec3D2 = this.d.a(this.b, n); + if (localVec3D1.distanceSquared(localVec3D2) < f1) { + this.d.c(n + 1); + } + } + int n = MathHelper.f(this.b.width); + int i1 = (int) this.b.length + 1; + int i2 = n; + for (int i3 = k - 1; i3 >= this.d.e(); i3--) { + if (a(localVec3D1, this.d.a(this.b, i3), n, i1, i2)) { + this.d.c(i3); + break; + } + } + a(localVec3D1); + } + + @Override + public boolean m() { + return (this.d == null) || (this.d.b()); + } + + @Override + public void n() { + this.d = null; + } + + @Override + protected boolean o() { + return (this.b.V()) || (this.b.ab()); + } + + private int p() { + if ((!this.b.V()) || (!h())) { + return (int) (this.b.getBoundingBox().b + 0.5D); + } + int i = (int) this.b.getBoundingBox().b; + Block localBlock = this.c + .getType(new BlockPosition(MathHelper.floor(this.b.locX), i, MathHelper.floor(this.b.locZ))).getBlock(); + int j = 0; + while ((localBlock == Blocks.FLOWING_WATER) || (localBlock == Blocks.WATER)) { + i++; + localBlock = this.c + .getType(new BlockPosition(MathHelper.floor(this.b.locX), i, MathHelper.floor(this.b.locZ))) + .getBlock(); + j++; + if (j > 16) { + return (int) this.b.getBoundingBox().b; + } + } + return i; + } + + public void setRange(float pathfindingRange) { + this.a.setValue(pathfindingRange); + } + + private static EntityInsentient getDummyInsentient(EntityHumanNPC from, World world) { + return new EntityInsentient(world) { + }; + } +} diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerPathfinder.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerPathfinder.java new file mode 100644 index 000000000..9510fafc6 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerPathfinder.java @@ -0,0 +1,137 @@ +package net.citizensnpcs.nms.v1_8_R3.util; + +import java.lang.reflect.Field; + +import net.citizensnpcs.util.NMS; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.Entity; +import net.minecraft.server.v1_8_R3.IBlockAccess; +import net.minecraft.server.v1_8_R3.Path; +import net.minecraft.server.v1_8_R3.PathEntity; +import net.minecraft.server.v1_8_R3.PathPoint; + +public class PlayerPathfinder { + private final Path a = new Path(); + private final PathPoint[] b = new PathPoint[32]; + private final PlayerPathfinderNormal c; + + public PlayerPathfinder(PlayerPathfinderNormal paramPathfinderAbstract) { + this.c = paramPathfinderAbstract; + } + + private PathEntity a(Entity paramEntity, PathPoint paramPathPoint1, PathPoint paramPathPoint2, float paramFloat) { + float newF = 0.0F; + try { + E.set(paramPathPoint1, 0.0F); + newF = paramPathPoint1.b(paramPathPoint2); + F.set(paramPathPoint1, newF); + G.set(paramPathPoint1, newF); + } catch (IllegalArgumentException e1) { + e1.printStackTrace(); + } catch (IllegalAccessException e1) { + e1.printStackTrace(); + } + + this.a.a(); + this.a.a(paramPathPoint1); + + Object localObject = paramPathPoint1; + while (!this.a.e()) { + PathPoint localPathPoint1 = this.a.c(); + if (localPathPoint1.equals(paramPathPoint2)) { + return a(paramPathPoint1, paramPathPoint2); + } + if (localPathPoint1.b(paramPathPoint2) < ((PathPoint) localObject).b(paramPathPoint2)) { + localObject = localPathPoint1; + } + localPathPoint1.i = true; + + int i = this.c.a(this.b, paramEntity, localPathPoint1, paramPathPoint2, paramFloat); + for (int j = 0; j < i; j++) { + PathPoint localPathPoint2 = this.b[j]; + try { + float e = E.getFloat(localObject); + float f = e + localPathPoint1.b(localPathPoint2); + if ((f < paramFloat * 2.0F) && ((!localPathPoint2.a()) || (f < e))) { + H.set(localPathPoint2, localPathPoint1); + E.set(localPathPoint2, f); + newF = localPathPoint2.b(paramPathPoint2); + F.set(localPathPoint2, newF); + if (localPathPoint2.a()) { + this.a.a(localPathPoint2, f + newF); + } else { + G.set(localPathPoint2, f + newF); + this.a.a(localPathPoint2); + } + } + } catch (IllegalArgumentException e1) { + e1.printStackTrace(); + } catch (IllegalAccessException e1) { + e1.printStackTrace(); + } + } + } + if (localObject == paramPathPoint1) { + return null; + } + return a(paramPathPoint1, (PathPoint) localObject); + } + + public PathEntity a(IBlockAccess paramIBlockAccess, Entity paramEntity, BlockPosition paramBlockPosition, + float paramFloat) { + return a(paramIBlockAccess, paramEntity, paramBlockPosition.getX() + 0.5F, paramBlockPosition.getY() + 0.5F, + paramBlockPosition.getZ() + 0.5F, paramFloat); + } + + private PathEntity a(IBlockAccess paramIBlockAccess, Entity paramEntity, double paramDouble1, double paramDouble2, + double paramDouble3, float paramFloat) { + this.a.a(); + this.c.a(paramIBlockAccess, paramEntity); + PathPoint localPathPoint1 = this.c.a(paramEntity); + PathPoint localPathPoint2 = this.c.a(paramEntity, paramDouble1, paramDouble2, paramDouble3); + + PathEntity localPathEntity = a(paramEntity, localPathPoint1, localPathPoint2, paramFloat); + + this.c.a(); + return localPathEntity; + } + + public PathEntity a(IBlockAccess paramIBlockAccess, Entity paramEntity1, Entity paramEntity2, float paramFloat) { + return a(paramIBlockAccess, paramEntity1, paramEntity2.locX, paramEntity2.getBoundingBox().b, paramEntity2.locZ, + paramFloat); + } + + private PathEntity a(PathPoint paramPathPoint1, PathPoint paramPathPoint2) { + int i = 1; + PathPoint localPathPoint = paramPathPoint2; + try { + while (H.get(localPathPoint) != null) { + i++; + localPathPoint = (PathPoint) H.get(localPathPoint); + } + } catch (IllegalArgumentException e1) { + e1.printStackTrace(); + } catch (IllegalAccessException e1) { + e1.printStackTrace(); + } + PathPoint[] arrayOfPathPoint = new PathPoint[i]; + localPathPoint = paramPathPoint2; + arrayOfPathPoint[(--i)] = localPathPoint; + try { + while (H.get(localPathPoint) != null) { + localPathPoint = (PathPoint) H.get(localPathPoint); + arrayOfPathPoint[(--i)] = localPathPoint; + } + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return new PathEntity(arrayOfPathPoint); + } + + private static Field E = NMS.getField(PathPoint.class, "e"); + private static Field F = NMS.getField(PathPoint.class, "f"); + private static Field G = NMS.getField(PathPoint.class, "g"); + private static Field H = NMS.getField(PathPoint.class, "h"); +} diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerPathfinderAbstract.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerPathfinderAbstract.java new file mode 100644 index 000000000..e4d20b9d9 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerPathfinderAbstract.java @@ -0,0 +1,51 @@ +package net.citizensnpcs.nms.v1_8_R3.util; + +import net.minecraft.server.v1_8_R3.Entity; +import net.minecraft.server.v1_8_R3.IBlockAccess; +import net.minecraft.server.v1_8_R3.IntHashMap; +import net.minecraft.server.v1_8_R3.MathHelper; +import net.minecraft.server.v1_8_R3.PathPoint; +import net.minecraft.server.v1_8_R3.PathfinderAbstract; + +public abstract class PlayerPathfinderAbstract extends PathfinderAbstract { + protected IBlockAccess a; + protected IntHashMap b = new IntHashMap(); + protected int c; + protected int d; + protected int e; + + @Override + public void a() { + } + + @Override + public abstract PathPoint a(Entity paramEntity); + + @Override + public abstract PathPoint a(Entity paramEntity, double paramDouble1, double paramDouble2, double paramDouble3); + + @Override + public void a(IBlockAccess paramIBlockAccess, Entity paramEntity) { + this.a = paramIBlockAccess; + this.b.c(); + + this.c = MathHelper.d(paramEntity.width + 1.0F); + this.d = MathHelper.d(paramEntity.length + 1.0F); + this.e = MathHelper.d(paramEntity.width + 1.0F); + } + + @Override + protected PathPoint a(int paramInt1, int paramInt2, int paramInt3) { + int i = PathPoint.a(paramInt1, paramInt2, paramInt3); + PathPoint localPathPoint = this.b.get(i); + if (localPathPoint == null) { + localPathPoint = new PathPoint(paramInt1, paramInt2, paramInt3); + this.b.a(i, localPathPoint); + } + return localPathPoint; + } + + @Override + public abstract int a(PathPoint[] paramArrayOfPathPoint, Entity paramEntity, PathPoint paramPathPoint1, + PathPoint paramPathPoint2, float paramFloat); +} diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerPathfinderNormal.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerPathfinderNormal.java new file mode 100644 index 000000000..a965d190a --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerPathfinderNormal.java @@ -0,0 +1,221 @@ +package net.citizensnpcs.nms.v1_8_R3.util; + +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockCobbleWall; +import net.minecraft.server.v1_8_R3.BlockDoor; +import net.minecraft.server.v1_8_R3.BlockFence; +import net.minecraft.server.v1_8_R3.BlockFenceGate; +import net.minecraft.server.v1_8_R3.BlockMinecartTrackAbstract; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.Blocks; +import net.minecraft.server.v1_8_R3.Entity; +import net.minecraft.server.v1_8_R3.IBlockAccess; +import net.minecraft.server.v1_8_R3.Material; +import net.minecraft.server.v1_8_R3.MathHelper; +import net.minecraft.server.v1_8_R3.PathPoint; + +public class PlayerPathfinderNormal extends PlayerPathfinderAbstract { + private boolean f; + private boolean g; + private boolean h; + private boolean i; + private boolean j; + + @Override + public void a() { + super.a(); + this.h = this.j; + } + + public void a(boolean paramBoolean) { + this.f = paramBoolean; + } + + @Override + public PathPoint a(Entity paramEntity) { + int k; + if ((this.i) && (paramEntity.V())) { + k = (int) paramEntity.getBoundingBox().b; + BlockPosition.MutableBlockPosition localMutableBlockPosition = new BlockPosition.MutableBlockPosition( + MathHelper.floor(paramEntity.locX), k, MathHelper.floor(paramEntity.locZ)); + Block localBlock = this.a.getType(localMutableBlockPosition).getBlock(); + while ((localBlock == Blocks.FLOWING_WATER) || (localBlock == Blocks.WATER)) { + k++; + localMutableBlockPosition.c(MathHelper.floor(paramEntity.locX), k, MathHelper.floor(paramEntity.locZ)); + localBlock = this.a.getType(localMutableBlockPosition).getBlock(); + } + this.h = false; + } else { + k = MathHelper.floor(paramEntity.getBoundingBox().b + 0.5D); + } + return a(MathHelper.floor(paramEntity.getBoundingBox().a), k, MathHelper.floor(paramEntity.getBoundingBox().c)); + } + + @Override + public PathPoint a(Entity paramEntity, double paramDouble1, double paramDouble2, double paramDouble3) { + return a(MathHelper.floor(paramDouble1 - paramEntity.width / 2.0F), MathHelper.floor(paramDouble2), + MathHelper.floor(paramDouble3 - paramEntity.width / 2.0F)); + } + + private int a(Entity paramEntity, int paramInt1, int paramInt2, int paramInt3) { + return a(this.a, paramEntity, paramInt1, paramInt2, paramInt3, this.c, this.d, this.e, this.h, this.g, this.f); + } + + private PathPoint a(Entity paramEntity, int paramInt1, int paramInt2, int paramInt3, int paramInt4) { + PathPoint localPathPoint = null; + int k = a(paramEntity, paramInt1, paramInt2, paramInt3); + if (k == 2) { + return a(paramInt1, paramInt2, paramInt3); + } + if (k == 1) { + localPathPoint = a(paramInt1, paramInt2, paramInt3); + } + if ((localPathPoint == null) && (paramInt4 > 0) && (k != -3) && (k != -4) + && (a(paramEntity, paramInt1, paramInt2 + paramInt4, paramInt3) == 1)) { + localPathPoint = a(paramInt1, paramInt2 + paramInt4, paramInt3); + paramInt2 += paramInt4; + } + if (localPathPoint != null) { + int m = 0; + int n = 0; + while (paramInt2 > 0) { + n = a(paramEntity, paramInt1, paramInt2 - 1, paramInt3); + if ((this.h) && (n == -1)) { + return null; + } + if (n == 1) { + if (m++ >= paramEntity.aE()) { + return null; + } + paramInt2--; + if (paramInt2 > 0) { + localPathPoint = a(paramInt1, paramInt2, paramInt3); + } else { + return null; + } + } + } + if (n == -2) { + return null; + } + } + return localPathPoint; + } + + @Override + public void a(IBlockAccess paramIBlockAccess, Entity paramEntity) { + super.a(paramIBlockAccess, paramEntity); + this.j = this.h; + } + + @Override + public int a(PathPoint[] paramArrayOfPathPoint, Entity paramEntity, PathPoint paramPathPoint1, + PathPoint paramPathPoint2, float paramFloat) { + int k = 0; + + int m = 0; + if (a(paramEntity, paramPathPoint1.a, paramPathPoint1.b + 1, paramPathPoint1.c) == 1) { + m = 1; + } + PathPoint localPathPoint1 = a(paramEntity, paramPathPoint1.a, paramPathPoint1.b, paramPathPoint1.c + 1, m); + PathPoint localPathPoint2 = a(paramEntity, paramPathPoint1.a - 1, paramPathPoint1.b, paramPathPoint1.c, m); + PathPoint localPathPoint3 = a(paramEntity, paramPathPoint1.a + 1, paramPathPoint1.b, paramPathPoint1.c, m); + PathPoint localPathPoint4 = a(paramEntity, paramPathPoint1.a, paramPathPoint1.b, paramPathPoint1.c - 1, m); + if ((localPathPoint1 != null) && (!localPathPoint1.i) && (localPathPoint1.a(paramPathPoint2) < paramFloat)) { + paramArrayOfPathPoint[(k++)] = localPathPoint1; + } + if ((localPathPoint2 != null) && (!localPathPoint2.i) && (localPathPoint2.a(paramPathPoint2) < paramFloat)) { + paramArrayOfPathPoint[(k++)] = localPathPoint2; + } + if ((localPathPoint3 != null) && (!localPathPoint3.i) && (localPathPoint3.a(paramPathPoint2) < paramFloat)) { + paramArrayOfPathPoint[(k++)] = localPathPoint3; + } + if ((localPathPoint4 != null) && (!localPathPoint4.i) && (localPathPoint4.a(paramPathPoint2) < paramFloat)) { + paramArrayOfPathPoint[(k++)] = localPathPoint4; + } + return k; + } + + public boolean b() { + return this.f; + } + + public void b(boolean paramBoolean) { + this.g = paramBoolean; + } + + public void c(boolean paramBoolean) { + this.h = paramBoolean; + } + + public boolean d() { + return this.i; + } + + public void d(boolean paramBoolean) { + this.i = paramBoolean; + } + + public boolean e() { + return this.h; + } + + public static int a(IBlockAccess paramIBlockAccess, Entity paramEntity, int paramInt1, int paramInt2, int paramInt3, + int paramInt4, int paramInt5, int paramInt6, boolean paramBoolean1, boolean paramBoolean2, + boolean paramBoolean3) { + int k = 0; + BlockPosition localBlockPosition = new BlockPosition(paramEntity); + + BlockPosition.MutableBlockPosition localMutableBlockPosition = new BlockPosition.MutableBlockPosition(); + for (int m = paramInt1; m < paramInt1 + paramInt4; m++) { + for (int n = paramInt2; n < paramInt2 + paramInt5; n++) { + for (int i1 = paramInt3; i1 < paramInt3 + paramInt6; i1++) { + localMutableBlockPosition.c(m, n, i1); + Block localBlock = paramIBlockAccess.getType(localMutableBlockPosition).getBlock(); + if (localBlock.getMaterial() != Material.AIR) { + if ((localBlock == Blocks.TRAPDOOR) || (localBlock == Blocks.IRON_TRAPDOOR)) { + k = 1; + } else if ((localBlock == Blocks.FLOWING_WATER) || (localBlock == Blocks.WATER)) { + if (paramBoolean1) { + return -1; + } + k = 1; + } else if ((!paramBoolean3) && ((localBlock instanceof BlockDoor)) + && (localBlock.getMaterial() == Material.WOOD)) { + return 0; + } + if ((paramEntity.world.getType(localMutableBlockPosition) + .getBlock() instanceof BlockMinecartTrackAbstract)) { + if ((!(paramEntity.world.getType(localBlockPosition) + .getBlock() instanceof BlockMinecartTrackAbstract)) + && (!(paramEntity.world.getType(localBlockPosition.down()) + .getBlock() instanceof BlockMinecartTrackAbstract))) { + return -3; + } + } else if (!localBlock.b(paramIBlockAccess, localMutableBlockPosition)) { + if ((!paramBoolean2) || (!(localBlock instanceof BlockDoor)) + || (localBlock.getMaterial() != Material.WOOD)) { + if (((localBlock instanceof BlockFence)) || ((localBlock instanceof BlockFenceGate)) + || ((localBlock instanceof BlockCobbleWall))) { + return -3; + } + if ((localBlock == Blocks.TRAPDOOR) || (localBlock == Blocks.IRON_TRAPDOOR)) { + return -4; + } + Material localMaterial = localBlock.getMaterial(); + if (localMaterial == Material.LAVA) { + if (!paramEntity.ab()) { + return -2; + } + } else { + return 0; + } + } + } + } + } + } + } + return k != 0 ? 2 : 1; + } +} diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerlistTrackerEntry.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerlistTrackerEntry.java new file mode 100644 index 000000000..ded766a92 --- /dev/null +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerlistTrackerEntry.java @@ -0,0 +1,96 @@ +package net.citizensnpcs.nms.v1_8_R3.util; + +import java.lang.reflect.Field; + +import org.bukkit.entity.Player; + +import net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC; +import net.citizensnpcs.npc.skin.SkinnableEntity; +import net.citizensnpcs.util.NMS; +import net.minecraft.server.v1_8_R3.Entity; +import net.minecraft.server.v1_8_R3.EntityPlayer; +import net.minecraft.server.v1_8_R3.EntityTrackerEntry; + +public class PlayerlistTrackerEntry extends EntityTrackerEntry { + public PlayerlistTrackerEntry(Entity entity, int i, int j, boolean flag) { + super(entity, i, j, flag); + } + + public PlayerlistTrackerEntry(EntityTrackerEntry entry) { + this(getTracker(entry), getB(entry), getC(entry), getU(entry)); + } + + @Override + public void updatePlayer(final EntityPlayer entityplayer) { + // prevent updates to NPC "viewers" + if (entityplayer instanceof EntityHumanNPC) + return; + Entity tracker = getTracker(this); + if (entityplayer != tracker && c(entityplayer)) { + if (!this.trackedPlayers.contains(entityplayer) + && ((entityplayer.u().getPlayerChunkMap().a(entityplayer, tracker.ae, tracker.ag)) + || (tracker.attachedToPlayer))) { + if ((tracker instanceof SkinnableEntity)) { + + SkinnableEntity skinnable = (SkinnableEntity) tracker; + + Player player = skinnable.getBukkitEntity(); + if (!entityplayer.getBukkitEntity().canSee(player)) + return; + + skinnable.getSkinTracker().updateViewer(entityplayer.getBukkitEntity()); + } + } + } + super.updatePlayer(entityplayer); + } + + private static int getB(EntityTrackerEntry entry) { + try { + return (Integer) B.get(entry); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return 0; + } + + private static int getC(EntityTrackerEntry entry) { + try { + return (Integer) C.get(entry); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return 0; + } + + private static Entity getTracker(EntityTrackerEntry entry) { + try { + return (Entity) TRACKER.get(entry); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return null; + } + + private static boolean getU(EntityTrackerEntry entry) { + try { + return (Boolean) U.get(entry); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return false; + } + + private static Field B = NMS.getField(EntityTrackerEntry.class, "b"); + private static Field C = NMS.getField(EntityTrackerEntry.class, "c"); + private static Field TRACKER = NMS.getField(EntityTrackerEntry.class, "tracker"); + private static Field U = NMS.getField(EntityTrackerEntry.class, "u"); +}