use of cat.nyaa.nyaacore.Message in project InfernalMobs by NyaaCat.
the class EventListener method onEntityDeath.
@EventHandler(priority = EventPriority.HIGH)
public void onEntityDeath(final EntityDeathEvent event) {
UUID id = event.getEntity().getUniqueId();
Mob mob = plugin.mobManager.mobMap.get(id);
if (mob == null)
return;
LivingEntity mobEntity = event.getEntity();
for (EnumAbilities ab : mob.abilityList) {
ab.onDeath(mobEntity, mob, mobEntity.getKiller(), event);
}
// item drop decision
ItemStack selectedDropItem = null;
Player killer = mobEntity.getKiller();
if (determineShouldDrop(killer != null, (killer != null) && (killer.getGameMode() == GameMode.CREATIVE))) {
ItemStack drop = this.plugin.lootManager.getRandomLoot(killer, mob.getMobLevel());
if (drop != null && drop.getType() != Material.AIR) {
final int min = 1;
final int max = ConfigReader.getDropChance();
final int randomNum = new Random().nextInt(max - min + 1) + min;
if (randomNum == 1) {
event.getDrops().add(drop);
selectedDropItem = drop;
}
}
}
// set xp drop
final int xpm = ConfigReader.getXpMultiplier();
final int xp = event.getDroppedExp() * xpm;
event.setDroppedExp(xp);
// broadcast death message TODO use ConfigReader
if (ConfigReader.isMobDeathMessageEnabled() && event.getEntity().getKiller() != null) {
Player player = event.getEntity().getKiller();
String playerName = player.getName();
String mobName;
if (event.getEntity().getCustomName() != null) {
mobName = event.getEntity().getCustomName();
} else {
mobName = event.getEntity().getType().name();
}
boolean broadcastToAllWorld = ConfigReader.isDeathMessageBroadcastAllWorld();
if (this.plugin.getConfig().getList("deathMessages") != null) {
String deathMessage = Helper.randomItem(plugin.getConfig().getStringList("deathMessages"));
deathMessage = ChatColor.translateAlternateColorCodes('&', deathMessage);
deathMessage = deathMessage.replace("{player}", playerName);
deathMessage = deathMessage.replace("{mob}", mobName);
ItemStack item = player.getInventory().getItemInMainHand();
if (item != null && !item.getType().equals(Material.AIR)) {
if (broadcastToAllWorld) {
new Message("").append(deathMessage, item).broadcast();
} else {
new Message("").append(deathMessage, item).broadcast(player.getLocation().getWorld());
}
} else {
if (broadcastToAllWorld) {
new Message(deathMessage.replace("{itemName}", "fist").replace("{itemName:0}", "fist")).broadcast();
} else {
new Message(deathMessage.replace("{itemName}", "fist").replace("{itemName:0}", "fist")).broadcast(player.getLocation().getWorld());
}
}
} else {
System.out.println("No valid death messages found!");
}
if (plugin.getConfig().isList("dropMessages") && selectedDropItem != null) {
String msg = Helper.randomItem(plugin.getConfig().getStringList("dropMessages"));
msg = ChatColor.translateAlternateColorCodes('&', msg);
msg = msg.replace("{player}", playerName);
msg = msg.replace("{mob}", mobName);
if (broadcastToAllWorld) {
new Message("").append(msg, selectedDropItem).broadcast();
} else {
new Message("").append(msg, selectedDropItem).broadcast(player.getLocation().getWorld());
}
}
if (plugin.getConfig().isList("nodropMessages") && selectedDropItem == null) {
String msg = Helper.randomItem(plugin.getConfig().getStringList("nodropMessages"));
msg = ChatColor.translateAlternateColorCodes('&', msg);
msg = msg.replace("{player}", playerName);
msg = msg.replace("{mob}", mobName);
if (broadcastToAllWorld) {
new Message(msg).broadcast();
} else {
new Message(msg).broadcast(player.getLocation().getWorld());
}
}
}
plugin.mobManager.mobMap.remove(id);
// TODO event
}
Aggregations