Search in sources :

Example 21 with GameMode

use of org.bukkit.GameMode in project Glowstone by GlowstoneMC.

the class GlowPlayer method setGameModeDefaults.

private void setGameModeDefaults() {
    GameMode mode = getGameMode();
    setAllowFlight(mode == GameMode.CREATIVE || mode == GameMode.SPECTATOR);
    metadata.setBit(MetadataIndex.STATUS, StatusFlags.INVISIBLE, mode == GameMode.SPECTATOR);
}
Also used : GameMode(org.bukkit.GameMode)

Example 22 with GameMode

use of org.bukkit.GameMode in project InfernalMobs by NyaaCat.

the class EventListener method onEntityAttack.

@EventHandler(priority = EventPriority.HIGH)
public void onEntityAttack(final EntityDamageByEntityEvent event) {
    // todo unexpected fireball damage
    boolean isDirectAttack = true;
    Entity trueVictim = event.getEntity();
    Entity trueAttacker = event.getDamager();
    if (trueAttacker instanceof Projectile) {
        isDirectAttack = false;
        ProjectileSource src = ((Projectile) trueAttacker).getShooter();
        if (src instanceof Entity) {
            trueAttacker = (Entity) src;
        } else {
            return;
        }
    }
    if (!(trueAttacker instanceof LivingEntity))
        return;
    if (!(trueVictim instanceof LivingEntity))
        return;
    if (plugin.mobManager.mobMap.containsKey(trueVictim.getUniqueId())) {
        // something attacked infernal mob
        if (!(trueAttacker instanceof Player))
            return;
        Mob mob = plugin.mobManager.mobMap.get(trueVictim.getUniqueId());
        mob.lastDamageCause = event;
        GameMode gameMode = ((Player) trueAttacker).getGameMode();
        if (gameMode != GameMode.CREATIVE && gameMode != GameMode.SPECTATOR) {
            for (EnumAbilities ab : mob.abilityList) {
                ab.onPlayerAttack((LivingEntity) trueVictim, mob, (Player) trueAttacker, isDirectAttack, event);
            }
        }
        if (ConfigReader.isEnhanceEnabled()) {
            double resistedDamage = ConfigReader.getLevelConfig().calcResistedDamage(event.getDamage(), mob.getMobLevel());
            event.setDamage(resistedDamage);
        }
    }
    if ((plugin.mobManager.mobMap.containsKey(trueAttacker.getUniqueId()))) {
        // infernal mob attacked something
        EntityDamageEvent.DamageCause cause = event.getCause();
        double originDamage = event.getDamage();
        Mob mob = plugin.mobManager.mobMap.get(trueAttacker.getUniqueId());
        if (isValidDamageCause(cause, mob)) {
            if ((trueVictim instanceof Player)) {
                GameMode gameMode = ((Player) trueVictim).getGameMode();
                if (gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR)
                    return;
                for (EnumAbilities ab : mob.abilityList) {
                    ab.onAttackPlayer((LivingEntity) trueAttacker, mob, (Player) trueVictim, isDirectAttack, event);
                }
            }
            double extraDamage = event.getDamage() - originDamage;
            if (ConfigReader.isEnhanceEnabled()) {
                LevelConfig levelConfig = ConfigReader.getLevelConfig();
                double damage = levelConfig.getDamage(originDamage, mob.getMobLevel());
                damage += extraDamage;
                event.setDamage(damage);
            }
        }
    }
}
Also used : Mob(com.jacob_vejvoda.infernal_mobs.persist.Mob) LevelConfig(com.jacob_vejvoda.infernal_mobs.config.LevelConfig) GameMode(org.bukkit.GameMode) ProjectileSource(org.bukkit.projectiles.ProjectileSource) EnumAbilities(com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities) EventHandler(org.bukkit.event.EventHandler)

Aggregations

GameMode (org.bukkit.GameMode)22 Player (org.bukkit.entity.Player)7 Location (org.bukkit.Location)3 ItemStack (org.bukkit.inventory.ItemStack)3 ModelFlying (fr.neatmonster.nocheatplus.checks.moving.model.ModelFlying)2 ResourceBundle (java.util.ResourceBundle)2 LocalizedStringImpl (net.glowstone.i18n.LocalizedStringImpl)2 Entity (org.bukkit.entity.Entity)2 EventHandler (org.bukkit.event.EventHandler)2 MinigameType (au.com.mineauz.minigames.gametypes.MinigameType)1 GameMechanicBase (au.com.mineauz.minigames.mechanics.GameMechanicBase)1 Callback (au.com.mineauz.minigames.menu.Callback)1 Menu (au.com.mineauz.minigames.menu.Menu)1 MenuItem (au.com.mineauz.minigames.menu.MenuItem)1 MenuItemAddFlag (au.com.mineauz.minigames.menu.MenuItemAddFlag)1 MenuItemBoolean (au.com.mineauz.minigames.menu.MenuItemBoolean)1 MenuItemCustom (au.com.mineauz.minigames.menu.MenuItemCustom)1 MenuItemDisplayLoadout (au.com.mineauz.minigames.menu.MenuItemDisplayLoadout)1 MenuItemDisplayWhitelist (au.com.mineauz.minigames.menu.MenuItemDisplayWhitelist)1 MenuItemFlag (au.com.mineauz.minigames.menu.MenuItemFlag)1