MobHealth Code

Select a file to view contents.

.classpath
.gitignore
.project
.settings/org.eclipse.core.resources.prefs
README.md
bin/me/sablednah/MobHealth/API/MobHealthAPI.class
bin/me/sablednah/MobHealth/HeroesEventListener.class
bin/me/sablednah/MobHealth/MessageScheduler.class
bin/me/sablednah/MobHealth/Metrics$1.class
bin/me/sablednah/MobHealth/Metrics$Graph.class
bin/me/sablednah/MobHealth/Metrics$Plotter.class
bin/me/sablednah/MobHealth/Metrics.class
bin/me/sablednah/MobHealth/MobHealth$1.class
bin/me/sablednah/MobHealth/MobHealth.class
bin/me/sablednah/MobHealth/MobHealthCommandExecutor.class
bin/me/sablednah/MobHealth/NewWidgitActions.class
bin/me/sablednah/MobHealth/SaveToggle.class
bin/me/sablednah/MobHealth/ServerDamageEntityListener$ScheduledshowBar.class
bin/me/sablednah/MobHealth/ServerDamageEntityListener.class
bin/me/sablednah/MobHealth/SetHealth.class
bin/me/sablednah/MobHealth/SkillMessageScheduler.class
bin/me/sablednah/MobHealth/SpoutNotifications.class
bin/me/sablednah/MobHealth/Updater$UpdateResult.class
bin/me/sablednah/MobHealth/Updater$UpdateRunnable.class
bin/me/sablednah/MobHealth/Updater$UpdateType.class
bin/me/sablednah/MobHealth/Updater.class
licence.txt
pom.xml
src/main/java/me/sablednah/MobHealth/API/ActionBar.java
src/main/java/me/sablednah/MobHealth/API/ActionBar_1_8_1.java
src/main/java/me/sablednah/MobHealth/API/ActionBar_1_8_3.java
src/main/java/me/sablednah/MobHealth/API/ActionBar_1_8_4.java
src/main/java/me/sablednah/MobHealth/API/MobHealthAPI.java
src/main/java/me/sablednah/MobHealth/API/PlayerHealthEvent.java
src/main/java/me/sablednah/MobHealth/HeroesEventListener.java
src/main/java/me/sablednah/MobHealth/MessageScheduler.java
src/main/java/me/sablednah/MobHealth/Metrics.java
src/main/java/me/sablednah/MobHealth/MobHealth.java
src/main/java/me/sablednah/MobHealth/MobHealthCommandExecutor.java
src/main/java/me/sablednah/MobHealth/NewWidgitActions.java
src/main/java/me/sablednah/MobHealth/SaveToggle.java
src/main/java/me/sablednah/MobHealth/ServerDamageEntityListener.java
src/main/java/me/sablednah/MobHealth/SetHealth.java
src/main/java/me/sablednah/MobHealth/SkillMessageScheduler.java
src/main/java/me/sablednah/MobHealth/SpoutNotifications.java
src/main/java/me/sablednah/MobHealth/Updater.java
src/main/resources/config.yml
src/main/resources/lang.yml
src/main/resources/players.yml
src/main/resources/plugin.yml


/*
 * This file is part of MobHealth.
 * Copyright (C) 2012-2013 Darren Douglas - [email protected]
 *
 * MobHealth is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MobHealth is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MobHealth.  If not, see <http://www.gnu.org/licenses/>.
 */

package main.java.me.sablednah.MobHealth;

import main.java.me.sablednah.MobHealth.API.MobHealthAPI;

import org.bukkit.entity.Ambient;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Egg;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Golem;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.NPC;
import org.bukkit.entity.Player;
import org.bukkit.entity.Snowball;
import org.bukkit.entity.WaterMob;
import org.bukkit.event.entity.EntityDamageByEntityEvent;

import com.herocraftonline.heroes.api.events.*;

public class MessageScheduler implements Runnable {
    
    private Player player;
    private EntityDamageByEntityEvent damageEvent;
    private WeaponDamageEvent weaponDamageEvent;
    private LivingEntity targetMob;
    private Entity damagerMob;
    public MobHealth plugin;
    private int HealthBefore;
    private int DamageBefore;
    
    public MessageScheduler(Player shooter, EntityDamageByEntityEvent damageEvent, LivingEntity targetMob, int HealthBefore, int DamageBefore, MobHealth plugin) {
        this.plugin = plugin;
        this.damageEvent = damageEvent;
        this.player = shooter;
        this.targetMob = targetMob;
        this.HealthBefore = HealthBefore;
        this.DamageBefore = DamageBefore;
    }
    
    public MessageScheduler(Player shooter, WeaponDamageEvent weaponDamageEvent, LivingEntity targetMob, int HealthBefore, int DamageBefore, MobHealth plugin) {
        this.plugin = plugin;
        this.weaponDamageEvent = weaponDamageEvent;
        this.player = shooter;
        this.targetMob = targetMob;
        this.HealthBefore = HealthBefore;
        this.DamageBefore = DamageBefore;
    }
    
