Fixed an issue with exp holos

This commit is contained in:
Indyuce 2022-03-20 15:16:09 +01:00
parent 735baac901
commit 2d3249b15f
4 changed files with 14 additions and 3 deletions

View File

@ -538,7 +538,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
// Experience hologram // Experience hologram
if (hologramLocation != null && isOnline()) 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 = MMOCore.plugin.boosterManager.calculateExp(null, value);
value *= 1 + getStats().getStat(StatType.ADDITIONAL_EXPERIENCE) / 100; value *= 1 + getStats().getStat(StatType.ADDITIONAL_EXPERIENCE) / 100;

View File

@ -65,6 +65,7 @@ public class MMOCoreUtils {
*/ */
public static void displayIndicator(Location loc, String message) { public static void displayIndicator(Location loc, String message) {
Hologram holo = Hologram.create(Position.of(loc), Arrays.asList(message)); Hologram holo = Hologram.create(Position.of(loc), Arrays.asList(message));
holo.spawn();
Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> holo.despawn(), 20); Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> holo.despawn(), 20);
} }
@ -212,4 +213,11 @@ public class MMOCoreUtils {
item.setItemMeta(meta); 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());
}
} }

View File

@ -1,6 +1,7 @@
package net.Indyuce.mmocore.experience.dispenser; package net.Indyuce.mmocore.experience.dispenser;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.experience.EXPSource; import net.Indyuce.mmocore.experience.EXPSource;
import org.bukkit.Location; import org.bukkit.Location;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -37,7 +38,8 @@ public interface ExperienceDispenser {
*/ */
boolean shouldHandle(PlayerData playerData); boolean shouldHandle(PlayerData playerData);
@Nullable
default Location getPlayerLocation(PlayerData player) { default Location getPlayerLocation(PlayerData player) {
return player.isOnline() ? player.getPlayer().getLocation() : null; return player.isOnline() ? MMOCoreUtils.getCenterLocation(player.getPlayer()) : null;
} }
} }

View File

@ -4,6 +4,7 @@ import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.mythic.lib.api.event.PlayerKillEntityEvent; import io.lumine.mythic.lib.api.event.PlayerKillEntityEvent;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData; 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.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource; import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager; import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
@ -34,7 +35,7 @@ public class KillMobExperienceSource extends SpecificExperienceSource<Entity> {
for (KillMobExperienceSource source : getSources()) for (KillMobExperienceSource source : getSources())
if (source.matches(data, event.getTarget())) if (source.matches(data, event.getTarget()))
source.giveExperience(data, 1, event.getTarget().getLocation()); source.giveExperience(data, 1, MMOCoreUtils.getCenterLocation(event.getTarget()));
} }
}, 2); }, 2);
} }