Fix death messages losing formatting (#4482)

This commit is contained in:
lexikiq 2021-04-08 16:25:24 -04:00 committed by GitHub
parent 74d0d2c3f9
commit 80aac93fd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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(WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld())) if (!(event.getEntity() instanceof Player))
return;
if (!(event.getDamager() instanceof LivingEntity))
return;
// world blacklist check
if (WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld()))
return;
// world guard main flag check
if (WorldGuardUtils.isWorldGuardLoaded() && !WorldGuardManager.getInstance().hasMainFlag((Player) event.getEntity()))
return; return;
String deathMessage = event.getDeathMessage(); Player player = (Player) event.getEntity();
LivingEntity attacker = (LivingEntity) event.getDamager();
/* WORLD GUARD MAIN FLAG CHECK */ // we only want to handle player deaths
if(WorldGuardUtils.isWorldGuardLoaded()) if ((player.getHealth() - event.getFinalDamage()) > 0)
{
if(!WorldGuardManager.getInstance().hasMainFlag(event.getEntity()))
return; return;
// temporarily clear the mob's name
new MobHealthDisplayUpdaterTask(attacker).run();
// set the name back
new BukkitRunnable() {
@Override
public void run() {
MobHealthbarUtils.handleMobHealthbars(attacker, 0, mcMMO.p);
} }
}.runTaskLater(mcMMO.p, 1);
if (deathMessage == null) {
return;
}
Player player = event.getEntity();
event.setDeathMessage(MobHealthbarUtils.fixDeathMessage(deathMessage, player));
} }
/** /**