From 7353cba619dbd1b6db626251df73689559abb328 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Fri, 20 Aug 2021 11:32:34 +0200 Subject: [PATCH] small cleanup --- pom.xml | 21 ---------- .../mmocore/api/experience/Booster.java | 31 +++++++++++---- .../api/experience/PlayerProfessions.java | 10 ++--- .../mmocore/api/experience/Profession.java | 14 +++++++ .../mmocore/api/player/PlayerData.java | 9 ++--- .../mmocore/api/util/MMOCoreUtils.java | 17 +++++++++ .../mmocore/gui/api/item/TriggerItem.java | 3 +- .../listener/profession/FishingListener.java | 38 +++++++++---------- .../manager/social/BoosterManager.java | 14 ++++--- 9 files changed, 88 insertions(+), 69 deletions(-) diff --git a/pom.xml b/pom.xml index 35e92a4f..d4d0c1a6 100644 --- a/pom.xml +++ b/pom.xml @@ -184,27 +184,6 @@ provided - - com.Zrips.CMI - CMI - 8.6.5.0 - provided - - - - com.sainttx.holograms - Holograms - 2.9.1 - provided - - - - com.gmail.filoghost.holographicdisplays - holographicdisplays-api - 2.4.0 - provided - - net.citizensnpcs Citizens diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/Booster.java b/src/main/java/net/Indyuce/mmocore/api/experience/Booster.java index a016badf..6df11403 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/Booster.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/Booster.java @@ -1,5 +1,6 @@ package net.Indyuce.mmocore.api.experience; +import java.util.Objects; import java.util.UUID; public class Booster { @@ -12,6 +13,8 @@ public class Booster { /** * Length is not final because boosters can stacks. This allows to reduce * the amount of boosters displayed in the main player menu + * + * See {@link net.Indyuce.mmocore.manager.social.BoosterManager#register(Booster)} */ private long length; @@ -26,18 +29,19 @@ public class Booster { } /** - * @param author - * The booster creator - * @param extra - * 1 for +100% experience, 3 for 300% etc. - * @param length - * Booster length in milliseconds + * Main class experience booster + * + * @param author The booster creator + * @param extra 1 for +100% experience, 3 for 300% etc. + * @param length Booster length in milliseconds */ public Booster(String author, double extra, long length) { this(author, null, extra, length); } /** + * Profession experience booster + * * @param author * The booster creator * @param profession @@ -99,6 +103,19 @@ public class Booster { } public boolean canStackWith(Booster booster) { - return extra == booster.extra && (profession != null ? profession.equals(booster.getProfession()) : booster.getProfession() == null); + return extra == booster.extra && Objects.equals(profession, booster.profession); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Booster booster = (Booster) o; + return Objects.equals(uuid, booster.uuid); + } + + @Override + public int hashCode() { + return Objects.hash(uuid); } } diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/PlayerProfessions.java b/src/main/java/net/Indyuce/mmocore/api/experience/PlayerProfessions.java index 7e96cc08..e9264b34 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/PlayerProfessions.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/PlayerProfessions.java @@ -4,13 +4,12 @@ import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.lumine.mythic.lib.MythicLib; -import io.lumine.mythic.utils.holograms.Hologram; -import io.lumine.mythic.utils.serialize.Position; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.ConfigMessage; import net.Indyuce.mmocore.api.event.PlayerExperienceGainEvent; import net.Indyuce.mmocore.api.event.PlayerLevelUpEvent; import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.Indyuce.mmocore.api.util.math.particle.SmallParticleEffect; import net.Indyuce.mmocore.manager.SoundManager; import org.bukkit.Bukkit; @@ -20,7 +19,6 @@ import org.bukkit.Particle; import org.bukkit.configuration.ConfigurationSection; import javax.annotation.Nullable; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -139,10 +137,8 @@ public class PlayerProfessions { value = MMOCore.plugin.boosterManager.calculateExp(profession, value); // display hologram - if (hologramLocation != null && playerData.isOnline()) { - Hologram holo = Hologram.create(Position.of(hologramLocation.add(.5, 1.5, .5)), Arrays.asList(MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message())); - Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> holo.despawn(), 20); - } + if (hologramLocation != null && playerData.isOnline()) + MMOCoreUtils.displayIndicator(hologramLocation.add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message()); PlayerExperienceGainEvent event = new PlayerExperienceGainEvent(playerData, profession, value, source); Bukkit.getPluginManager().callEvent(event); diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/Profession.java b/src/main/java/net/Indyuce/mmocore/api/experience/Profession.java index 950d406b..cff76488 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/Profession.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/Profession.java @@ -2,6 +2,7 @@ package net.Indyuce.mmocore.api.experience; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.logging.Level; import org.apache.commons.lang.Validate; @@ -171,4 +172,17 @@ public class Profession extends PostLoadObject { return def; } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Profession that = (Profession) o; + return id.equals(that.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } } 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 7be6c96e..5d25b13e 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -1,8 +1,6 @@ package net.Indyuce.mmocore.api.player; import io.lumine.mythic.lib.api.player.MMOPlayerData; -import io.lumine.mythic.utils.holograms.Hologram; -import io.lumine.mythic.utils.serialize.Position; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.ConfigMessage; import net.Indyuce.mmocore.api.Waypoint; @@ -26,6 +24,7 @@ import net.Indyuce.mmocore.api.skill.Skill; import net.Indyuce.mmocore.api.skill.Skill.SkillInfo; import net.Indyuce.mmocore.api.skill.SkillResult; import net.Indyuce.mmocore.api.skill.SkillResult.CancelReason; +import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.Indyuce.mmocore.api.util.math.particle.SmallParticleEffect; import net.Indyuce.mmocore.listener.SpellCast.SkillCasting; import net.Indyuce.mmocore.manager.SoundManager; @@ -472,10 +471,8 @@ public class PlayerData extends OfflinePlayerData { } // Experience hologram - if (hologramLocation != null && isOnline()) { - Hologram holo = Hologram.create(Position.of(hologramLocation.add(.5, 1.5, .5)), Arrays.asList(MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message())); - Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> holo.despawn(), 20); - } + if (hologramLocation != null && isOnline()) + MMOCoreUtils.displayIndicator(hologramLocation.add(.5, 1.5, .5), 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 8c44ba61..74733048 100644 --- a/src/main/java/net/Indyuce/mmocore/api/util/MMOCoreUtils.java +++ b/src/main/java/net/Indyuce/mmocore/api/util/MMOCoreUtils.java @@ -3,6 +3,9 @@ package net.Indyuce.mmocore.api.util; import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.version.VersionMaterial; +import io.lumine.mythic.utils.holograms.Hologram; +import io.lumine.mythic.utils.serialize.Position; +import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.player.PlayerData; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -53,6 +56,20 @@ public class MMOCoreUtils { return builder.toString(); } + /** + * Displays an in game indicator using a hologram. This uses + * LumineUtils hologramFactory to summon holograms + *

+ * The hologram despawns after 1sec + * + * @param loc Target location + * @param message Message to display + */ + public static void displayIndicator(Location loc, String message) { + Hologram holo = Hologram.create(Position.of(loc), Arrays.asList(message)); + Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> holo.despawn(), 20); + } + public static boolean isPlayerHead(Material material) { return material == VersionMaterial.PLAYER_HEAD.toMaterial() || material == VersionMaterial.PLAYER_WALL_HEAD.toMaterial(); } diff --git a/src/main/java/net/Indyuce/mmocore/gui/api/item/TriggerItem.java b/src/main/java/net/Indyuce/mmocore/gui/api/item/TriggerItem.java index c5053b7d..28c0df3b 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/api/item/TriggerItem.java +++ b/src/main/java/net/Indyuce/mmocore/gui/api/item/TriggerItem.java @@ -3,6 +3,7 @@ package net.Indyuce.mmocore.gui.api.item; import io.lumine.mythic.lib.api.MMOLineConfig; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.quest.trigger.Trigger; +import net.Indyuce.mmocore.gui.api.GeneratedInventory; import net.Indyuce.mmocore.gui.api.PluginInventory; import org.bukkit.configuration.ConfigurationSection; @@ -16,7 +17,7 @@ public class TriggerItem extends InventoryItem { } @Override - public Placeholders getPlaceholders(PluginInventory inv, int n) { + public Placeholders getPlaceholders(GeneratedInventory inv, int n) { return new Placeholders(); } diff --git a/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java b/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java index 83bb797a..5b7296da 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java @@ -1,10 +1,15 @@ package net.Indyuce.mmocore.listener.profession; -import java.util.HashSet; -import java.util.Random; -import java.util.Set; -import java.util.UUID; - +import io.lumine.mythic.lib.version.VersionSound; +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.api.droptable.dropitem.fishing.FishingDropItem; +import net.Indyuce.mmocore.api.event.CustomPlayerFishEvent; +import net.Indyuce.mmocore.api.experience.EXPSource; +import net.Indyuce.mmocore.api.loot.LootBuilder; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.api.player.stats.StatType; +import net.Indyuce.mmocore.api.util.MMOCoreUtils; +import net.Indyuce.mmocore.manager.profession.FishingManager.FishingDropTable; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -23,16 +28,10 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.droptable.dropitem.fishing.FishingDropItem; -import net.Indyuce.mmocore.api.event.CustomPlayerFishEvent; -import net.Indyuce.mmocore.api.experience.EXPSource; -import net.Indyuce.mmocore.api.loot.LootBuilder; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.api.player.stats.StatType; -import net.Indyuce.mmocore.api.util.MMOCoreUtils; -import net.Indyuce.mmocore.manager.profession.FishingManager.FishingDropTable; -import io.lumine.mythic.lib.version.VersionSound; +import java.util.HashSet; +import java.util.Random; +import java.util.Set; +import java.util.UUID; public class FishingListener implements Listener { private final Set fishing = new HashSet<>(); @@ -55,9 +54,7 @@ public class FishingListener implements Listener { return; new FishingData(player, hook, table); - if (MMOCore.plugin.hasHolograms()) - MMOCore.plugin.hologramSupport.displayIndicator(hook.getLocation().add(0, 1.25, 0), - MMOCore.plugin.configManager.getSimpleMessage("caught-fish").message()); + MMOCoreUtils.displayIndicator(hook.getLocation().add(0, 1.25, 0), MMOCore.plugin.configManager.getSimpleMessage("caught-fish").message()); } } @@ -173,9 +170,8 @@ public class FishingListener implements Listener { // calculate velocity Item item = hook.getWorld().dropItemNaturally(hook.getLocation(), collect); - if (MMOCore.plugin.hasHolograms()) - MMOCore.plugin.hologramSupport.displayIndicator(location.add(0, 1.25, 0), - MMOCore.plugin.configManager.getSimpleMessage("fish-out-water" + (isCrit() ? "-crit" : "")).message()); + MMOCoreUtils.displayIndicator(location.add(0, 1.25, 0), + MMOCore.plugin.configManager.getSimpleMessage("fish-out-water" + (isCrit() ? "-crit" : "")).message()); Vector vec = player.getLocation().subtract(hook.getLocation()).toVector(); vec.setY(vec.getY() * .031 + vec.length() * .05); vec.setX(vec.getX() * .08); diff --git a/src/main/java/net/Indyuce/mmocore/manager/social/BoosterManager.java b/src/main/java/net/Indyuce/mmocore/manager/social/BoosterManager.java index d98882a3..c9590faf 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/social/BoosterManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/social/BoosterManager.java @@ -1,12 +1,13 @@ package net.Indyuce.mmocore.manager.social; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - import net.Indyuce.mmocore.api.experience.Booster; import net.Indyuce.mmocore.api.experience.Profession; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + public class BoosterManager { private final List map = new ArrayList<>(); @@ -51,7 +52,7 @@ public class BoosterManager { double d = 1; for (Booster booster : map) - if (booster.getProfession() == profession && !booster.isTimedOut()) + if (Objects.equals(profession, booster.getProfession()) && !booster.isTimedOut()) d += booster.getExtra(); return d; @@ -68,8 +69,9 @@ public class BoosterManager { public List getBoosters() { return map; } + /** - * @return Same as getBoosters() but does not include timed out boosters + * @return Same as {@link #getBoosters()} but does not include timed out boosters */ public List getActiveBoosters() { return map.stream().filter((b) -> !b.isTimedOut()).collect(Collectors.toList());