Exp holograms are no longer hidden to player

This commit is contained in:
Indyuce 2020-12-21 02:11:54 +01:00
parent b50b365a30
commit bc2b14136c
4 changed files with 38 additions and 26 deletions

View File

@ -141,8 +141,8 @@ public class PlayerData extends OfflinePlayerData {
MMOCore.log(Level.SEVERE, "[Userdata] Could not find skill " + boundSkills.get(j).getSkill().getId() + " in class " MMOCore.log(Level.SEVERE, "[Userdata] Could not find skill " + boundSkills.get(j).getSkill().getId() + " in class "
+ getProfess().getId() + " while refreshing player data."); + getProfess().getId() + " while refreshing player data.");
} catch (NullPointerException npe2) { } catch (NullPointerException npe2) {
MMOCore.log(Level.SEVERE, "[Userdata] Could not find unidentified skill in class " MMOCore.log(Level.SEVERE,
+ getProfess().getId() + " while refreshing player data."); "[Userdata] Could not find unidentified skill in class " + getProfess().getId() + " while refreshing player data.");
} }
} }
} }
@ -260,7 +260,8 @@ public class PlayerData extends OfflinePlayerData {
public void refreshVanillaExp() { public void refreshVanillaExp() {
if (MMOCore.plugin.configManager.overrideVanillaExp) { if (MMOCore.plugin.configManager.overrideVanillaExp) {
if(!isOnline()) return; if (!isOnline())
return;
getPlayer().setLevel(getLevel()); getPlayer().setLevel(getLevel());
getPlayer().setExp(Math.max(0, Math.min(1, (float) experience / (float) getLevelUpExperience()))); getPlayer().setExp(Math.max(0, Math.min(1, (float) experience / (float) getLevelUpExperience())));
} }
@ -315,7 +316,7 @@ public class PlayerData extends OfflinePlayerData {
} }
public boolean hasWaypoint(Waypoint waypoint) { public boolean hasWaypoint(Waypoint waypoint) {
return waypoint.isDefault() || waypoints.contains(waypoint.getId()); return waypoint.isDefault() || waypoints.contains(waypoint.getId());
} }
public void unlockWaypoint(Waypoint waypoint) { public void unlockWaypoint(Waypoint waypoint) {
@ -340,7 +341,8 @@ public class PlayerData extends OfflinePlayerData {
} }
public void heal(double heal) { public void heal(double heal) {
if(!isOnline()) return; if (!isOnline())
return;
double newest = Math.max(0, Math.min(getPlayer().getHealth() + heal, getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue())); double newest = Math.max(0, Math.min(getPlayer().getHealth() + heal, getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
if (getPlayer().getHealth() == newest) if (getPlayer().getHealth() == newest)
return; return;
@ -384,7 +386,8 @@ public class PlayerData extends OfflinePlayerData {
} }
public void sendFriendRequest(PlayerData target) { public void sendFriendRequest(PlayerData target) {
if(!isOnline() || !target.isOnline()) return; if (!isOnline() || !target.isOnline())
return;
setLastFriendRequest(System.currentTimeMillis()); setLastFriendRequest(System.currentTimeMillis());
FriendRequest request = new FriendRequest(this, target); FriendRequest request = new FriendRequest(this, target);
@ -404,7 +407,8 @@ public class PlayerData extends OfflinePlayerData {
giveStellium(-waypoint.getStelliumCost()); giveStellium(-waypoint.getStelliumCost());
if(!isOnline()) return; if (!isOnline())
return;
new BukkitRunnable() { new BukkitRunnable() {
final int x = getPlayer().getLocation().getBlockX(); final int x = getPlayer().getLocation().getBlockX();
final int y = getPlayer().getLocation().getBlockY(); final int y = getPlayer().getLocation().getBlockY();
@ -412,7 +416,8 @@ public class PlayerData extends OfflinePlayerData {
int t; int t;
public void run() { public void run() {
if(!isOnline()) return; if (!isOnline())
return;
if (getPlayer().getLocation().getBlockX() != x || getPlayer().getLocation().getBlockY() != y if (getPlayer().getLocation().getBlockX() != x || getPlayer().getLocation().getBlockY() != y
|| getPlayer().getLocation().getBlockZ() != z) { || getPlayer().getLocation().getBlockZ() != z) {
MMOCore.plugin.soundManager.play(getPlayer(), SoundManager.SoundEvent.WARP_CANCELLED); MMOCore.plugin.soundManager.play(getPlayer(), SoundManager.SoundEvent.WARP_CANCELLED);
@ -485,7 +490,7 @@ public class PlayerData extends OfflinePlayerData {
if (level > oldLevel) { if (level > oldLevel) {
Bukkit.getPluginManager().callEvent(new PlayerLevelUpEvent(this, null, oldLevel, level)); Bukkit.getPluginManager().callEvent(new PlayerLevelUpEvent(this, null, oldLevel, level));
if(isOnline()) { if (isOnline()) {
new ConfigMessage("level-up").addPlaceholders("level", "" + level).send(getPlayer()); new ConfigMessage("level-up").addPlaceholders("level", "" + level).send(getPlayer());
MMOCore.plugin.soundManager.play(getPlayer(), SoundManager.SoundEvent.LEVEL_UP); MMOCore.plugin.soundManager.play(getPlayer(), SoundManager.SoundEvent.LEVEL_UP);
new SmallParticleEffect(getPlayer(), Particle.SPELL_INSTANT); new SmallParticleEffect(getPlayer(), Particle.SPELL_INSTANT);
@ -593,7 +598,8 @@ public class PlayerData extends OfflinePlayerData {
} }
public void displayActionBar(String message) { public void displayActionBar(String message) {
if(!isOnline()) return; if (!isOnline())
return;
setActionBarTimeOut(MMOCore.plugin.actionBarManager.getTimeOut()); setActionBarTimeOut(MMOCore.plugin.actionBarManager.getTimeOut());
getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message)); getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
} }
@ -745,7 +751,7 @@ public class PlayerData extends OfflinePlayerData {
*/ */
SkillResult cast = skill.getSkill().whenCast(this, skill); SkillResult cast = skill.getSkill().whenCast(this, skill);
if (!cast.isSuccessful()) { if (!cast.isSuccessful()) {
if (!skill.getSkill().isPassive() && isOnline()) { if (!skill.getSkill().isPassive() && isOnline()) {
if (cast.getCancelReason() == CancelReason.LOCKED) if (cast.getCancelReason() == CancelReason.LOCKED)
MMOCore.plugin.configManager.getSimpleMessage("not-unlocked-skill").send(getPlayer()); MMOCore.plugin.configManager.getSimpleMessage("not-unlocked-skill").send(getPlayer());

View File

@ -1,22 +1,24 @@
package net.Indyuce.mmocore.comp.holograms; package net.Indyuce.mmocore.comp.holograms;
import com.Zrips.CMI.CMI; import java.util.Collections;
import com.Zrips.CMI.Modules.Holograms.CMIHologram; import java.util.UUID;
import net.Indyuce.mmocore.MMOCore;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Collections; import com.Zrips.CMI.CMI;
import java.util.UUID; import com.Zrips.CMI.Modules.Holograms.CMIHologram;
import net.Indyuce.mmocore.MMOCore;
public class CMIPlugin extends HologramSupport { public class CMIPlugin extends HologramSupport {
@Override @Override
public void displayIndicator(Location loc, String format, Player player) { public void displayIndicator(Location loc, String format, Player player) {
final CMIHologram hologram = new CMIHologram("MMOItems_" + UUID.randomUUID().toString(), loc); final CMIHologram hologram = new CMIHologram("MMOItems_" + UUID.randomUUID().toString(), loc);
hologram.setLines(Collections.singletonList(format)); hologram.setLines(Collections.singletonList(format));
if (player != null) // if (player != null)
hologram.hide(player.getUniqueId()); // hologram.hide(player.getUniqueId());
CMI.getInstance().getHologramManager().addHologram(hologram); CMI.getInstance().getHologramManager().addHologram(hologram);
hologram.update(); hologram.update();
Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> CMI.getInstance().getHologramManager().removeHolo(hologram), 20); Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> CMI.getInstance().getHologramManager().removeHolo(hologram), 20);

View File

@ -1,16 +1,20 @@
package net.Indyuce.mmocore.comp.holograms; package net.Indyuce.mmocore.comp.holograms;
import javax.annotation.Nullable;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public abstract class HologramSupport { public abstract class HologramSupport {
/**
/* * Displays a message using a hologram
* the third argument is the player which the hologram needs to be hidden *
* from to prevent the indicator from taking too much space on the player * @param loc The location at which the message should be displayed
* screen * @param message The message to display
* @param player Source player, can be null in some cases source player for
* instance for regen holograms
*/ */
public abstract void displayIndicator(Location loc, String message, Player player); public abstract void displayIndicator(Location loc, String message, @Nullable Player player);
public void displayIndicator(Location loc, String message) { public void displayIndicator(Location loc, String message) {
displayIndicator(loc, message, null); displayIndicator(loc, message, null);

View File

@ -14,8 +14,8 @@ public class HolographicDisplaysPlugin extends HologramSupport {
public void displayIndicator(Location loc, String format, Player player) { public void displayIndicator(Location loc, String format, Player player) {
Hologram hologram = HologramsAPI.createHologram(MMOCore.plugin, loc); Hologram hologram = HologramsAPI.createHologram(MMOCore.plugin, loc);
hologram.appendTextLine(format); hologram.appendTextLine(format);
if (player != null) // if (player != null)
hologram.getVisibilityManager().hideTo(player); // hologram.getVisibilityManager().hideTo(player);
Bukkit.getScheduler().scheduleSyncDelayedTask(MMOCore.plugin, hologram::delete, 20); Bukkit.getScheduler().scheduleSyncDelayedTask(MMOCore.plugin, hologram::delete, 20);
} }
} }