use of org.bukkit.event.entity.EntityDamageEvent in project AllMiniGames by MiniGameWorlds.
the class Dropper method onEvent.
@Override
protected void onEvent(Event event) {
if (event instanceof EntityDamageEvent) {
EntityDamageEvent e = (EntityDamageEvent) event;
Player p = (Player) e.getEntity();
boolean isDead = p.getHealth() <= e.getDamage();
if (isDead) {
e.setDamage(0);
PlayerTool.makePureState(p);
if (!checkBelowBlock(p)) {
// respawn
p.teleport(getLocation());
}
}
}
}
use of org.bukkit.event.entity.EntityDamageEvent in project AllMiniGames by MiniGameWorlds.
the class LavaUp method onEvent.
@Override
protected void onEvent(Event event) {
if (event instanceof EntityDamageEvent) {
EntityDamageEvent damageEvent = (EntityDamageEvent) event;
checkPlayerIsDead(damageEvent);
if (damageEvent instanceof EntityDamageByEntityEvent) {
cancelPlayerHitDamage((EntityDamageByEntityEvent) damageEvent);
}
}
}
use of org.bukkit.event.entity.EntityDamageEvent in project Bukkit by Bukkit.
the class KillCommand method execute.
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender))
return true;
if (sender instanceof Player) {
Player player = (Player) sender;
EntityDamageEvent ede = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.SUICIDE, 1000);
Bukkit.getPluginManager().callEvent(ede);
if (ede.isCancelled())
return true;
ede.getEntity().setLastDamageCause(ede);
player.setHealth(0);
sender.sendMessage("Ouch. That look like it hurt.");
} else {
sender.sendMessage("You can only perform this command as a player");
}
return true;
}
use of org.bukkit.event.entity.EntityDamageEvent in project Glowstone by GlowstoneMC.
the class GlowLivingEntity method damage.
@Override
public void damage(double amount, Entity source, @NotNull DamageCause cause) {
// invincibility timer
if (noDamageTicks > 0 || health <= 0 || !canTakeDamage(cause) || isInvulnerable()) {
return;
} else {
noDamageTicks = maximumNoDamageTicks;
}
// fire resistance
if (hasPotionEffect(PotionEffectType.FIRE_RESISTANCE)) {
if (source instanceof Fireball) {
return;
} else {
switch(cause) {
case FIRE:
case FIRE_TICK:
case HOT_FLOOR:
case LAVA:
return;
default:
}
}
}
// armor damage protection
// formula source: http://minecraft.gamepedia.com/Armor#Damage_Protection
double defensePoints = getAttributeManager().getPropertyValue(Key.KEY_ARMOR);
double toughness = getAttributeManager().getPropertyValue(Key.KEY_ARMOR_TOUGHNESS);
amount = amount * (1 - Math.min(20.0, Math.max(defensePoints / 5.0, defensePoints - amount / (2.0 + toughness / 4.0))) / 25);
// fire event
EntityDamageEvent event = EventFactory.getInstance().onEntityDamage(source == null ? new EntityDamageEvent(this, cause, amount) : new EntityDamageByEntityEvent(source, this, cause, amount));
if (event.isCancelled()) {
return;
}
// apply damage
amount = event.getFinalDamage();
lastDamage = amount;
if (isPlayerHit(source)) {
playerDamageTick = ticksLived;
if (health - amount <= 0) {
killer = determinePlayer(source);
if (killer != null) {
killer.incrementStatistic(Statistic.KILL_ENTITY, getType());
}
}
}
setHealth(health - amount);
playEffectKnownAndSelf(EntityEffect.HURT);
if (cause == DamageCause.ENTITY_ATTACK && source != null) {
Vector distance = RayUtil.getRayBetween(getLocation(), ((LivingEntity) source).getEyeLocation());
Vector rayLength = RayUtil.getVelocityRay(distance).normalize();
Vector currentVelocity = getVelocity();
currentVelocity.add(rayLength.multiply(((amount + 1) / 2d)));
setVelocity(currentVelocity);
}
// play sounds, handle death
if (health > 0) {
Sound hurtSound = getHurtSound();
if (hurtSound != null && !isSilent()) {
world.playSound(location, hurtSound, getSoundVolume(), getSoundPitch());
}
}
setLastDamager(source);
}
use of org.bukkit.event.entity.EntityDamageEvent in project MyMaid2 by jaoafa.
the class Event_CommandBlockVariable method onCommandBlockCall.
@EventHandler
public void onCommandBlockCall(ServerCommandEvent event) {
if (!(event.getSender() instanceof BlockCommandSender))
return;
BlockCommandSender sender = (BlockCommandSender) event.getSender();
if (sender.getBlock() == null || !(sender.getBlock().getState() instanceof CommandBlock))
return;
CommandBlock cmdb = (CommandBlock) sender.getBlock().getState();
String command = cmdb.getCommand();
// 最初に$が入ってたら変数入りコマンド
if (!command.startsWith("$"))
return;
// $を消す
command = StringUtils.stripStart(command, "$");
// /を消す
command = StringUtils.stripStart(command, "/");
// 「@p」のみ置き換える動作をする
if (sender instanceof Player) {
Player player = (Player) sender;
NearestPlayer npr = new NearestPlayer(player.getLocation());
if (npr.getStatus()) {
command = command.replaceAll("@" + "p" + "", npr.getPlayer().getName());
}
} else if (sender instanceof BlockCommandSender) {
NearestPlayer npr = new NearestPlayer(cmdb.getBlock().getLocation());
if (npr.getStatus()) {
command = command.replaceAll("@" + "p" + "", npr.getPlayer().getName());
}
}
// ----- 事前定義(予約済み変数) ----- //
SimpleDateFormat sdf_Year = new SimpleDateFormat("yyyy");
command = command.replaceAll("\\$" + "DateTime_Year" + "\\$", sdf_Year.format(new Date()));
SimpleDateFormat sdf_Month = new SimpleDateFormat("MM");
command = command.replaceAll("\\$" + "DateTime_Month" + "\\$", sdf_Month.format(new Date()));
SimpleDateFormat sdf_Day = new SimpleDateFormat("dd");
command = command.replaceAll("\\$" + "DateTime_Day" + "\\$", sdf_Day.format(new Date()));
SimpleDateFormat sdf_Hour = new SimpleDateFormat("HH");
command = command.replaceAll("\\$" + "DateTime_Hour" + "\\$", sdf_Hour.format(new Date()));
SimpleDateFormat sdf_Minute = new SimpleDateFormat("mm");
command = command.replaceAll("\\$" + "DateTime_Minute" + "\\$", sdf_Minute.format(new Date()));
SimpleDateFormat sdf_Second = new SimpleDateFormat("ss");
command = command.replaceAll("\\$" + "DateTime_Second" + "\\$", sdf_Second.format(new Date()));
command = command.replaceAll("\\$" + "PlayerCount" + "\\$", String.valueOf(Bukkit.getServer().getOnlinePlayers().size()));
for (Player p : Bukkit.getOnlinePlayers()) {
if (!command.contains("$" + "Damager_" + p.getName() + "$")) {
continue;
}
EntityDamageEvent ede = p.getLastDamageCause();
if (ede == null) {
continue;
}
Entity e = ede.getEntity();
if (e == null) {
continue;
}
String name = e.getName();
command = command.replaceAll("\\$" + "Damager_" + p.getName() + "\\$", name);
}
ScoreboardManager sbm = Bukkit.getScoreboardManager();
Scoreboard sb = sbm.getMainScoreboard();
for (Objective obj : sb.getObjectives()) {
String regex = "\\$Score_" + obj.getName() + "_(.+?)\\$";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(command);
while (m.find()) {
Score i = obj.getScore(m.group(1));
if (i == null) {
continue;
}
command = command.replaceAll("\\$" + "Score_" + obj.getName() + "_" + m.group(1) + "\\$", "" + i.getScore());
}
}
// ----- 事前定義(予約済み変数) ----- //
Map<String, String> map = MyMaidVariable.listALL();
for (Map.Entry<String, String> e : map.entrySet()) {
command = command.replaceAll("\\$" + e.getKey() + "\\$", e.getValue());
}
Bukkit.dispatchCommand(sender, command);
}
Aggregations