Advertisement
Guest User

Untitled

a guest
May 13th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.16 KB | None | 0 0
  1. package CustomDesires;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.entity.Entity;
  5. import org.bukkit.entity.Player;
  6.  
  7. import Resources.Factions.FactionsMain;
  8.  
  9. import net.minecraft.server.v1_5_R3.*;
  10. import de.kumpelblase2.remoteentities.api.RemoteEntity;
  11. import de.kumpelblase2.remoteentities.api.thinking.DesireType;
  12. import de.kumpelblase2.remoteentities.api.thinking.goals.DesireTargetBase;
  13. import de.kumpelblase2.remoteentities.persistence.ParameterData;
  14. import de.kumpelblase2.remoteentities.persistence.SerializeAs;
  15. import de.kumpelblase2.remoteentities.utilities.NMSClassMap;
  16. import de.kumpelblase2.remoteentities.utilities.ReflectionUtil;
  17.  
  18. public class DesireFindEnemyPlayer extends DesireTargetBase{
  19.  
  20.     @SerializeAs(pos = 5)
  21.     protected int m_targetChance;
  22.     @SerializeAs(pos = 4)
  23.     protected Class<? extends Entity> m_targetClass;
  24.     protected DistanceComparator m_comparator;
  25.     protected EntityLiving m_target;
  26.     @SerializeAs(pos = 6)
  27.     protected boolean m_onlyAtNight;
  28.     FactionsMain FM = new FactionsMain();
  29.    
  30.     public DesireFindEnemyPlayer(RemoteEntity inEntity,Class<?> inTargetClass,float inDistance, boolean inShouldCheckSight, int inChance)
  31.     {
  32.         this(inEntity,inTargetClass, inDistance, inShouldCheckSight, false, inChance,null);
  33.     }
  34.    
  35.     @SuppressWarnings("unchecked")
  36.     public DesireFindEnemyPlayer(RemoteEntity inEntity, Class<?> inTargetClass, float inDistance, boolean inShouldCheckSight, boolean inShouldMelee, int inChance, IEntitySelector inSelector)
  37.     {
  38.         super(inEntity, inDistance, inShouldCheckSight, inShouldMelee);
  39.         this.m_comparator = new DistanceComparator(null, this.getEntityHandle());
  40.         this.m_targetChance = inChance;
  41.        
  42.         if(Entity.class.isAssignableFrom(inTargetClass))
  43.             this.m_targetClass = (Class<? extends Entity>)inTargetClass;
  44.         else
  45.             this.m_targetClass = (Class<? extends Entity>)NMSClassMap.getNMSClass(inTargetClass);
  46.    
  47.         this.m_onlyAtNight = false;
  48.         this.m_type = DesireType.PRIMAL_INSTINCT;
  49.     }
  50.  
  51.    
  52.     @SuppressWarnings("unchecked")
  53.     @Override
  54.     public boolean shouldExecute()
  55.     {
  56.         if(this.getEntityHandle() == null)
  57.             return false;
  58.    
  59.         if(this.m_onlyAtNight && this.getEntityHandle().world.v())
  60.             return false;
  61.         else if(this.m_targetChance > 0 && this.getEntityHandle().aE().nextInt(this.m_targetChance) != 0)
  62.             return false;
  63.         else
  64.         {
  65.             if(this.m_targetClass == EntityHuman.class)
  66.             {
  67.                 EntityHuman human = this.getEntityHandle().world.findNearbyVulnerablePlayer(this.getEntityHandle(), this.m_distance);
  68.                 Bukkit.broadcastMessage(FM.getFactionTag((Player) human));
  69.                 Bukkit.broadcastMessage(this.getRemoteEntity().getBukkitEntity().getCustomName().split("[")[0]);
  70.                
  71.                 if(this.isSuitableTarget(human, false) && FM.getFactionTag((Player) human).equals(this.getRemoteEntity().getBukkitEntity().getCustomName().split("[")[0]))
  72.                 {
  73.                 this.m_target = human;
  74.                 return true;
  75.                 }
  76.             }
  77.     return false;
  78.     }
  79.     }
  80.    
  81.     @Override
  82.     public void startExecuting()
  83.     {
  84.         this.getEntityHandle().setGoalTarget(this.m_target);
  85.         super.startExecuting();
  86.     }
  87.    
  88.     @Override
  89.     public ParameterData[] getSerializeableData()
  90.     {
  91.         return ReflectionUtil.getParameterDataForClass(this).toArray(new ParameterData[0]);
  92.     }
  93.  
  94.    
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement