Fixed exp holograms always showing for certain professions

This commit is contained in:
Jules 2024-05-23 16:22:01 -07:00
parent d9fa24a730
commit bbe7d2b9b8
5 changed files with 10 additions and 11 deletions

View File

@ -128,8 +128,8 @@ public class MMOCoreUtils {
* @param message Message to display
*/
public static void displayIndicator(Location loc, String message) {
Hologram holo = Hologram.create(loc, Arrays.asList(message));
Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> holo.despawn(), 20);
Hologram holo = Hologram.create(loc, Collections.singletonList(message));
Bukkit.getScheduler().runTaskLater(MMOCore.plugin, holo::despawn, 20);
}
public static boolean isPlayerHead(Material material) {

View File

@ -155,11 +155,11 @@ public class PlayerProfessions {
return profession.hasMaxLevel() && getLevel(profession) >= profession.getMaxLevel();
}
public void giveExperience(Profession profession, double value, EXPSource source) {
public void giveExperience(@NotNull Profession profession, double value, @NotNull EXPSource source) {
giveExperience(profession, value, source, null, true);
}
public void giveExperience(Profession profession, double value, EXPSource source, @Nullable Location hologramLocation, boolean splitExp) {
public void giveExperience(@NotNull Profession profession, double value, @NotNull EXPSource source, @Nullable Location hologramLocation, boolean splitExp) {
Validate.isTrue(playerData.isOnline(), "Cannot give experience to offline player");
if (value <= 0) {
exp.put(profession.getId(), Math.max(0, exp.getOrDefault(profession.getId(), 0d) + value));
@ -190,7 +190,7 @@ public class PlayerProfessions {
return;
// Display hologram
if (hologramLocation != null)
if (hologramLocation != null && profession.getOption(Profession.ProfessionOption.EXP_HOLOGRAMS))
MMOCoreUtils.displayIndicator(hologramLocation.add(.5, 1.5, .5), ConfigMessage.fromKey("exp-hologram", "exp", MythicLib.plugin.getMMOConfig().decimal.format(event.getExperience())).asLine());
exp.put(profession.getId(), Math.max(0, exp.getOrDefault(profession.getId(), 0d) + event.getExperience()));
@ -228,10 +228,10 @@ public class PlayerProfessions {
playerData.getStats().updateStats();
}
StringBuilder bar = new StringBuilder("" + ChatColor.BOLD);
StringBuilder bar = new StringBuilder(ChatColor.BOLD.toString());
int chars = (int) (exp / needed * 20);
for (int j = 0; j < 20; j++)
bar.append(j == chars ? "" + ChatColor.WHITE + ChatColor.BOLD : "").append("|");
bar.append(j == chars ? ChatColor.WHITE.toString() + ChatColor.BOLD : "").append("|");
if (playerData.isOnline())
ConfigMessage.fromKey("exp-notification", "profession", profession.getName(), "progress", bar.toString(), "ratio",
MythicLib.plugin.getMMOConfig().decimal.format(exp / needed * 100)).send(playerData.getPlayer());

View File

@ -124,8 +124,7 @@ public class Profession extends PostLoadObject implements ExperienceObject {
}
@Override
public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, EXPSource source) {
hologramLocation = !getOption(Profession.ProfessionOption.EXP_HOLOGRAMS) ? null : hologramLocation;
public void giveExperience(@NotNull PlayerData playerData, double experience, @Nullable Location hologramLocation, @NotNull EXPSource source) {
playerData.getCollectionSkills().giveExperience(this, experience, EXPSource.SOURCE, hologramLocation, true);
}

View File

@ -19,7 +19,7 @@ public class RegionBounds {
String name = config.getString("world");
Validate.notNull(name, "Could not find world name");
Validate.notNull(world = Bukkit.getWorld(name), "Could not find world " + config.getString("world"));
Validate.notNull(world = Bukkit.getWorld(name), "Could not find world '" + config.getString("world") + "'");
x1 = Math.min(config.getInt("x1"), config.getInt("x2"));
x2 = Math.max(config.getInt("x1"), config.getInt("x2"));

View File

@ -69,7 +69,7 @@ public class CustomBlockManager extends SpecificProfessionManager {
* @return The new block behaviour or null if no new behaviour
*/
public @Nullable BlockInfo getInfo(Block block) {
return map.getOrDefault(findBlockType(block).generateKey(), null);
return map.get(findBlockType(block).generateKey());
}
public BlockType findBlockType(Block block) {