Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package darkevilmac.karma.effect
- import java.util.ArrayList
- import cpw.mods.fml.common.eventhandler.SubscribeEvent
- import cpw.mods.fml.relauncher.{ReflectionHelper, Side}
- import darkevilmac.karma.tools.KarmaUtils
- import net.minecraft.entity.player.EntityPlayer
- import net.minecraft.entity.{EntityLiving, EntityLivingBase}
- import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent
- /**
- * Created by Darkevilmac on 6/25/2014.
- */
- class MobIgnoreEffect extends KarmaEffect {
- var playersToCheck: ArrayList[String] = new ArrayList[String]()
- def init(player: String, side: Side) {
- playersToCheck.add(player)
- }
- def onUpdate(player: EntityPlayer, side: Side) {
- }
- def finish(player: String, side: Side) {
- var i: Int = 0
- while (i < playersToCheck.size()) {
- if (playersToCheck.get(i) == player) {
- playersToCheck.remove(i)
- return
- }
- i = i + 1;
- }
- }
- def shouldContinue(player: EntityPlayer, side: Side): Boolean = {
- return KarmaUtils.getPlayerKarma(player) >= 950
- }
- def canApply(player: EntityPlayer): Boolean = {
- return KarmaUtils.getPlayerKarma(player) >= 950
- }
- @SubscribeEvent
- def onLivingSetAttackTarget(e: LivingSetAttackTargetEvent) {
- if (e.target.isInstanceOf[EntityPlayer] && e.entityLiving.isInstanceOf[EntityLiving]) {
- val entityLiving: EntityLiving = e.entityLiving.asInstanceOf[EntityLiving]
- val entityLivingBase: EntityLivingBase = entityLiving.asInstanceOf[EntityLivingBase]
- val entityPlayer: EntityPlayer = e.target.asInstanceOf[EntityPlayer]
- if (playersToCheck.contains(entityPlayer.getCommandSenderName)) {
- entityLiving.setAttackTarget(null)
- ReflectionHelper.setPrivateValue(classOf[EntityLivingBase], entityLivingBase, null, "entityLivingToAttack")
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement