mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 07:06:45 +01:00
Fix death messages losing formatting (#4482)
This commit is contained in:
parent
74d0d2c3f9
commit
80aac93fd2
@ -12,6 +12,7 @@ import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
|
|||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.party.ShareHandler;
|
import com.gmail.nossr50.party.ShareHandler;
|
||||||
|
import com.gmail.nossr50.runnables.MobHealthDisplayUpdaterTask;
|
||||||
import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask;
|
import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask;
|
||||||
import com.gmail.nossr50.skills.fishing.FishingManager;
|
import com.gmail.nossr50.skills.fishing.FishingManager;
|
||||||
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
|
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
|
||||||
@ -35,6 +36,7 @@ import org.bukkit.GameMode;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.conversations.Conversation;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.*;
|
||||||
import org.bukkit.entity.minecart.PoweredMinecart;
|
import org.bukkit.entity.minecart.PoweredMinecart;
|
||||||
@ -43,11 +45,13 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.event.player.*;
|
import org.bukkit.event.player.*;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@ -104,36 +108,46 @@ public class PlayerListener implements Listener {
|
|||||||
|
|
||||||
UserManager.getPlayer(player).actualizeTeleportATS();
|
UserManager.getPlayer(player).actualizeTeleportATS();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle PlayerDeathEvents at the lowest priority.
|
* Handle {@link EntityDamageByEntityEvent} at the highest priority.
|
||||||
* <p>
|
* <p>
|
||||||
* These events are used to modify the death message of a player when
|
* This handler is used to clear the names of mobs with health bars to
|
||||||
* needed to correct issues potentially caused by the custom naming used
|
* fix death messages showing mob health bars on death.
|
||||||
* for mob healthbars.
|
|
||||||
*
|
*
|
||||||
* @param event The event to modify
|
* @param event the event to listen to
|
||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onPlayerDeathLowest(PlayerDeathEvent event) {
|
public void onEntityDamageByEntityHighest(EntityDamageByEntityEvent event) {
|
||||||
/* WORLD BLACKLIST CHECK */
|
// we only care about players as this is for fixing player death messages
|
||||||
|
if (!(event.getEntity() instanceof Player))
|
||||||
|
return;
|
||||||
|
if (!(event.getDamager() instanceof LivingEntity))
|
||||||
|
return;
|
||||||
|
// world blacklist check
|
||||||
if (WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld()))
|
if (WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld()))
|
||||||
return;
|
return;
|
||||||
|
// world guard main flag check
|
||||||
String deathMessage = event.getDeathMessage();
|
if (WorldGuardUtils.isWorldGuardLoaded() && !WorldGuardManager.getInstance().hasMainFlag((Player) event.getEntity()))
|
||||||
|
|
||||||
/* WORLD GUARD MAIN FLAG CHECK */
|
|
||||||
if(WorldGuardUtils.isWorldGuardLoaded())
|
|
||||||
{
|
|
||||||
if(!WorldGuardManager.getInstance().hasMainFlag(event.getEntity()))
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (deathMessage == null) {
|
Player player = (Player) event.getEntity();
|
||||||
|
LivingEntity attacker = (LivingEntity) event.getDamager();
|
||||||
|
|
||||||
|
// we only want to handle player deaths
|
||||||
|
if ((player.getHealth() - event.getFinalDamage()) > 0)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
Player player = event.getEntity();
|
// temporarily clear the mob's name
|
||||||
event.setDeathMessage(MobHealthbarUtils.fixDeathMessage(deathMessage, player));
|
new MobHealthDisplayUpdaterTask(attacker).run();
|
||||||
|
|
||||||
|
// set the name back
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
MobHealthbarUtils.handleMobHealthbars(attacker, 0, mcMMO.p);
|
||||||
|
}
|
||||||
|
}.runTaskLater(mcMMO.p, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user