From 41ac1e95ac45ff33dd9ae1944c3bd63acd2b9b28 Mon Sep 17 00:00:00 2001 From: Jules Date: Sun, 24 Apr 2022 08:42:27 +0200 Subject: [PATCH 1/7] Merging expDispensers with expObjects --- .../api/player/profess/PlayerClass.java | 39 ++++++++++++++----- .../api/quest/trigger/ExperienceTrigger.java | 17 ++++---- .../mmocore/experience/ExperienceObject.java | 37 +++++++++++++++++- .../mmocore/experience/Profession.java | 20 ++++++++-- .../dispenser/ClassExperienceDispenser.java | 28 ------------- .../dispenser/ExperienceDispenser.java | 3 ++ .../ProfessionExperienceDispenser.java | 27 ------------- .../dispenser/SimpleExperienceDispenser.java | 22 ----------- .../mmocore/manager/MMOLoadManager.java | 1 + 9 files changed, 93 insertions(+), 101 deletions(-) delete mode 100644 src/main/java/net/Indyuce/mmocore/experience/dispenser/ClassExperienceDispenser.java delete mode 100644 src/main/java/net/Indyuce/mmocore/experience/dispenser/ProfessionExperienceDispenser.java delete mode 100644 src/main/java/net/Indyuce/mmocore/experience/dispenser/SimpleExperienceDispenser.java diff --git a/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java b/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java index 346a2b9a..cc847430 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java @@ -8,6 +8,7 @@ import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.util.PostLoadObject; import io.lumine.mythic.lib.version.VersionMaterial; import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.profess.event.EventTrigger; import net.Indyuce.mmocore.api.player.profess.resource.ManaDisplayOptions; import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource; @@ -15,19 +16,18 @@ import net.Indyuce.mmocore.api.player.profess.resource.ResourceRegeneration; import net.Indyuce.mmocore.api.player.stats.StatType; import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.Indyuce.mmocore.api.util.math.formula.LinearValue; +import net.Indyuce.mmocore.experience.EXPSource; import net.Indyuce.mmocore.loot.chest.particle.CastingParticle; import net.Indyuce.mmocore.experience.ExpCurve; import net.Indyuce.mmocore.experience.ExperienceObject; import net.Indyuce.mmocore.experience.droptable.ExperienceTable; -import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser; -import net.Indyuce.mmocore.experience.dispenser.ClassExperienceDispenser; import net.Indyuce.mmocore.experience.source.type.ExperienceSource; import net.Indyuce.mmocore.player.playerclass.ClassTrigger; import net.Indyuce.mmocore.player.playerclass.ClassTriggerType; import net.Indyuce.mmocore.skill.ClassSkill; import net.Indyuce.mmocore.skill.RegisteredSkill; import net.md_5.bungee.api.ChatColor; -import org.apache.commons.lang.Validate; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Particle; import org.bukkit.configuration.ConfigurationSection; @@ -156,10 +156,9 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject { } if (config.contains("main-exp-sources")) { - ExperienceDispenser dispenser = new ClassExperienceDispenser(this); for (String key : config.getStringList("main-exp-sources")) try { - ExperienceSource source = MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), dispenser); + ExperienceSource source = MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), this); MMOCore.plugin.experience.registerSource(source); } catch (IllegalArgumentException exception) { MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load exp source '" + key + "' from class '" @@ -389,11 +388,6 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject { return stats.containsKey(type) ? stats.get(type) : type.getDefault(); } - @Override - public boolean equals(Object obj) { - return obj instanceof PlayerClass && ((PlayerClass) obj).id.equals(id); - } - public String getActionBar() { return actionBarFormat; } @@ -401,4 +395,29 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject { public boolean hasActionBar() { return actionBarFormat != null; } + + @Override + public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, EXPSource source) { + hologramLocation = !MMOCore.plugin.getConfig().getBoolean("display-main-class-exp-holograms") ? null + : hologramLocation == null ? getPlayerLocation(playerData) : hologramLocation; + playerData.giveExperience(experience, source, hologramLocation, true); + } + + @Override + public boolean shouldHandle(PlayerData playerData) { + return equals(playerData.getProfess()); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + PlayerClass that = (PlayerClass) o; + return id.equals(that.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } } diff --git a/src/main/java/net/Indyuce/mmocore/api/quest/trigger/ExperienceTrigger.java b/src/main/java/net/Indyuce/mmocore/api/quest/trigger/ExperienceTrigger.java index 4a84e0b0..4f84729d 100644 --- a/src/main/java/net/Indyuce/mmocore/api/quest/trigger/ExperienceTrigger.java +++ b/src/main/java/net/Indyuce/mmocore/api/quest/trigger/ExperienceTrigger.java @@ -1,8 +1,6 @@ package net.Indyuce.mmocore.api.quest.trigger; -import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser; -import net.Indyuce.mmocore.experience.dispenser.ProfessionExperienceDispenser; -import net.Indyuce.mmocore.experience.dispenser.SimpleExperienceDispenser; +import net.Indyuce.mmocore.experience.ExperienceObject; import org.apache.commons.lang.Validate; import net.Indyuce.mmocore.MMOCore; @@ -11,14 +9,17 @@ import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.util.math.formula.RandomAmount; import io.lumine.mythic.lib.api.MMOLineConfig; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Objects; public class ExperienceTrigger extends Trigger { @NotNull private final RandomAmount amount; @NotNull private final EXPSource source; - @NotNull - private final ExperienceDispenser dispenser; + @Nullable + private final ExperienceObject expObject; public ExperienceTrigger(MMOLineConfig config) { super(config); @@ -28,15 +29,15 @@ public class ExperienceTrigger extends Trigger { if (config.contains("profession")) { String id = config.getString("profession").toLowerCase().replace("_", "-"); Validate.isTrue(MMOCore.plugin.professionManager.has(id), "Could not find profession"); - dispenser = new ProfessionExperienceDispenser(MMOCore.plugin.professionManager.get(id)); + expObject = MMOCore.plugin.professionManager.get(id); } else - dispenser = new SimpleExperienceDispenser(); + expObject = null; amount = new RandomAmount(config.getString("amount")); source = config.contains("source") ? EXPSource.valueOf(config.getString("source").toUpperCase()) : EXPSource.QUEST; } @Override public void apply(PlayerData player) { - dispenser.giveExperience(player, amount.calculateInt(), null, source); + Objects.requireNonNullElse(expObject, player.getProfess()).giveExperience(player, amount.calculateInt(), null, source); } } diff --git a/src/main/java/net/Indyuce/mmocore/experience/ExperienceObject.java b/src/main/java/net/Indyuce/mmocore/experience/ExperienceObject.java index 3f9e6cc8..a5ebf4f4 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/ExperienceObject.java +++ b/src/main/java/net/Indyuce/mmocore/experience/ExperienceObject.java @@ -1,6 +1,10 @@ package net.Indyuce.mmocore.experience; +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.droptable.ExperienceTable; +import org.bukkit.Location; import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; @@ -10,7 +14,7 @@ import javax.annotation.Nullable; * * @author jules */ -public interface ExperienceObject { +public interface ExperienceObject extends ExperienceDispenser { String getKey(); @@ -22,11 +26,40 @@ public interface ExperienceObject { @Nullable ExpCurve getExpCurve(); + boolean hasExperienceTable(); + /** * @return Table read when leveling up */ @NotNull ExperienceTable getExperienceTable(); - boolean hasExperienceTable(); + /** + * Called when experience is gained in main class/profession + * + * @param playerData Player gaining the experience + * @param experience Experience gained. Note that it is a double + * because it gets converted to an integer at + * the very last moment in MMOCore + * @param hologramLocation Location of displayed hologram. When set to null + * and if exp holograms are enabled it will take the + * player's location instead. + * @param source Why the EXP was gained + */ + void giveExperience(PlayerData playerData, double experience, @org.jetbrains.annotations.Nullable Location hologramLocation, @NotNull EXPSource source); + + /** + * Experience sources handle both CLASS experience sources and PROFESSION + * experience sources. Professions have no problem because whatever + * class the player has chosen, he can get exp in that profession. + *

+ * But class experience sources must first make sure that the player has + * the right class before giving exp to the player + */ + boolean shouldHandle(PlayerData playerData); + + @Nullable + default Location getPlayerLocation(PlayerData player) { + return player.isOnline() ? MMOCoreUtils.getCenterLocation(player.getPlayer()) : null; + } } diff --git a/src/main/java/net/Indyuce/mmocore/experience/Profession.java b/src/main/java/net/Indyuce/mmocore/experience/Profession.java index ade8f4fb..27870d28 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/Profession.java +++ b/src/main/java/net/Indyuce/mmocore/experience/Profession.java @@ -3,14 +3,15 @@ package net.Indyuce.mmocore.experience; import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.util.PostLoadObject; import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.util.math.formula.LinearValue; import net.Indyuce.mmocore.experience.droptable.ExperienceTable; -import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser; -import net.Indyuce.mmocore.experience.dispenser.ProfessionExperienceDispenser; import org.apache.commons.lang.Validate; +import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; @@ -64,10 +65,9 @@ public class Profession extends PostLoadObject implements ExperienceObject { maxLevel = config.getInt("max-level"); if (config.contains("exp-sources")) { - ExperienceDispenser dispenser = new ProfessionExperienceDispenser(this); for (String key : config.getStringList("exp-sources")) try { - MMOCore.plugin.experience.registerSource(MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), dispenser)); + MMOCore.plugin.experience.registerSource(MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), this)); } catch (IllegalArgumentException exception) { MMOCore.plugin.getLogger().log(Level.WARNING, "Could not register exp source '" + key + "' from profession '" + id + "': " + exception.getMessage()); @@ -124,6 +124,18 @@ public class Profession extends PostLoadObject implements ExperienceObject { return Objects.requireNonNull(expTable, "Profession has no exp table"); } + @Override + public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, EXPSource source) { + hologramLocation = !getOption(Profession.ProfessionOption.EXP_HOLOGRAMS) ? null + : hologramLocation == null ? getPlayerLocation(playerData) : hologramLocation; + playerData.getCollectionSkills().giveExperience(this, experience, EXPSource.SOURCE, hologramLocation); + } + + @Override + public boolean shouldHandle(PlayerData playerData) { + return true; + } + public static enum ProfessionOption { /** diff --git a/src/main/java/net/Indyuce/mmocore/experience/dispenser/ClassExperienceDispenser.java b/src/main/java/net/Indyuce/mmocore/experience/dispenser/ClassExperienceDispenser.java deleted file mode 100644 index 8be7dfe0..00000000 --- a/src/main/java/net/Indyuce/mmocore/experience/dispenser/ClassExperienceDispenser.java +++ /dev/null @@ -1,28 +0,0 @@ -package net.Indyuce.mmocore.experience.dispenser; - -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.api.player.profess.PlayerClass; -import net.Indyuce.mmocore.experience.EXPSource; -import org.bukkit.Location; -import org.jetbrains.annotations.Nullable; - -public class ClassExperienceDispenser implements ExperienceDispenser { - private final PlayerClass profess; - - public ClassExperienceDispenser(PlayerClass profess) { - this.profess = profess; - } - - @Override - public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, EXPSource source) { - hologramLocation = !MMOCore.plugin.getConfig().getBoolean("display-main-class-exp-holograms") ? null - : hologramLocation == null ? getPlayerLocation(playerData) : hologramLocation; - playerData.giveExperience(experience, source, hologramLocation, true); - } - - @Override - public boolean shouldHandle(PlayerData playerData) { - return playerData.getProfess().equals(profess); - } -} 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 5ac9eac0..2218bace 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/dispenser/ExperienceDispenser.java +++ b/src/main/java/net/Indyuce/mmocore/experience/dispenser/ExperienceDispenser.java @@ -11,7 +11,10 @@ import org.jetbrains.annotations.Nullable; * Used to differenciate between the main class experience and * experience given in a specific profession. Also being used to * monitor EXP holograms. + * + * @deprecated Merged with {@link net.Indyuce.mmocore.experience.ExperienceObject} */ +@Deprecated public interface ExperienceDispenser { /** diff --git a/src/main/java/net/Indyuce/mmocore/experience/dispenser/ProfessionExperienceDispenser.java b/src/main/java/net/Indyuce/mmocore/experience/dispenser/ProfessionExperienceDispenser.java deleted file mode 100644 index af385fc1..00000000 --- a/src/main/java/net/Indyuce/mmocore/experience/dispenser/ProfessionExperienceDispenser.java +++ /dev/null @@ -1,27 +0,0 @@ -package net.Indyuce.mmocore.experience.dispenser; - -import net.Indyuce.mmocore.experience.EXPSource; -import net.Indyuce.mmocore.experience.Profession; -import net.Indyuce.mmocore.api.player.PlayerData; -import org.bukkit.Location; -import org.jetbrains.annotations.Nullable; - -public class ProfessionExperienceDispenser implements ExperienceDispenser { - private final Profession profession; - - public ProfessionExperienceDispenser(Profession profession) { - this.profession = profession; - } - - @Override - public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, EXPSource source) { - hologramLocation = !profession.getOption(Profession.ProfessionOption.EXP_HOLOGRAMS) ? null - : hologramLocation == null ? getPlayerLocation(playerData) : hologramLocation; - playerData.getCollectionSkills().giveExperience(profession, experience, EXPSource.SOURCE, hologramLocation); - } - - @Override - public boolean shouldHandle(PlayerData playerData) { - return true; - } -} diff --git a/src/main/java/net/Indyuce/mmocore/experience/dispenser/SimpleExperienceDispenser.java b/src/main/java/net/Indyuce/mmocore/experience/dispenser/SimpleExperienceDispenser.java deleted file mode 100644 index fc99e73b..00000000 --- a/src/main/java/net/Indyuce/mmocore/experience/dispenser/SimpleExperienceDispenser.java +++ /dev/null @@ -1,22 +0,0 @@ -package net.Indyuce.mmocore.experience.dispenser; - -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.experience.EXPSource; -import org.bukkit.Location; -import org.jetbrains.annotations.Nullable; - -public class SimpleExperienceDispenser implements ExperienceDispenser { - - @Override - public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, EXPSource source) { - hologramLocation = !MMOCore.plugin.getConfig().getBoolean("display-main-class-exp-holograms") ? null - : hologramLocation == null ? getPlayerLocation(playerData) : hologramLocation; - playerData.giveExperience(experience, source, hologramLocation, true); - } - - @Override - public boolean shouldHandle(PlayerData playerData) { - return true; - } -} diff --git a/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java b/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java index 67f7c279..be250b6a 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java @@ -41,6 +41,7 @@ public class MMOLoadManager { return load(Objective.class, config, loader -> loader.loadObjective(config, section)); } + @Deprecated public ExperienceSource loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) { return load(ExperienceSource.class, config, loader -> loader.loadExperienceSource(config, dispenser)); } From ba2691daf2932c821e03e70a59b98fd775750960 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Tue, 14 Jun 2022 09:39:58 +0200 Subject: [PATCH 2/7] Fixed exp splitting + now supports professions --- .../mmocore/api/event/PlayerLevelUpEvent.java | 4 ++- .../mmocore/api/player/PlayerData.java | 15 ++++---- .../rpg/admin/ExperienceCommandTreeNode.java | 4 +-- .../Indyuce/mmocore/experience/EXPSource.java | 3 ++ .../mmocore/experience/PlayerProfessions.java | 36 ++++++++++++------- .../mmocore/experience/Profession.java | 2 +- .../listener/profession/FishingListener.java | 2 +- .../manager/social/BoosterManager.java | 7 ++-- 8 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/api/event/PlayerLevelUpEvent.java b/src/main/java/net/Indyuce/mmocore/api/event/PlayerLevelUpEvent.java index b02a90bc..0938dc8a 100644 --- a/src/main/java/net/Indyuce/mmocore/api/event/PlayerLevelUpEvent.java +++ b/src/main/java/net/Indyuce/mmocore/api/event/PlayerLevelUpEvent.java @@ -4,11 +4,12 @@ import org.bukkit.event.HandlerList; import net.Indyuce.mmocore.experience.Profession; import net.Indyuce.mmocore.api.player.PlayerData; +import org.jetbrains.annotations.Nullable; public class PlayerLevelUpEvent extends PlayerDataEvent { private static final HandlerList handlers = new HandlerList(); - // if null, this is main level + // If null, this is main level private final Profession profession; private final int oldLevel, newLevel; @@ -36,6 +37,7 @@ public class PlayerLevelUpEvent extends PlayerDataEvent { return profession != null; } + @Nullable public Profession getProfession() { return profession; } 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 8713d21f..b8e3922c 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -540,18 +540,19 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc return; } - value = MMOCore.plugin.boosterManager.calculateExp(null, value); - value *= 1 + getStats().getStat("ADDITIONAL_EXPERIENCE") / 100; - // Splitting exp through party members - AbstractParty party = getParty(); - if (splitExp && party != null) { - List onlineMembers = getParty().getOnlineMembers(); + AbstractParty party; + if (splitExp && (party = getParty()) != null) { + List onlineMembers = party.getOnlineMembers(); value /= onlineMembers.size(); for (PlayerData member : onlineMembers) - member.giveExperience(value, EXPSource.PARTY_SHARING, null, false); + if (!equals(member)) + member.giveExperience(value, source, null, false); } + // Apply buffs AFTER splitting exp + value *= (1 + getStats().getStat("ADDITIONAL_EXPERIENCE") / 100) * MMOCore.plugin.boosterManager.getMultiplier(null); + PlayerExperienceGainEvent event = new PlayerExperienceGainEvent(this, value, source); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExperienceCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExperienceCommandTreeNode.java index 5c4b7664..5bd2d305 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExperienceCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExperienceCommandTreeNode.java @@ -23,9 +23,9 @@ public class ExperienceCommandTreeNode extends CommandTreeNode { addChild(new ActionCommandTreeNode(this, "set", PlayerData::setExperience, PlayerProfessions::setExperience)); addChild(new ActionCommandTreeNode(this, "give", (data, value) -> data.giveExperience(value, EXPSource.COMMAND), (professions, profession, - value) -> professions.giveExperience(profession, value, EXPSource.COMMAND, professions.getPlayerData().getPlayer().getLocation()))); + value) -> professions.giveExperience(profession, value, EXPSource.COMMAND))); addChild(new ActionCommandTreeNode(this, "take", (data, value) -> data.giveExperience(-value, EXPSource.COMMAND), (professions, profession, - value) -> professions.giveExperience(profession, -value, EXPSource.COMMAND, professions.getPlayerData().getPlayer().getLocation()))); + value) -> professions.giveExperience(profession, -value, EXPSource.COMMAND))); } public static class ActionCommandTreeNode extends CommandTreeNode { diff --git a/src/main/java/net/Indyuce/mmocore/experience/EXPSource.java b/src/main/java/net/Indyuce/mmocore/experience/EXPSource.java index 89f522f3..08ccf6c9 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/EXPSource.java +++ b/src/main/java/net/Indyuce/mmocore/experience/EXPSource.java @@ -19,7 +19,10 @@ public enum EXPSource { /** * When party members share exp + * + * @deprecated Not used anymore */ + @Deprecated PARTY_SHARING, /** diff --git a/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java b/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java index 44f3552c..9b0d11c1 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java +++ b/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java @@ -13,6 +13,7 @@ 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.loot.chest.particle.SmallParticleEffect; +import net.Indyuce.mmocore.party.AbstractParty; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -22,6 +23,7 @@ import org.bukkit.configuration.ConfigurationSection; import javax.annotation.Nullable; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -147,15 +149,15 @@ public class PlayerProfessions { giveExperience(profession, total, source); } - public void giveExperience(Profession profession, double value, EXPSource source) { - giveExperience(profession, value, source, null); - } - public boolean hasReachedMaxLevel(Profession profession) { return profession.hasMaxLevel() && getLevel(profession) >= profession.getMaxLevel(); } - public void giveExperience(Profession profession, double value, EXPSource source, @Nullable Location hologramLocation) { + public void giveExperience(Profession profession, double value, EXPSource source) { + giveExperience(profession, value, source, null, true); + } + + public void giveExperience(Profession profession, double value, EXPSource source, @Nullable Location hologramLocation, boolean splitExp) { Validate.isTrue(playerData.isOnline(), "Cannot give experience to offline player"); if (value <= 0) return; @@ -165,23 +167,31 @@ public class PlayerProfessions { return; } - value = MMOCore.plugin.boosterManager.calculateExp(profession, value); + // Splitting exp through party members + AbstractParty party; + if (splitExp && (party = playerData.getParty()) != null) { + List onlineMembers = party.getOnlineMembers(); + value /= onlineMembers.size(); + for (PlayerData member : onlineMembers) + if (!member.equals(playerData)) + member.getCollectionSkills().giveExperience(profession, value, source, null, false); + } - // Adds functionality for additional experience per profession. - value *= 1 + playerData.getStats().getInstance("ADDITIONAL_EXPERIENCE_" + UtilityMethods.enumName(profession.getId())).getTotal() / 100; - - // Display hologram - if (hologramLocation != null) - MMOCoreUtils.displayIndicator(hologramLocation.add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message()); + // Apply buffs AFTER splitting exp + value *= (1 + playerData.getStats().getStat("ADDITIONAL_EXPERIENCE_" + UtilityMethods.enumName(profession.getId())) / 100) * MMOCore.plugin.boosterManager.getMultiplier(profession); PlayerExperienceGainEvent event = new PlayerExperienceGainEvent(playerData, profession, value, source); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) return; + // Display hologram + if (hologramLocation != null) + MMOCoreUtils.displayIndicator(hologramLocation.add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message()); + exp.put(profession.getId(), Math.max(0, exp.getOrDefault(profession.getId(), 0.) + event.getExperience())); int level, oldLevel = getLevel(profession); - double needed,exp; + double needed, exp; /* * Loop for exp overload when leveling up, will continue diff --git a/src/main/java/net/Indyuce/mmocore/experience/Profession.java b/src/main/java/net/Indyuce/mmocore/experience/Profession.java index 42db02b1..ac71dc28 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/Profession.java +++ b/src/main/java/net/Indyuce/mmocore/experience/Profession.java @@ -127,7 +127,7 @@ public class Profession extends PostLoadObject implements ExperienceObject { public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, EXPSource source) { hologramLocation = !getOption(Profession.ProfessionOption.EXP_HOLOGRAMS) ? null : hologramLocation; - playerData.getCollectionSkills().giveExperience(this, experience, EXPSource.SOURCE, hologramLocation); + playerData.getCollectionSkills().giveExperience(this, experience, EXPSource.SOURCE, hologramLocation, true); } @Override 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 50c1405c..4f1e0588 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java @@ -197,7 +197,7 @@ public class FishingListener implements Listener { location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, 0, 4 * (RANDOM.nextDouble() - .5), RANDOM.nextDouble() + 1, 4 * (RANDOM.nextDouble() - .5), .08); if (MMOCore.plugin.fishingManager.hasLinkedProfession()) - playerData.getCollectionSkills().giveExperience(MMOCore.plugin.fishingManager.getLinkedProfession(), experienceDropped, EXPSource.FISHING, location); + playerData.getCollectionSkills().giveExperience(MMOCore.plugin.fishingManager.getLinkedProfession(), experienceDropped, EXPSource.FISHING, location, true); } } } 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 113b99ba..9d31ace6 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/social/BoosterManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/social/BoosterManager.java @@ -2,6 +2,7 @@ package net.Indyuce.mmocore.manager.social; import net.Indyuce.mmocore.experience.Booster; import net.Indyuce.mmocore.experience.Profession; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -48,7 +49,7 @@ public class BoosterManager { /** * @return Sums all current experience boosters values */ - public double getMultiplier(Profession profession) { + public double getMultiplier(@Nullable Profession profession) { double d = 1; for (Booster booster : map) @@ -58,10 +59,6 @@ public class BoosterManager { return d; } - public double calculateExp(Profession profession, double exp) { - return (exp * getMultiplier(profession)); - } - /** * @return Collection of currently registered boosters. Some of them can be * expired but are not unregistered yet! From 88da562ebdfc682f93fe5a3241b63b339eab5970 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Thu, 16 Jun 2022 11:37:32 +0200 Subject: [PATCH 3/7] Guild module --- .../java/net/Indyuce/mmocore/MMOCore.java | 25 +- .../comp/placeholder/RPGPlaceholders.java | 4 +- .../gui/social/guild/EditableGuildAdmin.java | 33 ++- .../gui/social/guild/EditableGuildView.java | 32 ++- .../Indyuce/mmocore/guild/AbstractGuild.java | 7 + .../mmocore/guild/GuildModuleType.java | 4 +- .../guild/compat/FactionsGuildModule.java | 14 +- .../guild/compat/GuildsGuildModule.java | 10 +- .../guild/compat/KingdomsXGuildModule.java | 16 +- .../compat/UltimateClansGuildModule.java | 11 +- .../Indyuce/mmocore/guild/provided/Guild.java | 242 ++++++++---------- .../mmocore/guild/provided/GuildInvite.java | 2 +- .../mmocore/listener/GuildListener.java | 2 +- .../mmocore/manager/ConfigManager.java | 3 +- .../manager/data/GuildDataManager.java | 2 +- .../data/mysql/MySQLPlayerDataManager.java | 2 +- .../data/yaml/YAMLGuildDataManager.java | 2 +- .../data/yaml/YAMLPlayerDataManager.java | 2 +- src/main/resources/config.yml | 24 +- 19 files changed, 254 insertions(+), 183 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/MMOCore.java b/src/main/java/net/Indyuce/mmocore/MMOCore.java index 3af53024..6c9c9454 100644 --- a/src/main/java/net/Indyuce/mmocore/MMOCore.java +++ b/src/main/java/net/Indyuce/mmocore/MMOCore.java @@ -25,7 +25,10 @@ import net.Indyuce.mmocore.comp.region.WorldGuardMMOLoader; import net.Indyuce.mmocore.comp.region.WorldGuardRegionHandler; import net.Indyuce.mmocore.comp.vault.VaultEconomy; import net.Indyuce.mmocore.comp.vault.VaultMMOLoader; +import net.Indyuce.mmocore.guild.GuildModule; +import net.Indyuce.mmocore.guild.GuildModuleType; import net.Indyuce.mmocore.guild.provided.Guild; +import net.Indyuce.mmocore.guild.provided.MMOCoreGuildModule; import net.Indyuce.mmocore.listener.*; import net.Indyuce.mmocore.listener.event.PlayerPressKeyListener; import net.Indyuce.mmocore.listener.option.*; @@ -97,6 +100,8 @@ public class MMOCore extends LuminePlugin { // Modules @NotNull public PartyModule partyModule; + @NotNull + public GuildModule guildModule; public boolean shouldDebugSQL = false; @@ -216,8 +221,8 @@ public class MMOCore extends LuminePlugin { // Load quest module try { - String questPluginName = UtilityMethods.enumName(getConfig().getString("quest-plugin")); - PartyModuleType moduleType = PartyModuleType.valueOf(questPluginName); + String pluginName = UtilityMethods.enumName(getConfig().getString("quest-plugin")); + PartyModuleType moduleType = PartyModuleType.valueOf(pluginName); Validate.isTrue(moduleType.isValid(), "Plugin '" + moduleType.name() + "' is not installed"); partyModule = moduleType.provideModule(); } catch (RuntimeException exception) { @@ -225,12 +230,10 @@ public class MMOCore extends LuminePlugin { partyModule = new MMOCorePartyModule(); } - - // Load party module try { - String partyPluginName = UtilityMethods.enumName(getConfig().getString("party-plugin")); - PartyModuleType moduleType = PartyModuleType.valueOf(partyPluginName); + String pluginName = UtilityMethods.enumName(getConfig().getString("party-plugin")); + PartyModuleType moduleType = PartyModuleType.valueOf(pluginName); Validate.isTrue(moduleType.isValid(), "Plugin '" + moduleType.name() + "' is not installed"); partyModule = moduleType.provideModule(); } catch (RuntimeException exception) { @@ -238,6 +241,16 @@ public class MMOCore extends LuminePlugin { partyModule = new MMOCorePartyModule(); } + // Load guild module + try { + String pluginName = UtilityMethods.enumName(getConfig().getString("guild-plugin")); + GuildModuleType moduleType = GuildModuleType.valueOf(pluginName); + Validate.isTrue(moduleType.isValid(), "Plugin '" + moduleType.name() + "' is not installed"); + guildModule = moduleType.provideModule(); + } catch (RuntimeException exception) { + getLogger().log(Level.WARNING, "Could not initialize guild module: " + exception.getMessage()); + guildModule = new MMOCoreGuildModule(); + } // Skill casting try { diff --git a/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java b/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java index 795ac3a1..944b25e6 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java +++ b/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java @@ -226,9 +226,9 @@ public class RPGPlaceholders extends PlaceholderExpansion { else if (placeholder.equalsIgnoreCase("leader")) return Bukkit.getOfflinePlayer(playerData.getGuild().getOwner()).getName(); else if (placeholder.equalsIgnoreCase("members")) - return "" + playerData.getGuild().getMembers().count(); + return String.valueOf(playerData.getGuild().countMembers()); else if (placeholder.equalsIgnoreCase("online_members")) - return "" + playerData.getGuild().getMembers().countOnline(); + return String.valueOf(playerData.getGuild().countOnlineMembers()); } return null; diff --git a/src/main/java/net/Indyuce/mmocore/gui/social/guild/EditableGuildAdmin.java b/src/main/java/net/Indyuce/mmocore/gui/social/guild/EditableGuildAdmin.java index accda5e7..33fca626 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/social/guild/EditableGuildAdmin.java +++ b/src/main/java/net/Indyuce/mmocore/gui/social/guild/EditableGuildAdmin.java @@ -1,7 +1,5 @@ package net.Indyuce.mmocore.gui.social.guild; -import io.lumine.mythic.lib.api.item.ItemTag; -import io.lumine.mythic.lib.api.item.NBTItem; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.util.input.PlayerInput.InputType; @@ -25,6 +23,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.persistence.PersistentDataType; +import java.util.List; import java.util.UUID; public class EditableGuildAdmin extends EditableInventory { @@ -43,7 +42,7 @@ public class EditableGuildAdmin extends EditableInventory { return new GuildViewInventory(data, this); } - public static class MemberDisplayItem extends InventoryItem { + public static class MemberDisplayItem extends InventoryItem { public MemberDisplayItem(MemberItem memberItem, ConfigurationSection config) { super(memberItem, config); } @@ -54,8 +53,8 @@ public class EditableGuildAdmin extends EditableInventory { } @Override - public Placeholders getPlaceholders(GeneratedInventory inv, int n) { - PlayerData member = PlayerData.get(inv.getPlayerData().getGuild().getMembers().get(n)); + public Placeholders getPlaceholders(GuildViewInventory inv, int n) { + PlayerData member = PlayerData.get(inv.members.get(n)); Placeholders holders = new Placeholders(); @@ -68,8 +67,8 @@ public class EditableGuildAdmin extends EditableInventory { } @Override - public ItemStack display(GeneratedInventory inv, int n) { - UUID uuid = inv.getPlayerData().getGuild().getMembers().get(n); + public ItemStack display(GuildViewInventory inv, int n) { + UUID uuid = inv.members.get(n); OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid); ItemStack disp = super.display(inv, n); @@ -87,7 +86,7 @@ public class EditableGuildAdmin extends EditableInventory { } } - public static class MemberItem extends SimplePlaceholderItem { + public static class MemberItem extends SimplePlaceholderItem { private final InventoryItem empty; private final MemberDisplayItem member; @@ -102,8 +101,8 @@ public class EditableGuildAdmin extends EditableInventory { } @Override - public ItemStack display(GeneratedInventory inv, int n) { - return inv.getPlayerData().getGuild().getMembers().count() > n ? member.display(inv, n) : empty.display(inv, n); + public ItemStack display(GuildViewInventory inv, int n) { + return inv.getPlayerData().getGuild().countMembers() > n ? member.display(inv, n) : empty.display(inv, n); } @Override @@ -115,15 +114,23 @@ public class EditableGuildAdmin extends EditableInventory { public class GuildViewInventory extends GeneratedInventory { private final int max; + private List members; + public GuildViewInventory(PlayerData playerData, EditableInventory editable) { super(playerData, editable); max = editable.getByFunction("member").getSlots().size(); } + @Override + public void open() { + members = playerData.getGuild().listMembers(); + super.open(); + } + @Override public String calculateName() { - return getName().replace("{max}", "" + max).replace("{players}", "" + getPlayerData().getGuild().getMembers().count()); + return getName().replace("{max}", "" + max).replace("{players}", "" + getPlayerData().getGuild().countMembers()); } @Override @@ -138,7 +145,7 @@ public class EditableGuildAdmin extends EditableInventory { if (item.getFunction().equals("invite")) { - if (playerData.getGuild().getMembers().count() >= max) { + if (playerData.getGuild().countMembers() >= max) { MMOCore.plugin.configManager.getSimpleMessage("guild-is-full").send(player); player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1); return; @@ -162,7 +169,7 @@ public class EditableGuildAdmin extends EditableInventory { } PlayerData targetData = PlayerData.get(target); - if (playerData.getGuild().getMembers().has(target.getUniqueId())) { + if (playerData.getGuild().hasMember(target.getUniqueId())) { MMOCore.plugin.configManager.getSimpleMessage("already-in-guild", "player", target.getName()).send(player); player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1); open(); diff --git a/src/main/java/net/Indyuce/mmocore/gui/social/guild/EditableGuildView.java b/src/main/java/net/Indyuce/mmocore/gui/social/guild/EditableGuildView.java index 165b87e3..450c1228 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/social/guild/EditableGuildView.java +++ b/src/main/java/net/Indyuce/mmocore/gui/social/guild/EditableGuildView.java @@ -21,6 +21,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.persistence.PersistentDataType; +import java.util.List; import java.util.UUID; public class EditableGuildView extends EditableInventory { @@ -35,7 +36,7 @@ public class EditableGuildView extends EditableInventory { return function.equals("member") ? new MemberItem(config) : (function.equals("next") || function.equals("previous") || function.equals("disband") || function.equals("invite")) ? new ConditionalItem(function, config) : new SimplePlaceholderItem(config); } - public static class MemberDisplayItem extends InventoryItem { + public static class MemberDisplayItem extends InventoryItem { public MemberDisplayItem(MemberItem memberItem, ConfigurationSection config) { super(memberItem, config); } @@ -46,8 +47,8 @@ public class EditableGuildView extends EditableInventory { } @Override - public Placeholders getPlaceholders(GeneratedInventory inv, int n) { - UUID uuid = inv.getPlayerData().getGuild().getMembers().get(n); + public Placeholders getPlaceholders(GuildViewInventory inv, int n) { + UUID uuid = inv.members.get(n); Placeholders holders = new Placeholders(); /* * Will never be null since a players name will always be recorded @@ -64,8 +65,8 @@ public class EditableGuildView extends EditableInventory { } @Override - public ItemStack display(GeneratedInventory inv, int n) { - UUID uuid = inv.getPlayerData().getGuild().getMembers().get(n); + public ItemStack display(GuildViewInventory inv, int n) { + UUID uuid = inv.members.get(n); ItemStack disp = super.display(inv, n); ItemMeta meta = disp.getItemMeta(); @@ -99,7 +100,7 @@ public class EditableGuildView extends EditableInventory { @Override public ItemStack display(GuildViewInventory inv, int n) { int index = n * inv.getPage(); - return inv.getPlayerData().getGuild().getMembers().count() > index ? member.display(inv, index) : empty.display(inv, index); + return inv.getPlayerData().getGuild().countMembers() > index ? member.display(inv, index) : empty.display(inv, index); } @Override @@ -120,7 +121,7 @@ public class EditableGuildView extends EditableInventory { public ItemStack display(GuildViewInventory inv, int n) { if (function.equals("next")) - if (inv.getPage() == (inv.getPlayerData().getGuild().getMembers().count() + 20) + if (inv.getPage() == (inv.getPlayerData().getGuild().countMembers() + 20) / inv.getByFunction("member").getSlots().size()) return null; if (function.equals("previous") && inv.getPage() == 1) @@ -136,19 +137,26 @@ public class EditableGuildView extends EditableInventory { } public class GuildViewInventory extends GeneratedInventory { - private int page = 1; private final int maxpages; + private int page = 1; + private List members; + public GuildViewInventory(PlayerData playerData, EditableInventory editable) { super(playerData, editable); - maxpages = (playerData.getGuild().getMembers().count() + 20) - / editable.getByFunction("member").getSlots().size(); + maxpages = (playerData.getGuild().countMembers() + 20) / editable.getByFunction("member").getSlots().size(); + } + + @Override + public void open() { + members = playerData.getGuild().listMembers(); + super.open(); } @Override public String calculateName() { - return getName().replace("{online_players}", "" + getPlayerData().getGuild().getMembers().countOnline()).replace("{page}", "" + page).replace("{maxpages}", "" + maxpages).replace("{players}", "" + getPlayerData().getGuild().getMembers().count()).replace("{tag}", getPlayerData().getGuild().getTag()).replace("{name}", getPlayerData().getGuild().getName()); + return getName().replace("{online_players}", "" + getPlayerData().getGuild().countOnlineMembers()).replace("{page}", "" + page).replace("{maxpages}", "" + maxpages).replace("{players}", String.valueOf(getPlayerData().getGuild().countMembers())).replace("{tag}", getPlayerData().getGuild().getTag()).replace("{name}", getPlayerData().getGuild().getName()); } @Override @@ -209,7 +217,7 @@ public class EditableGuildView extends EditableInventory { } PlayerData targetData = PlayerData.get(target); - if (playerData.getGuild().getMembers().has(targetData.getUniqueId())) { + if (playerData.getGuild().hasMember(targetData.getUniqueId())) { MMOCore.plugin.configManager.getSimpleMessage("already-in-guild", "player", target.getName()).send(player); player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1); open(); diff --git a/src/main/java/net/Indyuce/mmocore/guild/AbstractGuild.java b/src/main/java/net/Indyuce/mmocore/guild/AbstractGuild.java index 670c5a06..29694a1a 100644 --- a/src/main/java/net/Indyuce/mmocore/guild/AbstractGuild.java +++ b/src/main/java/net/Indyuce/mmocore/guild/AbstractGuild.java @@ -1,4 +1,11 @@ package net.Indyuce.mmocore.guild; +import org.bukkit.entity.Player; + public interface AbstractGuild { + + /** + * @return If given player is in that party + */ + boolean hasMember(Player player); } diff --git a/src/main/java/net/Indyuce/mmocore/guild/GuildModuleType.java b/src/main/java/net/Indyuce/mmocore/guild/GuildModuleType.java index bca192f4..dab5c398 100644 --- a/src/main/java/net/Indyuce/mmocore/guild/GuildModuleType.java +++ b/src/main/java/net/Indyuce/mmocore/guild/GuildModuleType.java @@ -1,6 +1,5 @@ package net.Indyuce.mmocore.guild; -import net.Indyuce.mmocore.guild.compat.FactionsGuildModule; import net.Indyuce.mmocore.guild.compat.GuildsGuildModule; import net.Indyuce.mmocore.guild.compat.UltimateClansGuildModule; import net.Indyuce.mmocore.guild.provided.MMOCoreGuildModule; @@ -9,7 +8,8 @@ import org.bukkit.Bukkit; import javax.inject.Provider; public enum GuildModuleType { - FACTIONS("Factions", FactionsGuildModule::new), + // Useless since MythicLib already supports FactionBridge + // FACTIONS("Factions", FactionsGuildModule::new), GUILDS("Guilds", GuildsGuildModule::new), KINGDOMSX("Guilds", GuildsGuildModule::new), MMOCORE("MMOCore", MMOCoreGuildModule::new), diff --git a/src/main/java/net/Indyuce/mmocore/guild/compat/FactionsGuildModule.java b/src/main/java/net/Indyuce/mmocore/guild/compat/FactionsGuildModule.java index 066b6181..bf3b4447 100644 --- a/src/main/java/net/Indyuce/mmocore/guild/compat/FactionsGuildModule.java +++ b/src/main/java/net/Indyuce/mmocore/guild/compat/FactionsGuildModule.java @@ -6,13 +6,20 @@ import com.massivecraft.factions.Faction; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.guild.AbstractGuild; import net.Indyuce.mmocore.guild.GuildModule; +import org.apache.commons.lang.NotImplementedException; +import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import java.util.Objects; + public class FactionsGuildModule implements GuildModule { @Override public AbstractGuild getGuild(PlayerData playerData) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(playerData.getPlayer()); + if (fPlayer == null) + return null; + return fPlayer.hasFaction() ? new CustomGuild(fPlayer.getFaction()) : null; } @@ -22,7 +29,12 @@ public class FactionsGuildModule implements GuildModule { private final Faction faction; CustomGuild(Faction faction) { - this.faction = faction; + this.faction = Objects.requireNonNull(faction); + } + + @Override + public boolean hasMember(Player player) { + throw new NotImplementedException(); } } } diff --git a/src/main/java/net/Indyuce/mmocore/guild/compat/GuildsGuildModule.java b/src/main/java/net/Indyuce/mmocore/guild/compat/GuildsGuildModule.java index bfeca8ce..2350fd88 100644 --- a/src/main/java/net/Indyuce/mmocore/guild/compat/GuildsGuildModule.java +++ b/src/main/java/net/Indyuce/mmocore/guild/compat/GuildsGuildModule.java @@ -5,8 +5,11 @@ import me.glaremasters.guilds.guild.Guild; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.guild.AbstractGuild; import net.Indyuce.mmocore.guild.GuildModule; +import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import java.util.Objects; + public class GuildsGuildModule implements GuildModule { @Override @@ -21,7 +24,12 @@ public class GuildsGuildModule implements GuildModule { private final Guild guild; CustomGuild(Guild guild) { - this.guild = guild; + this.guild = Objects.requireNonNull(guild); + } + + @Override + public boolean hasMember(Player player) { + return guild.getMember(player.getUniqueId()) != null; } } } diff --git a/src/main/java/net/Indyuce/mmocore/guild/compat/KingdomsXGuildModule.java b/src/main/java/net/Indyuce/mmocore/guild/compat/KingdomsXGuildModule.java index 21487d76..41eed066 100644 --- a/src/main/java/net/Indyuce/mmocore/guild/compat/KingdomsXGuildModule.java +++ b/src/main/java/net/Indyuce/mmocore/guild/compat/KingdomsXGuildModule.java @@ -3,18 +3,23 @@ package net.Indyuce.mmocore.guild.compat; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.guild.AbstractGuild; import net.Indyuce.mmocore.guild.GuildModule; +import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.kingdoms.constants.kingdom.Kingdom; import org.kingdoms.constants.player.KingdomPlayer; import org.kingdoms.main.Kingdoms; +import java.util.Objects; + public class KingdomsXGuildModule implements GuildModule { @Override public AbstractGuild getGuild(PlayerData playerData) { KingdomPlayer kPlayer = Kingdoms.get().getDataHandlers().getKingdomPlayerManager().getData(playerData.getUniqueId()); - Kingdom kingdom = kPlayer == null ? null : kPlayer.getKingdom(); + if (kPlayer == null) + return null; + + Kingdom kingdom = kPlayer.getKingdom(); return kingdom == null ? null : new CustomGuild(kingdom); } @@ -24,7 +29,12 @@ public class KingdomsXGuildModule implements GuildModule { private final Kingdom kingdom; CustomGuild(Kingdom kingdom) { - this.kingdom = kingdom; + this.kingdom = Objects.requireNonNull(kingdom); + } + + @Override + public boolean hasMember(Player player) { + return kingdom.isMember(player); } } } diff --git a/src/main/java/net/Indyuce/mmocore/guild/compat/UltimateClansGuildModule.java b/src/main/java/net/Indyuce/mmocore/guild/compat/UltimateClansGuildModule.java index 1005db38..2996a53d 100644 --- a/src/main/java/net/Indyuce/mmocore/guild/compat/UltimateClansGuildModule.java +++ b/src/main/java/net/Indyuce/mmocore/guild/compat/UltimateClansGuildModule.java @@ -6,8 +6,11 @@ import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.guild.AbstractGuild; import net.Indyuce.mmocore.guild.GuildModule; import org.bukkit.Bukkit; +import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import java.util.Objects; + public class UltimateClansGuildModule implements GuildModule { private static final UClans API = (UClans) Bukkit.getPluginManager().getPlugin("UltimateCLans"); @@ -22,7 +25,13 @@ public class UltimateClansGuildModule implements GuildModule { private final ClanData clan; CustomGuild(ClanData clan) { - this.clan = clan; + this.clan = Objects.requireNonNull(clan); + } + + @Override + public boolean hasMember(Player player) { + // List implementation. Pretty bad + return clan.getMembers().contains(player); } } } diff --git a/src/main/java/net/Indyuce/mmocore/guild/provided/Guild.java b/src/main/java/net/Indyuce/mmocore/guild/provided/Guild.java index 32106ae8..33aefcab 100644 --- a/src/main/java/net/Indyuce/mmocore/guild/provided/Guild.java +++ b/src/main/java/net/Indyuce/mmocore/guild/provided/Guild.java @@ -1,164 +1,148 @@ package net.Indyuce.mmocore.guild.provided; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.function.Consumer; - -import net.Indyuce.mmocore.guild.AbstractGuild; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.ConfigMessage; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.social.Request; import net.Indyuce.mmocore.gui.api.PluginInventory; import net.Indyuce.mmocore.gui.social.guild.EditableGuildView.GuildViewInventory; +import net.Indyuce.mmocore.guild.AbstractGuild; import net.Indyuce.mmocore.manager.InventoryManager; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.*; +import java.util.function.Consumer; public class Guild implements AbstractGuild { - private final GuildMembers members = new GuildMembers(); - private final Map invites = new HashMap<>(); - private final String guildId, guildName, guildTag; + private final Map invites = new HashMap<>(); + private final String guildId, guildName, guildTag; - /** - * Owner changes when the old owner leaves guild - */ - private UUID owner; + private final Set members = new HashSet<>(); - public Guild(UUID owner, String name, String tag) { - this.owner = owner; - this.guildId = tag.toLowerCase(); - this.guildName = name; - this.guildTag = tag; - } + /** + * Owner changes when the old owner leaves guild + */ + private UUID owner; - public UUID getOwner() { - return owner; - } - - public String getName() { - return guildName; - } + public Guild(UUID owner, String name, String tag) { + this.owner = owner; + this.guildId = tag.toLowerCase(); + this.guildName = name; + this.guildTag = tag; + } - public String getId() { - return guildId; - } - - public String getTag() { - return guildTag; - } + public UUID getOwner() { + return owner; + } - public GuildMembers getMembers() { - return members; - } + public String getName() { + return guildName; + } - public long getLastInvite(Player player) { - return invites.containsKey(player.getUniqueId()) ? invites.get(player.getUniqueId()) : 0; - } + public String getId() { + return guildId; + } - public void removeLastInvite(Player player) { - invites.remove(player.getUniqueId()); - } - - public void removeMember(UUID uuid) - { removeMember(uuid, false); } - - // Disband boolean is to prevent co-modification exception when disbanding a guild - public void removeMember(UUID uuid, boolean disband) { - PlayerData data = PlayerData.get(uuid); - if (data != null && data.isOnline() && data.getPlayer().getOpenInventory() != null && data.getPlayer().getOpenInventory().getTopInventory().getHolder() instanceof GuildViewInventory) - InventoryManager.GUILD_CREATION.newInventory(data).open(); + public String getTag() { + return guildTag; + } - if(!disband) members.remove(uuid); - if(data != null) data.setGuild(null); - reopenInventories(); + public long getLastInvite(Player player) { + return invites.containsKey(player.getUniqueId()) ? invites.get(player.getUniqueId()) : 0; + } - //if(!disband) { + public void removeLastInvite(Player player) { + invites.remove(player.getUniqueId()); + } - // disband the guild if no member left - if (members.count() < 1) { - MMOCore.plugin.dataProvider.getGuildManager().unregisterGuild(this); - return; - } + public void removeMember(UUID uuid) { + removeMember(uuid, false); + } - // transfer ownership - if (owner.equals(uuid)) { - owner = members.get(0); - MMOCore.plugin.configManager.getSimpleMessage("transfer-guild-ownership").send(Bukkit.getPlayer(owner)); - } - //} - } + // Disband boolean is to prevent co-modification exception when disbanding a guild + public void removeMember(UUID uuid, boolean disband) { + PlayerData data = PlayerData.get(uuid); + if (data != null && data.isOnline() && data.getPlayer().getOpenInventory() != null && data.getPlayer().getOpenInventory().getTopInventory().getHolder() instanceof GuildViewInventory) + InventoryManager.GUILD_CREATION.newInventory(data).open(); - public void addMember(UUID uuid) { - PlayerData data = PlayerData.get(uuid); - if (data.inGuild()) - data.getGuild().removeMember(uuid); + if (!disband) + members.remove(uuid); + if (data != null) + data.setGuild(null); + reopenInventories(); - data.setGuild(this); - members.add(uuid); + // Disband the guild if no member left + if (members.size() < 1) { + MMOCore.plugin.dataProvider.getGuildManager().unregisterGuild(this); + return; + } - reopenInventories(); - } - - public void registerMember(UUID uuid) { - members.add(uuid); - } + // Transfer ownership + if (owner.equals(uuid)) { + owner = members.stream().findAny().get(); + MMOCore.plugin.configManager.getSimpleMessage("transfer-guild-ownership").send(Bukkit.getPlayer(owner)); + } + } - public void reopenInventories() { - for (UUID uuid : members.members) { - PlayerData member = PlayerData.get(uuid); - if (member != null && member.isOnline() && member.getPlayer().getOpenInventory() != null && member.getPlayer().getOpenInventory().getTopInventory().getHolder() instanceof GuildViewInventory) - ((PluginInventory) member.getPlayer().getOpenInventory().getTopInventory().getHolder()).open(); - } - } + public void addMember(UUID uuid) { + PlayerData data = PlayerData.get(uuid); + if (data.inGuild()) + data.getGuild().removeMember(uuid); - public void sendGuildInvite(PlayerData inviter, PlayerData target) { - invites.put(target.getUniqueId(), System.currentTimeMillis()); - Request request = new GuildInvite(this, inviter, target); - new ConfigMessage("guild-invite").addPlaceholders("player", inviter.getPlayer().getName(), "uuid", request.getUniqueId().toString()).sendAsJSon(target.getPlayer()); - MMOCore.plugin.requestManager.registerRequest(request); - } - - public static class GuildMembers { - private final List members = new ArrayList<>(); + data.setGuild(this); + members.add(uuid); - public UUID get(int count) { - return members.get(count); - } + reopenInventories(); + } - public boolean has(UUID player) { - return members.contains(player); - } + public void registerMember(UUID uuid) { + members.add(uuid); + } - public void add(UUID player) { - members.add(player); - } + public void reopenInventories() { + for (UUID uuid : members) { + PlayerData member = PlayerData.get(uuid); + if (member != null && member.isOnline() && member.getPlayer().getOpenInventory() != null && member.getPlayer().getOpenInventory().getTopInventory().getHolder() instanceof GuildViewInventory) + ((PluginInventory) member.getPlayer().getOpenInventory().getTopInventory().getHolder()).open(); + } + } - public void remove(UUID player) { - members.remove(player); - } + public void sendGuildInvite(PlayerData inviter, PlayerData target) { + invites.put(target.getUniqueId(), System.currentTimeMillis()); + Request request = new GuildInvite(this, inviter, target); + new ConfigMessage("guild-invite").addPlaceholders("player", inviter.getPlayer().getName(), "uuid", request.getUniqueId().toString()).sendAsJSon(target.getPlayer()); + MMOCore.plugin.requestManager.registerRequest(request); + } - public void forEach(Consumer action) { - members.forEach(action); - } + @Override + public boolean hasMember(Player player) { + return hasMember(player.getUniqueId()); + } - public int countOnline() { - int online = 0; - - for(UUID member : members) - if(Bukkit.getOfflinePlayer(member).isOnline()) - online += 1; - - return online; - } + public boolean hasMember(UUID player) { + return members.contains(player); + } - public int count() - { return members.size(); } - public void clear() - { members.clear(); } - } + public List listMembers() { + return new ArrayList<>(members); + } + + public void forEachMember(Consumer action) { + members.forEach(action); + } + + public int countOnlineMembers() { + int online = 0; + + for (UUID member : members) + if (Bukkit.getOfflinePlayer(member).isOnline()) + online++; + + return online; + } + + public int countMembers() { + return members.size(); + } } diff --git a/src/main/java/net/Indyuce/mmocore/guild/provided/GuildInvite.java b/src/main/java/net/Indyuce/mmocore/guild/provided/GuildInvite.java index 7e908639..7c6a9a9b 100644 --- a/src/main/java/net/Indyuce/mmocore/guild/provided/GuildInvite.java +++ b/src/main/java/net/Indyuce/mmocore/guild/provided/GuildInvite.java @@ -27,7 +27,7 @@ public class GuildInvite extends Request { @Override public void whenAccepted() { guild.removeLastInvite(getCreator().getPlayer()); - guild.getMembers().forEach(member -> { + guild.forEachMember(member -> { if (Bukkit.getPlayer(member) != null) { MMOCore.plugin.configManager.getSimpleMessage("guild-joined-other", "player", getTarget().getPlayer().getName()).send(Bukkit.getPlayer(member)); diff --git a/src/main/java/net/Indyuce/mmocore/listener/GuildListener.java b/src/main/java/net/Indyuce/mmocore/listener/GuildListener.java index c94ce3f0..43aaad9b 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/GuildListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/GuildListener.java @@ -32,7 +32,7 @@ public class GuildListener implements Listener { GuildChatEvent called = new GuildChatEvent(data, format.message()); Bukkit.getPluginManager().callEvent(called); if (!called.isCancelled()) - data.getGuild().getMembers().forEach(member -> { + data.getGuild().forEachMember(member -> { Player p = Bukkit.getPlayer(member); if (p != null) format.send(p); diff --git a/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java index 137160c3..2ecfc2ec 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java @@ -23,7 +23,7 @@ import java.util.logging.Level; public class ConfigManager { public final CommandVerbose commandVerbose = new CommandVerbose(); - public boolean overrideVanillaExp, canCreativeCast, cobbleGeneratorXP, saveDefaultClassInfo; + public boolean overrideVanillaExp, canCreativeCast, cobbleGeneratorXP, saveDefaultClassInfo, attributesAsClassInfo; public String partyChatPrefix, noSkillBoundPlaceholder; public ChatColor staminaFull, staminaHalf, staminaEmpty; public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown, globalSkillCooldown; @@ -99,6 +99,7 @@ public class ConfigManager { globalSkillCooldown = MMOCore.plugin.getConfig().getLong("global-skill-cooldown") * 50; noSkillBoundPlaceholder = getSimpleMessage("no-skill-placeholder").message(); lootChestsChanceWeight = MMOCore.plugin.getConfig().getDouble("chance-stat-weight.loot-chests"); + attributesAsClassInfo = MMOCore.plugin.getConfig().getBoolean("attributes-as-class-info"); staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN); staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN); diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/GuildDataManager.java b/src/main/java/net/Indyuce/mmocore/manager/data/GuildDataManager.java index cedf04aa..1c3a8f43 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/data/GuildDataManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/data/GuildDataManager.java @@ -33,7 +33,7 @@ public abstract class GuildDataManager { } public void unregisterGuild(Guild guild) { - guild.getMembers().forEach(member -> guild.removeMember(member, true)); + guild.forEachMember(member -> guild.removeMember(member, true)); // guild.getMembers().clear(); guilds.remove(guild.getId()); delete(guild); diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java b/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java index 66d5ed47..a01e69f4 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java @@ -71,7 +71,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager { if (!isEmpty(result.getString("guild"))) { Guild guild = provider.getGuildManager().getGuild(result.getString("guild")); - data.setGuild(guild.getMembers().has(data.getUniqueId()) ? guild : null); + data.setGuild(guild.hasMember(data.getUniqueId()) ? guild : null); } if (!isEmpty(result.getString("attributes"))) data.getAttributes().load(result.getString("attributes")); if (!isEmpty(result.getString("professions"))) diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLGuildDataManager.java b/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLGuildDataManager.java index 8c4e0808..15d9e65e 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLGuildDataManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLGuildDataManager.java @@ -22,7 +22,7 @@ public class YAMLGuildDataManager extends GuildDataManager { config.getConfig().set("owner", guild.getOwner().toString()); List memberList = new ArrayList<>(); - guild.getMembers().forEach(uuid -> memberList.add(uuid.toString())); + guild.forEachMember(uuid -> memberList.add(uuid.toString())); config.getConfig().set("members", memberList); config.save(); diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java b/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java index e8eaa739..e9f6986d 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java @@ -47,7 +47,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager { if (config.contains("guild")) { Guild guild = provider.getGuildManager().getGuild(config.getString("guild")); - data.setGuild(guild.getMembers().has(data.getUniqueId()) ? guild : null); + data.setGuild(guild.hasMember(data.getUniqueId()) ? guild : null); } if (config.contains("attribute")) data.getAttributes().load(config.getConfigurationSection("attribute")); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index db45266d..aadb32bf 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -59,14 +59,22 @@ protect-custom-mine: false # - mcmmo party-plugin: mmocore -## Edit the plugin handling parties here. -## Supported values (just copy and paste): -## - mmocore -## - beauty_quest -## - quest_creator -## - quests +# Edit the plugin handling parties here. +# Supported values (just copy and paste): +# - mmocore +# - beauty_quest +# - quest_creator +# - quests quest-plugin: mmocore +# Edit the plugin handling guilds here. +# Supported values (just copy and paste): +# - mmocore +# - guilds +# - kingdomsx +# - ultimate_clans +guild-plugin: mmocore + # MythicLib introduces a CHANCE stat that is used in # several different systems in MMOCore. By changing these # weights you can define how much the Chance stat impacts @@ -206,6 +214,10 @@ resource-bar-colors: stamina-half: 'DARK_GREEN' stamina-empty: 'WHITE' +# When set to true, attributes are saved and +# reset when a player changes their class. +attributes-as-class-info: true + # Whether or not the admin commands should display # the result of the command when ran. # For Example: "Players Level is now 10." From 9004ce8ea15add155a4c5e5750c062c49fb7b2eb Mon Sep 17 00:00:00 2001 From: Indyuce Date: Fri, 17 Jun 2022 18:33:24 +0200 Subject: [PATCH 4/7] Guild module works with ability targets --- .../java/net/Indyuce/mmocore/MMOCore.java | 1 - .../mmocore/guild/GuildModuleType.java | 3 ++- .../party/MMOCoreTargetRestriction.java | 19 +++++++++++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/MMOCore.java b/src/main/java/net/Indyuce/mmocore/MMOCore.java index 6c9c9454..72845b4c 100644 --- a/src/main/java/net/Indyuce/mmocore/MMOCore.java +++ b/src/main/java/net/Indyuce/mmocore/MMOCore.java @@ -124,7 +124,6 @@ public class MMOCore extends LuminePlugin { MythicLib.plugin.getEntities().registerRestriction(new MMOCoreTargetRestriction()); MythicLib.plugin.getModifiers().registerModifierType("attribute", configObject -> new AttributeModifier(configObject)); - // Register extra objective, drop items... if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) loadManager.registerLoader(new WorldGuardMMOLoader()); diff --git a/src/main/java/net/Indyuce/mmocore/guild/GuildModuleType.java b/src/main/java/net/Indyuce/mmocore/guild/GuildModuleType.java index dab5c398..cfbbaf25 100644 --- a/src/main/java/net/Indyuce/mmocore/guild/GuildModuleType.java +++ b/src/main/java/net/Indyuce/mmocore/guild/GuildModuleType.java @@ -1,6 +1,7 @@ package net.Indyuce.mmocore.guild; import net.Indyuce.mmocore.guild.compat.GuildsGuildModule; +import net.Indyuce.mmocore.guild.compat.KingdomsXGuildModule; import net.Indyuce.mmocore.guild.compat.UltimateClansGuildModule; import net.Indyuce.mmocore.guild.provided.MMOCoreGuildModule; import org.bukkit.Bukkit; @@ -11,7 +12,7 @@ public enum GuildModuleType { // Useless since MythicLib already supports FactionBridge // FACTIONS("Factions", FactionsGuildModule::new), GUILDS("Guilds", GuildsGuildModule::new), - KINGDOMSX("Guilds", GuildsGuildModule::new), + KINGDOMSX("KingdomsX", KingdomsXGuildModule::new), MMOCORE("MMOCore", MMOCoreGuildModule::new), ULTIMATE_CLANS("UltimateClans", UltimateClansGuildModule::new), ; diff --git a/src/main/java/net/Indyuce/mmocore/party/MMOCoreTargetRestriction.java b/src/main/java/net/Indyuce/mmocore/party/MMOCoreTargetRestriction.java index e3603461..0e67bf43 100644 --- a/src/main/java/net/Indyuce/mmocore/party/MMOCoreTargetRestriction.java +++ b/src/main/java/net/Indyuce/mmocore/party/MMOCoreTargetRestriction.java @@ -4,6 +4,7 @@ import io.lumine.mythic.lib.comp.target.InteractionType; import io.lumine.mythic.lib.comp.target.TargetRestriction; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.guild.AbstractGuild; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -11,11 +12,21 @@ public class MMOCoreTargetRestriction implements TargetRestriction { @Override public boolean canTarget(Player player, LivingEntity livingEntity, InteractionType interactionType) { - if (!interactionType.isOffense() || !(livingEntity instanceof Player) || livingEntity.hasMetadata("NPC")) + if (!interactionType.isOffense() || !(livingEntity instanceof Player)) return true; - AbstractParty party = MMOCore.plugin.partyModule.getParty(PlayerData.get(player)); - // TODO check for guild - return party == null || !party.hasMember((Player) livingEntity); + PlayerData data = PlayerData.get(player); + + // Check for party + AbstractParty party = MMOCore.plugin.partyModule.getParty(data); + if (party != null && party.hasMember((Player) livingEntity)) + return false; + + // Check for guild + AbstractGuild guild = MMOCore.plugin.guildModule.getGuild(data); + if (guild != null && guild.hasMember((Player) livingEntity)) + return false; + + return true; } } From 1aa7d96347c4f65c1cb4d8c0b922939c32c9f3f2 Mon Sep 17 00:00:00 2001 From: Jules Date: Sat, 18 Jun 2022 12:35:26 +0200 Subject: [PATCH 5/7] Option to prevent high party level difference --- .../gui/social/party/EditablePartyView.java | 7 +++++++ .../Indyuce/mmocore/manager/ConfigManager.java | 1 - .../net/Indyuce/mmocore/party/provided/Party.java | 13 +++++++++++++ src/main/resources/config.yml | 15 +++++++++++++-- src/main/resources/default/messages.yml | 1 + 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/gui/social/party/EditablePartyView.java b/src/main/java/net/Indyuce/mmocore/gui/social/party/EditablePartyView.java index ce442cf2..aa93e292 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/social/party/EditablePartyView.java +++ b/src/main/java/net/Indyuce/mmocore/gui/social/party/EditablePartyView.java @@ -172,6 +172,13 @@ public class EditablePartyView extends EditableInventory { return; } + if (Math.abs(targetData.getLevel() - party.getLevel()) > MMOCore.plugin.configManager.maxPartyLevelDifference) { + MMOCore.plugin.configManager.getSimpleMessage("high-level-difference", "player", target.getName()).send(player); + player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1); + open(); + return; + } + party.sendInvite(playerData, targetData); MMOCore.plugin.configManager.getSimpleMessage("sent-party-invite", "player", target.getName()).send(player); player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1); diff --git a/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java index 2ecfc2ec..da56b890 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java @@ -99,7 +99,6 @@ public class ConfigManager { globalSkillCooldown = MMOCore.plugin.getConfig().getLong("global-skill-cooldown") * 50; noSkillBoundPlaceholder = getSimpleMessage("no-skill-placeholder").message(); lootChestsChanceWeight = MMOCore.plugin.getConfig().getDouble("chance-stat-weight.loot-chests"); - attributesAsClassInfo = MMOCore.plugin.getConfig().getBoolean("attributes-as-class-info"); staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN); staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN); diff --git a/src/main/java/net/Indyuce/mmocore/party/provided/Party.java b/src/main/java/net/Indyuce/mmocore/party/provided/Party.java index 659906f1..218a830e 100644 --- a/src/main/java/net/Indyuce/mmocore/party/provided/Party.java +++ b/src/main/java/net/Indyuce/mmocore/party/provided/Party.java @@ -9,6 +9,7 @@ import net.Indyuce.mmocore.gui.social.party.EditablePartyView.PartyViewInventory import net.Indyuce.mmocore.manager.InventoryManager; import net.Indyuce.mmocore.party.AbstractParty; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.*; import java.util.function.Consumer; @@ -25,13 +26,21 @@ public class Party implements AbstractParty { /** * Owner has to change when previous owner leaves party */ + @NotNull private PlayerData owner; + /** + * If the difference between a player level and the party + * level is too high then players cannot join the party. + */ + private final int partyLevel; + private final MMOCorePartyModule module; public Party(MMOCorePartyModule module, PlayerData owner) { this.owner = owner; this.module = module; + this.partyLevel = owner.getLevel(); addMember(owner); } @@ -59,6 +68,10 @@ public class Party implements AbstractParty { return online; } + public int getLevel() { + return partyLevel; + } + @Override public int countMembers() { return members.size(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index aadb32bf..e2fee491 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -143,10 +143,21 @@ party: # to talk in the party chat. chat-prefix: '@' - # The max players that can be in - # any given party. Between 2-8. + # The max amount of players in a party + # Has to be higher than 2 max-players: 8 + # If the difference between a player's level and the + # initial party owner's level is higher that this + # value, then that player can't join the party. + # + # This prevents low level players from joining + # high level players and earning tons of EXP. + # + # Set to the max level possible if you want to disable + # that feature. + max-level-difference: 3 + # Redirects vanilla experience obtained to MMOCore # class experience. You can define the % of the vanilla # experience that is being transfered as MMOCore exp. diff --git a/src/main/resources/default/messages.yml b/src/main/resources/default/messages.yml index b311b6ba..8d1f7fb0 100644 --- a/src/main/resources/default/messages.yml +++ b/src/main/resources/default/messages.yml @@ -118,6 +118,7 @@ party-joined-other: '&6{player}&e joined your party!' transfer-party-ownership: '&eYou were transfered the party ownership.' kick-from-party: '&eYou successfully kicked &6{player}&e.' party-invite-cooldown: '&cPlease wait {cooldown} before inviting {player}.' +high-level-difference: '&cYou cannot invite {player} as the level difference is too high.' # Guilds guild-chat: '&a[{tag}] {player}: {message}' From e1d43c8a05e908a98880244483c25495eadd7254 Mon Sep 17 00:00:00 2001 From: Jules Date: Sat, 18 Jun 2022 19:10:10 +0200 Subject: [PATCH 6/7] Fixed party max lvl diff --- pom.xml | 28 +++++-------------- .../mmocore/manager/ConfigManager.java | 2 ++ 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index 4f0e60df..de0373c3 100644 --- a/pom.xml +++ b/pom.xml @@ -15,20 +15,6 @@ UTF-8 - - - nexus - Lumine Releases - https://mvn.lumine.io/repository/maven-releases/ - - - nexus - Lumine Snapshots - https://mvn.lumine.io/repository/maven-snapshots/ - - - - ${project.name}-${project.version} @@ -81,13 +67,13 @@ - lumine - https://mvn.lumine.io/repository/maven/ + nexus + https://mvn.lumine.io/repository/maven-public/ - placeholderapi - https://repo.extendedclip.com/content/repositories/placeholderapi/ + phoenix + http://la-grange-evasion.pro.dns-orange.fr:8081/repository/maven-public/ @@ -160,8 +146,8 @@ me.clip - placeholderapi - 2.9.2 + PlaceholderAPI + 2.11.1 provided @@ -182,7 +168,7 @@ net.citizensnpcs Citizens - 2.0.25 + 2.0.30-b2571 provided diff --git a/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java index da56b890..bbf3ce55 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java @@ -28,6 +28,7 @@ public class ConfigManager { public ChatColor staminaFull, staminaHalf, staminaEmpty; public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown, globalSkillCooldown; public double lootChestsChanceWeight; + public int maxPartyLevelDifference; private final FileConfiguration messages; private final boolean chatInput; @@ -99,6 +100,7 @@ public class ConfigManager { globalSkillCooldown = MMOCore.plugin.getConfig().getLong("global-skill-cooldown") * 50; noSkillBoundPlaceholder = getSimpleMessage("no-skill-placeholder").message(); lootChestsChanceWeight = MMOCore.plugin.getConfig().getDouble("chance-stat-weight.loot-chests"); + maxPartyLevelDifference = MMOCore.plugin.getConfig().getInt("party.max-level-difference"); staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN); staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN); From 99962112968f0ee1b944bce491034063e4c0167b Mon Sep 17 00:00:00 2001 From: Jules Date: Sat, 18 Jun 2022 20:08:05 +0200 Subject: [PATCH 7/7] Fixed exp hologram display --- src/main/java/net/Indyuce/mmocore/api/PlayerActionBar.java | 2 +- src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java | 3 ++- .../mmocore/command/rpg/admin/ExperienceCommandTreeNode.java | 3 ++- .../Indyuce/mmocore/command/rpg/admin/InfoCommandTreeNode.java | 3 ++- .../net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java | 2 +- .../java/net/Indyuce/mmocore/experience/PlayerProfessions.java | 2 +- src/main/java/net/Indyuce/mmocore/gui/PlayerStats.java | 3 ++- src/main/resources/config.yml | 3 ++- 8 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/api/PlayerActionBar.java b/src/main/java/net/Indyuce/mmocore/api/PlayerActionBar.java index 0dbd8859..79328c22 100644 --- a/src/main/java/net/Indyuce/mmocore/api/PlayerActionBar.java +++ b/src/main/java/net/Indyuce/mmocore/api/PlayerActionBar.java @@ -49,7 +49,7 @@ public class PlayerActionBar extends BukkitRunnable { .replace("{stellium}", digit.format(data.getStellium())) .replace("{max_stellium}", StatInfo.valueOf("MAX_STELLIUM").format(data.getStats().getStat("MAX_STELLIUM"))) .replace("{class}", data.getProfess().getName()) - .replace("{xp}", "" + data.getExperience()) + .replace("{xp}", MythicLib.plugin.getMMOConfig().decimal.format(data.getExperience())) .replace("{armor}", StatInfo.valueOf("ARMOR").format(data.getPlayer().getAttribute(Attribute.GENERIC_ARMOR).getValue())) .replace("{level}", "" + data.getLevel()) .replace("{name}", data.getPlayer().getDisplayName()))))); 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 b8e3922c..b3c3797d 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -1,5 +1,6 @@ package net.Indyuce.mmocore.api.player; +import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.player.MMOPlayerData; import io.lumine.mythic.lib.player.TemporaryPlayerData; import io.lumine.mythic.lib.player.cooldown.CooldownMap; @@ -560,7 +561,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc // Experience hologram if (hologramLocation != null && isOnline()) - MMOCoreUtils.displayIndicator(hologramLocation, MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", String.valueOf(event.getExperience())).message()); + MMOCoreUtils.displayIndicator(hologramLocation, MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", MythicLib.plugin.getMMOConfig().decimal.format(event.getExperience())).message()); experience = Math.max(0, experience + event.getExperience()); diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExperienceCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExperienceCommandTreeNode.java index 5bd2d305..9bf465de 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExperienceCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExperienceCommandTreeNode.java @@ -1,5 +1,6 @@ package net.Indyuce.mmocore.command.rpg.admin; +import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.command.api.CommandTreeNode; import io.lumine.mythic.lib.command.api.Parameter; import net.Indyuce.mmocore.MMOCore; @@ -68,7 +69,7 @@ public class ExperienceCommandTreeNode extends CommandTreeNode { if (args[4].equalsIgnoreCase("main")) { main.accept(data, amount); CommandVerbose.verbose(sender, CommandVerbose.CommandType.EXPERIENCE, ChatColor.GOLD + player.getName() + ChatColor.YELLOW - + " now has " + ChatColor.GOLD + data.getExperience() + ChatColor.YELLOW + " EXP."); + + " now has " + ChatColor.GOLD + MythicLib.plugin.getMMOConfig().decimal.format(data.getExperience()) + ChatColor.YELLOW + " EXP."); return CommandResult.SUCCESS; } diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/InfoCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/InfoCommandTreeNode.java index 4b26626e..fcb7416b 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/InfoCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/InfoCommandTreeNode.java @@ -1,5 +1,6 @@ package net.Indyuce.mmocore.command.rpg.admin; +import io.lumine.mythic.lib.MythicLib; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -33,7 +34,7 @@ public class InfoCommandTreeNode extends CommandTreeNode { sender.sendMessage(ChatColor.YELLOW + "----------------------------------------------------"); sender.sendMessage(ChatColor.YELLOW + "Class: " + ChatColor.GOLD + playerData.getProfess().getName()); sender.sendMessage(ChatColor.YELLOW + "Level: " + ChatColor.GOLD + playerData.getLevel()); - sender.sendMessage(ChatColor.YELLOW + "Experience: " + ChatColor.GOLD + playerData.getExperience() + ChatColor.YELLOW + " / " + ChatColor.GOLD + sender.sendMessage(ChatColor.YELLOW + "Experience: " + ChatColor.GOLD + MythicLib.plugin.getMMOConfig().decimal.format(playerData.getExperience()) + ChatColor.YELLOW + " / " + ChatColor.GOLD + playerData.getLevelUpExperience()); sender.sendMessage(ChatColor.YELLOW + "Class Points: " + ChatColor.GOLD + playerData.getClassPoints()); sender.sendMessage(ChatColor.YELLOW + "Quests: " + ChatColor.GOLD + playerData.getQuestData().getFinishedQuests().size() + ChatColor.YELLOW diff --git a/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java b/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java index 944b25e6..ca6556eb 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java +++ b/src/main/java/net/Indyuce/mmocore/comp/placeholder/RPGPlaceholders.java @@ -128,7 +128,7 @@ public class RPGPlaceholders extends PlaceholderExpansion { .valueOf(playerData.getCollectionSkills().getLevel(identifier.substring(11).replace(" ", "-").replace("_", "-").toLowerCase())); else if (identifier.equals("experience")) - return String.valueOf(playerData.getExperience()); + return MythicLib.plugin.getMMOConfig().decimal.format(playerData.getExperience()); else if (identifier.equals("next_level")) return String.valueOf(playerData.getLevelUpExperience()); diff --git a/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java b/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java index 9b0d11c1..9a364586 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java +++ b/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java @@ -187,7 +187,7 @@ public class PlayerProfessions { // Display hologram if (hologramLocation != null) - MMOCoreUtils.displayIndicator(hologramLocation.add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message()); + MMOCoreUtils.displayIndicator(hologramLocation.add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", MythicLib.plugin.getMMOConfig().decimal.format(event.getExperience())).message()); exp.put(profession.getId(), Math.max(0, exp.getOrDefault(profession.getId(), 0.) + event.getExperience())); int level, oldLevel = getLevel(profession); diff --git a/src/main/java/net/Indyuce/mmocore/gui/PlayerStats.java b/src/main/java/net/Indyuce/mmocore/gui/PlayerStats.java index 63759744..9f306d65 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/PlayerStats.java +++ b/src/main/java/net/Indyuce/mmocore/gui/PlayerStats.java @@ -1,5 +1,6 @@ package net.Indyuce.mmocore.gui; +import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.api.stat.modifier.StatModifier; import io.lumine.mythic.lib.version.VersionMaterial; @@ -243,7 +244,7 @@ public class PlayerStats extends EditableInventory { bar.append(j == chars ? "" + ChatColor.WHITE + ChatColor.BOLD : "").append("|"); holders.register("percent", decimal.format(ratio * 100)); - holders.register("exp", "" + data.getExperience()); + holders.register("exp", MythicLib.plugin.getMMOConfig().decimal.format(data.getExperience())); holders.register("level", "" + data.getLevel()); holders.register("class_points", "" + data.getClassPoints()); holders.register("skill_points", "" + data.getSkillPoints()); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e2fee491..141b310d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -227,7 +227,8 @@ resource-bar-colors: # When set to true, attributes are saved and # reset when a player changes their class. -attributes-as-class-info: true +# Not implemented yet. +# attributes-as-class-info: true # Whether or not the admin commands should display # the result of the command when ran.