From 2d3249b15f2d240258ee7ffbb018d0e1e462fcf2 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Sun, 20 Mar 2022 15:16:09 +0100 Subject: [PATCH] Fixed an issue with exp holos --- .../java/net/Indyuce/mmocore/api/player/PlayerData.java | 2 +- .../java/net/Indyuce/mmocore/api/util/MMOCoreUtils.java | 8 ++++++++ .../mmocore/experience/dispenser/ExperienceDispenser.java | 4 +++- .../experience/source/KillMobExperienceSource.java | 3 ++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 5e0c6ee5..5499c244 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -538,7 +538,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc // Experience hologram if (hologramLocation != null && isOnline()) - MMOCoreUtils.displayIndicator(hologramLocation.add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message()); + MMOCoreUtils.displayIndicator(hologramLocation, MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message()); value = MMOCore.plugin.boosterManager.calculateExp(null, value); value *= 1 + getStats().getStat(StatType.ADDITIONAL_EXPERIENCE) / 100; diff --git a/src/main/java/net/Indyuce/mmocore/api/util/MMOCoreUtils.java b/src/main/java/net/Indyuce/mmocore/api/util/MMOCoreUtils.java index 869fa6be..b15bb60a 100644 --- a/src/main/java/net/Indyuce/mmocore/api/util/MMOCoreUtils.java +++ b/src/main/java/net/Indyuce/mmocore/api/util/MMOCoreUtils.java @@ -65,6 +65,7 @@ public class MMOCoreUtils { */ public static void displayIndicator(Location loc, String message) { Hologram holo = Hologram.create(Position.of(loc), Arrays.asList(message)); + holo.spawn(); Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> holo.despawn(), 20); } @@ -212,4 +213,11 @@ public class MMOCoreUtils { item.setItemMeta(meta); } } + + /** + * @return Center location of an entity using its bounding box + */ + public static Location getCenterLocation(Entity entity) { + return entity.getBoundingBox().getCenter().toLocation(entity.getWorld()); + } } diff --git a/src/main/java/net/Indyuce/mmocore/experience/dispenser/ExperienceDispenser.java b/src/main/java/net/Indyuce/mmocore/experience/dispenser/ExperienceDispenser.java index cdc266da..5ac9eac0 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/dispenser/ExperienceDispenser.java +++ b/src/main/java/net/Indyuce/mmocore/experience/dispenser/ExperienceDispenser.java @@ -1,6 +1,7 @@ package net.Indyuce.mmocore.experience.dispenser; import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.Indyuce.mmocore.experience.EXPSource; import org.bukkit.Location; import org.jetbrains.annotations.NotNull; @@ -37,7 +38,8 @@ public interface ExperienceDispenser { */ boolean shouldHandle(PlayerData playerData); + @Nullable default Location getPlayerLocation(PlayerData player) { - return player.isOnline() ? player.getPlayer().getLocation() : null; + return player.isOnline() ? MMOCoreUtils.getCenterLocation(player.getPlayer()) : null; } } diff --git a/src/main/java/net/Indyuce/mmocore/experience/source/KillMobExperienceSource.java b/src/main/java/net/Indyuce/mmocore/experience/source/KillMobExperienceSource.java index 82742749..3596a77d 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/source/KillMobExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/experience/source/KillMobExperienceSource.java @@ -4,6 +4,7 @@ import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.event.PlayerKillEntityEvent; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser; import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource; import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager; @@ -34,7 +35,7 @@ public class KillMobExperienceSource extends SpecificExperienceSource { for (KillMobExperienceSource source : getSources()) if (source.matches(data, event.getTarget())) - source.giveExperience(data, 1, event.getTarget().getLocation()); + source.giveExperience(data, 1, MMOCoreUtils.getCenterLocation(event.getTarget())); } }, 2); }