Merge branch 'master' of github.com:mcMMO-Dev/mcMMO

This commit is contained in:
nossr50 2021-04-08 13:26:36 -07:00
commit 483d23c04d

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 (!(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);
} }
/** /**