    public void run() {
        
        int thisDamange = 0, mobsHealth = 0, mobsMaxHealth = 0, damageTaken = 0, damageResisted = 0;
        Boolean isPlayer = false, isMonster = false, isAnimal = false;
        String damageOutput;
        
        MobHealthAPI API = new MobHealthAPI(plugin);
        
        /* thisDamange = damageEvent.getDamage(); if (thisDamange > 200) { thisDamange = DamageBefore; } */
        thisDamange = DamageBefore;
        
        mobsMaxHealth = API.getMobMaxHealth(targetMob);
        mobsHealth = API.getMobHealth(targetMob);
        if (mobsHealth < -50) { // hack to deal with mods using overkill
            mobsHealth = 0;
        }
        
        damageTaken = HealthBefore - mobsHealth;
        if (damageTaken > 9950) { // heroes hacky fix
            damageTaken = thisDamange;
        }
        damageResisted = thisDamange - damageTaken;
        
        // I need a Hero!
        if (weaponDamageEvent != null) {
            damagerMob = (Entity) weaponDamageEvent.getDamager().getEntity();
        } else {
            damagerMob = damageEvent.getDamager();
        }
        
        if (MobHealth.debugMode) {
            System.out.print("--");
            
            if (damageEvent != null) {
                System.out.print("[MobHealth] " + damageEvent.getDamage() + " damageEvent.getDamage();.");
            }
            if (weaponDamageEvent != null) {
                System.out.print("[MobHealth] " + weaponDamageEvent.getDamage() + " weaponDamageEvent.getDamage();.");
            }
            System.out.print("[MobHealth] " + DamageBefore + " DamageBefore.");
            System.out.print("[MobHealth] " + thisDamange + " thisDamange.");
            System.out.print("[MobHealth] " + mobsHealth + " mobsHealth.");
            System.out.print("[MobHealth] " + mobsMaxHealth + " mobsMaxHealth.");
            System.out.print("[MobHealth] " + HealthBefore + " HealthBefore.");
            System.out.print("[MobHealth] " + damageTaken + " damageTaken.");
            System.out.print("[MobHealth] " + damageResisted + " damageResisted.");
            System.out.print("[MobHealth] " + targetMob.getLastDamage() + " targetMob.getLastDamage().");
            System.out.print("[MobHealth] " + targetMob.getHealth() + " targetMob.getHealth().");
            System.out.print("[MobHealth] " + damagerMob + " damagerMob.");
        }
        
        String mobtype = API.getMobName(targetMob);
        
        if (targetMob instanceof Player) {
            isPlayer = true;
        } else {
            if (targetMob instanceof Animals || targetMob instanceof Ambient || targetMob instanceof WaterMob || targetMob instanceof Golem || targetMob instanceof NPC) {
                isAnimal = true;
            } else {
                isMonster = true;
            }
        }
        String skillname = null;
        
        if(targetMob.hasMetadata("HeroesSkillDamaged")) {
            skillname = targetMob.getMetadata("HeroesSkillDamaged").get(0).asString();
            targetMob.removeMetadata("HeroesSkillDamaged", plugin);
        }
        
        switch (MobHealth.damageDisplayType) {
            case 4: // # 4: display damage taken (+amount resisted)
                damageOutput = Integer.toString(damageTaken);
                if (damageResisted > 0)
                    damageOutput += "(+" + damageResisted + ")";
                break;
            case 3: // # 3: display damage inflicted (-amount resisted)
                damageOutput = Integer.toString(thisDamange);
                if (damageResisted > 0)
                    damageOutput += "(-" + damageResisted + ")";
                break;
            case 2: // # 2: display damage taken.
                damageOutput = Integer.toString(damageTaken);
                break;
            default: // # 1: display damage inflicted.
                damageOutput = Integer.toString(thisDamange);
        }
        
        Boolean checkForZeroDamageHide = true;
        
        if (damagerMob instanceof Egg && (!(plugin.getLangConfig().getString("chatMessageEgg") == null))) {
            checkForZeroDamageHide = false;
        } else if (damagerMob instanceof Snowball && (!(plugin.getLangConfig().getString("chatMessageSnowball") == null))) {
            checkForZeroDamageHide = false;
        } else if ((MobHealth.hideNoDammage && (damageTaken > 0)) || !MobHealth.hideNoDammage) {
            checkForZeroDamageHide = false;
        }
        
        if (MobHealth.debugMode) {
            if (isPlayer) {
                System.out.print("Is Player");
            } else {
                System.out.print("Is not Player");
            }
            if (isAnimal) {
                System.out.print("Is Animal");
            } else {
                System.out.print("Is not Animal");
            }
            if (isMonster) {
                System.out.print("Is Monster");
            } else {
                System.out.print("Is not Monster");
            }
            if (checkForZeroDamageHide) {
                System.out.print("Hide " + damageTaken + " damage");
            } else {
                System.out.print("Show " + damageTaken + " damage");
            }
        }
        
        if (((MobHealth.disablePlayers && !isPlayer) || !MobHealth.disablePlayers) && ((MobHealth.disableMonsters && !isMonster) || !MobHealth.disableMonsters)
                && ((MobHealth.disableAnimals && !isAnimal) || !MobHealth.disableAnimals) && (!checkForZeroDamageHide)) {            
            API.showNotification(player, damageOutput, mobtype, mobsHealth, mobsMaxHealth, skillname, damagerMob);
        }
        
        if (MobHealth.showPlayerHeadHealth || MobHealth.showMobHeadHealth) {
            API.showBar(targetMob);
        }

    }
}

Leave a Reply