Advertisement
Guest User

Untitled

a guest
Jul 1st, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.84 KB | None | 0 0
  1. package darkevilmac.karma.effect
  2.  
  3. import java.util.ArrayList
  4.  
  5. import cpw.mods.fml.common.eventhandler.SubscribeEvent
  6. import cpw.mods.fml.relauncher.{ReflectionHelper, Side}
  7. import darkevilmac.karma.tools.KarmaUtils
  8. import net.minecraft.entity.player.EntityPlayer
  9. import net.minecraft.entity.{EntityLiving, EntityLivingBase}
  10. import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent
  11.  
  12. /**
  13.  * Created by Darkevilmac on 6/25/2014.
  14.  */
  15. class MobIgnoreEffect extends KarmaEffect {
  16.  
  17.   var playersToCheck: ArrayList[String] = new ArrayList[String]()
  18.  
  19.   def init(player: String, side: Side) {
  20.     playersToCheck.add(player)
  21.   }
  22.  
  23.   def onUpdate(player: EntityPlayer, side: Side) {
  24.   }
  25.  
  26.   def finish(player: String, side: Side) {
  27.     var i: Int = 0
  28.     while (i < playersToCheck.size()) {
  29.       if (playersToCheck.get(i) == player) {
  30.         playersToCheck.remove(i)
  31.         return
  32.       }
  33.       i = i + 1;
  34.     }
  35.   }
  36.  
  37.   def shouldContinue(player: EntityPlayer, side: Side): Boolean = {
  38.     return KarmaUtils.getPlayerKarma(player) >= 950
  39.   }
  40.  
  41.   def canApply(player: EntityPlayer): Boolean = {
  42.     return KarmaUtils.getPlayerKarma(player) >= 950
  43.   }
  44.  
  45.   @SubscribeEvent
  46.   def onLivingSetAttackTarget(e: LivingSetAttackTargetEvent) {
  47.     if (e.target.isInstanceOf[EntityPlayer] && e.entityLiving.isInstanceOf[EntityLiving]) {
  48.       val entityLiving: EntityLiving = e.entityLiving.asInstanceOf[EntityLiving]
  49.       val entityLivingBase: EntityLivingBase = entityLiving.asInstanceOf[EntityLivingBase]
  50.       val entityPlayer: EntityPlayer = e.target.asInstanceOf[EntityPlayer]
  51.       if (playersToCheck.contains(entityPlayer.getCommandSenderName)) {
  52.         entityLiving.setAttackTarget(null)
  53.         ReflectionHelper.setPrivateValue(classOf[EntityLivingBase], entityLivingBase, null, "entityLivingToAttack")
  54.       }
  55.     }
  56.   }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement