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);
}
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);
}
}
}
}
Aggregations