SHARE
TWEET

Untitled

a guest Aug 13th, 2017 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package redecouverte.npcspawner;
  2.  
  3. import java.util.logging.Logger;
  4. import net.minecraft.server.Entity;
  5. import net.minecraft.server.EntityHuman;
  6. import net.minecraft.server.EntityPlayer;
  7. import net.minecraft.server.ItemInWorldManager;
  8. import net.minecraft.server.MinecraftServer;
  9. import net.minecraft.server.NetworkManager;
  10. import net.minecraft.server.Packet18ArmAnimation;
  11. import net.minecraft.server.World;
  12. import net.minecraft.server.WorldServer;
  13. import org.bukkit.craftbukkit.CraftServer;
  14. import org.bukkit.event.entity.EntityTargetEvent;
  15.  
  16. public class CHumanNpc extends EntityPlayer {
  17.  
  18.     private static final Logger logger = Logger.getLogger("Minecraft");
  19.     private int lastTargetId;
  20.     private long lastBounceTick;
  21.     private int lastBounceId;
  22.  
  23.     public CHumanNpc(MinecraftServer minecraftserver, World world, String s,
  24.             ItemInWorldManager iteminworldmanager) {
  25.         super(minecraftserver, world, s, iteminworldmanager);
  26.  
  27.         NetworkManager netMgr = new NpcNetworkManager(new NpcSocket(),
  28.                 "npc mgr", null);
  29.         this.a = new NpcNetHandler(minecraftserver, this, netMgr);
  30.  
  31.         this.lastTargetId = -1;
  32.         this.lastBounceId = -1;
  33.         this.lastBounceTick = 0;
  34.     }
  35.  
  36.     public void animateArmSwing() {
  37.         this.b.k.a(this, new Packet18ArmAnimation(this, 1));
  38.     }
  39.  
  40.     @Override
  41.     public boolean a(EntityHuman entity) {
  42.  
  43.         EntityTargetEvent event = new NpcEntityTargetEvent(getBukkitEntity(),
  44.                 entity.getBukkitEntity(),
  45.                 NpcEntityTargetEvent.NpcTargetReason.NPC_RIGHTCLICKED);
  46.         CraftServer server = ((WorldServer) this.world).getServer();
  47.         server.getPluginManager().callEvent(event);
  48.  
  49.         return super.a(entity);
  50.     }
  51.  
  52.     @Override
  53.     public void b(EntityHuman entity) {
  54.         if (lastTargetId == -1 || lastTargetId != entity.id) {
  55.             EntityTargetEvent event = new NpcEntityTargetEvent(
  56.                     getBukkitEntity(), entity.getBukkitEntity(),
  57.                     NpcEntityTargetEvent.NpcTargetReason.CLOSEST_PLAYER);
  58.             CraftServer server = ((WorldServer) this.world).getServer();
  59.             server.getPluginManager().callEvent(event);
  60.         }
  61.         lastTargetId = entity.id;
  62.  
  63.         super.b(entity);
  64.     }
  65.  
  66.     @Override
  67.     public void c(Entity entity) {
  68.         if (lastBounceId != entity.id
  69.                 || System.currentTimeMillis() - lastBounceTick > 1000) {
  70.             EntityTargetEvent event = new NpcEntityTargetEvent(
  71.                     getBukkitEntity(), entity.getBukkitEntity(),
  72.                     NpcEntityTargetEvent.NpcTargetReason.NPC_BOUNCED);
  73.             CraftServer server = ((WorldServer) this.world).getServer();
  74.             server.getPluginManager().callEvent(event);
  75.  
  76.             lastBounceTick = System.currentTimeMillis();
  77.         }
  78.  
  79.         lastBounceId = entity.id;
  80.  
  81.         super.c(entity);
  82.     }
  83. }
RAW Paste Data
Top