EnderLance

Main.java - Herobrine plugin

Feb 19th, 2014
147
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ca.enderlance.bukkit.herobrine;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.command.Command;
  5. import org.bukkit.command.CommandSender;
  6. import org.bukkit.entity.EntityType;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.event.EventHandler;
  9. import org.bukkit.event.Listener;
  10. import org.bukkit.event.player.PlayerJoinEvent;
  11. import org.bukkit.plugin.PluginManager;
  12. import org.bukkit.plugin.java.JavaPlugin;
  13.  
  14. import de.kumpelblase2.remoteentities.CreateEntityContext;
  15. import de.kumpelblase2.remoteentities.EntityManager;
  16. import de.kumpelblase2.remoteentities.RemoteEntities;
  17. import de.kumpelblase2.remoteentities.api.RemoteEntity;
  18. import de.kumpelblase2.remoteentities.api.RemoteEntityType;
  19. import de.kumpelblase2.remoteentities.api.pathfinding.Pathfinder;
  20. import de.kumpelblase2.remoteentities.api.thinking.DamageBehavior;
  21. import de.kumpelblase2.remoteentities.api.thinking.Desire;
  22. import de.kumpelblase2.remoteentities.api.thinking.goals.DesireAvoidSpecific;
  23. import de.kumpelblase2.remoteentities.api.thinking.goals.DesireAvoidSpecificEntity;
  24. import de.kumpelblase2.remoteentities.api.thinking.goals.DesireAvoidSun;
  25. import de.kumpelblase2.remoteentities.api.thinking.goals.DesireFindAttackingTarget;
  26. import de.kumpelblase2.remoteentities.api.thinking.goals.DesireFindNearestTarget;
  27. import de.kumpelblase2.remoteentities.api.thinking.goals.DesireLookAtNearest;
  28. import de.kumpelblase2.remoteentities.api.thinking.goals.DesireMoveAndMeleeAttack;
  29. import de.kumpelblase2.remoteentities.api.thinking.goals.DesireMoveToLocation;
  30. import de.kumpelblase2.remoteentities.api.thinking.goals.DesireSwim;
  31. import de.kumpelblase2.remoteentities.api.thinking.goals.DesireWanderAround;
  32. import de.kumpelblase2.remoteentities.api.thinking.goals.DesireWanderAroundArea;
  33. import de.kumpelblase2.remoteentities.entities.RemotePlayer;
  34. import de.kumpelblase2.remoteentities.entities.RemoteSpider;
  35.  
  36. public class Main extends JavaPlugin implements Listener {
  37.     EntityManager manager;
  38.     RemoteEntity herobrine;
  39.     DesireWanderAround wandering = new DesireWanderAround();
  40.     DesireAvoidSun fleeSunlight = new DesireAvoidSun();
  41.     //Desire fleeSpiders = new DesireAvoidSpecific(10, 4, 2, EntityType.SPIDER.getClass());
  42.     //Pathfinder path = new Pathfinder(herobrine);
  43.    
  44.     @Override
  45.     public void onEnable()
  46.     {  
  47.         PluginManager pm = getServer().getPluginManager();
  48.         pm.registerEvents(this, this);
  49.         manager = RemoteEntities.createManager(this);
  50.         //herobrine.despawn(DespawnReason.CUSTOM);
  51.         //herobrine = (RemotePlayer) manager.createNamedEntity(RemoteEntityType.Human, Bukkit.getWorld("world").getSpawnLocation(), "Herobrine");
  52.  
  53.         CreateEntityContext entityContext = manager.prepareEntity(RemoteEntityType.Human)
  54.                 .withName("Herobrine")
  55.                 .withMaxHealth(20)
  56.                 .atLocation(getServer().getWorld("world").getSpawnLocation())
  57.                 .asPushable(true)
  58.                 .asStationary(false)
  59.                 .withSpeed(2);
  60.        
  61.         herobrine = entityContext.create();
  62.        
  63.         herobrine.getMind().addTargetingDesire(new DesireFindAttackingTarget(50F, true, false), 1);
  64.         herobrine.getMind().addMovementDesire(new DesireMoveAndMeleeAttack(Player.class, true), 3);
  65.         //herobrine.getMind().addMovementDesire(new DesireAvoidSun(), 5);
  66.         //herobrine.getMind().addMovementDesire(new DesireAvoidSpecific(10, 7, 3, EntityType.SPIDER.getClass()), 7);
  67.         //herobrine.getMind().addMovementDesire(new DesireLookAtNearest(EntityType.PLAYER.getClass(), 3), 6);
  68.        
  69.         //setHerobrineMindset();
  70.         getLogger().info("Herobrine is stationary? "+herobrine.isStationary());
  71.     }
  72.    
  73.     public void setHerobrineMindset()
  74.     {
  75.        
  76.         herobrine.getMind().addMovementDesire(wandering, 2);
  77.         herobrine.getMind().addMovementDesire(fleeSunlight, 3);
  78.         //herobrine.getMind().addMovementDesire(fleeSpiders, 5);
  79.        
  80.     }
  81.    
  82.     @Override
  83.     public void onDisable()
  84.     {
  85.         manager.despawnAll();
  86.     }
  87.    
  88.     /*@EventHandler
  89.     public void onPush(RemoteEntityPushEvent e)
  90.     {
  91.     }*/
  92.    
  93.     @EventHandler
  94.     public void onPlayerJoin(PlayerJoinEvent e)
  95.     {
  96.         //Player player = e.getPlayer();
  97.         //herobrine.getMind().addMovementDesire(new DesireLookAtNearest(null, 5), 2);
  98.     }
  99.    
  100.     public void spawnAtPlayer(Player player)
  101.     {
  102.         /*RemoteEntity herobrine = manager.createEntity(RemoteEntityType.Human, player.getLocation(), false);
  103.         herobrine.setName("Herobrine");
  104.         herobrine.setStationary(false);
  105.         //herobrine.getMind().addMovementDesire(new DesireSwim(), 1);
  106.         //herobrine.getMind().addMovementDesire(new DesireWanderAround(), 2);*/
  107.         CreateEntityContext c = manager
  108.                 .prepareEntity(RemoteEntityType.Human)
  109.                 .asPushable(true)
  110.                 .asStationary(false)
  111.                 .atLocation(player.getLocation())
  112.                 .withName("Herobrine");
  113.        
  114.        
  115.         RemoteEntity entity = c.create();
  116.         //RemoteEntity entity = manager.createEntity(RemoteEntityType.Human, player.getLocation());
  117.         //entity.setName("Herobrine");
  118.         //entity.getMind().addMovementDesire(new DesireEatGrass(), 1);
  119.         entity.getMind().addMovementDesire(new DesireSwim(), 2);
  120.         entity.getMind().addMovementDesire(new DesireAvoidSun(), 1);
  121.         entity.setStationary(false);
  122.         //re.getMind().addMovementDesire(new DesireEatGrass(), 1);
  123.         //re.getMind().addMovementDesire(new DesireSwim(), 2);
  124.     }
  125.    
  126.     public void getLoc(CommandSender sender, RemoteEntity entity)
  127.     {
  128.         sender.sendMessage("Herobrine's position:");
  129.         sender.sendMessage("X: "+herobrine.getBukkitEntity().getLocation().getX());
  130.         sender.sendMessage("Y: "+herobrine.getBukkitEntity().getLocation().getY());
  131.         sender.sendMessage("Z: "+herobrine.getBukkitEntity().getLocation().getZ());
  132.     }
  133.    
  134.     public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
  135.     {
  136.         if(label.equalsIgnoreCase("bhb"))
  137.         {
  138.             if(args.length == 0)
  139.             {
  140.                 /*if(sender.hasPermission("bherobrine.spawn"))
  141.                 {
  142.                     Player player = (Player) sender;
  143.                     spawnAtPlayer(player);
  144.                     player.sendMessage("An Entity was spawned.");
  145.                 }*/
  146.             }
  147.            
  148.             else if(args.length == 1)
  149.             {
  150.                 if(args[0].equalsIgnoreCase("reload"))
  151.                 {
  152.                     onDisable();
  153.                     onEnable();
  154.                     sender.sendMessage("Plugin reloaded.");
  155.                 }
  156.                
  157.                 else if(args[0].equalsIgnoreCase("tphere"))
  158.                 {
  159.                     Player player = (Player) sender;
  160.                     herobrine.teleport(player.getLocation());
  161.                     player.sendMessage("Herobrine was teleported to you.");
  162.                     herobrine.getMind().addMovementDesire(new DesireWanderAroundArea(10, player.getLocation()), 4);
  163.                 }
  164.                
  165.                 else if(args[0].equalsIgnoreCase("getloc"))
  166.                 {
  167.                     getLoc(sender, herobrine);
  168.                 }
  169.                
  170.                 else if(args[0].equalsIgnoreCase("swing"))
  171.                 {
  172.                     herobrine.getBukkitEntity().damage(10);
  173.                     //herobrine.fakeDamage();
  174.                     //herobrine.doArmSwing();
  175.                 }
  176.                
  177.                 else if(args[0].equalsIgnoreCase("walkhere"))
  178.                 {
  179.                     Player player = (Player) sender;
  180.                     herobrine.move(player.getLocation());
  181.                     herobrine.getMind().addMovementDesire(new DesireMoveToLocation(player.getLocation()), 1);
  182.                 }
  183.                
  184.                 else if(args[0].equalsIgnoreCase("mind"))
  185.                 {
  186.                     setHerobrineMindset();
  187.                 }
  188.             }
  189.         }
  190.         return false;
  191.     }
  192.    
  193. }
RAW Paste Data