From 6fd4dd1403390aac674a4defb08dc90efadad483 Mon Sep 17 00:00:00 2001 From: cj89898 Date: Mon, 19 Jun 2023 20:02:11 -0500 Subject: [PATCH 1/2] Cleaned up PAPI Expansion --- .../nossr50/placeholders/PapiExpansion.java | 217 +++++------------- .../PartyIsLeaderPlaceholder.java | 29 --- .../PartyIsMemberPlaceholder.java | 21 -- .../placeholders/PartyLeaderPlaceholder.java | 22 -- .../placeholders/PartyNamePlaceholder.java | 22 -- .../placeholders/PartySizePlaceholder.java | 22 -- .../nossr50/placeholders/Placeholder.java | 18 -- .../PowerLevelCapPlaceholder.java | 22 -- .../placeholders/PowerLevelPlaceholder.java | 22 -- .../SkillExpNeededPlaceholder.java | 26 --- .../placeholders/SkillExpPlaceholder.java | 26 --- .../SkillExpRemainingPlaceholder.java | 25 -- .../placeholders/SkillLevelPlaceholder.java | 25 -- .../placeholders/SkillRankPlaceholder.java | 25 -- .../placeholders/SkillXpRatePlaceholder.java | 25 -- .../XpEventActivePlaceholder.java | 22 -- .../placeholders/XpRatePlaceholder.java | 22 -- 17 files changed, 54 insertions(+), 537 deletions(-) delete mode 100644 src/main/java/com/gmail/nossr50/placeholders/PartyIsLeaderPlaceholder.java delete mode 100644 src/main/java/com/gmail/nossr50/placeholders/PartyIsMemberPlaceholder.java delete mode 100644 src/main/java/com/gmail/nossr50/placeholders/PartyLeaderPlaceholder.java delete mode 100644 src/main/java/com/gmail/nossr50/placeholders/PartyNamePlaceholder.java delete mode 100644 src/main/java/com/gmail/nossr50/placeholders/PartySizePlaceholder.java delete mode 100644 src/main/java/com/gmail/nossr50/placeholders/Placeholder.java delete mode 100644 src/main/java/com/gmail/nossr50/placeholders/PowerLevelCapPlaceholder.java delete mode 100644 src/main/java/com/gmail/nossr50/placeholders/PowerLevelPlaceholder.java delete mode 100644 src/main/java/com/gmail/nossr50/placeholders/SkillExpNeededPlaceholder.java delete mode 100644 src/main/java/com/gmail/nossr50/placeholders/SkillExpPlaceholder.java delete mode 100644 src/main/java/com/gmail/nossr50/placeholders/SkillExpRemainingPlaceholder.java delete mode 100644 src/main/java/com/gmail/nossr50/placeholders/SkillLevelPlaceholder.java delete mode 100644 src/main/java/com/gmail/nossr50/placeholders/SkillRankPlaceholder.java delete mode 100644 src/main/java/com/gmail/nossr50/placeholders/SkillXpRatePlaceholder.java delete mode 100644 src/main/java/com/gmail/nossr50/placeholders/XpEventActivePlaceholder.java delete mode 100644 src/main/java/com/gmail/nossr50/placeholders/XpRatePlaceholder.java diff --git a/src/main/java/com/gmail/nossr50/placeholders/PapiExpansion.java b/src/main/java/com/gmail/nossr50/placeholders/PapiExpansion.java index ff7a90ceac..8db131b393 100644 --- a/src/main/java/com/gmail/nossr50/placeholders/PapiExpansion.java +++ b/src/main/java/com/gmail/nossr50/placeholders/PapiExpansion.java @@ -15,14 +15,10 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Map; -import java.util.TreeMap; public class PapiExpansion extends PlaceholderExpansion { - private final Map placeholders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); public PapiExpansion() { - init(); } @Override @@ -37,8 +33,7 @@ public String getAuthor() { @Override public String getVersion() { - //grab version from pom.xml - return "1.0,0"; + return mcMMO.p.getDescription().getVersion(); } @Override @@ -49,105 +44,41 @@ public String getRequiredPlugin() { @Override @Nullable public String onPlaceholderRequest(final Player player, @NotNull final String params) { - String token; - String data = null; - int dataPosition = params.indexOf(":"); - - if (dataPosition != -1) { - token = params.substring(0, dataPosition); - data = params.substring(dataPosition + 1); - } else { - token = params; - } - - Placeholder placeholder = placeholders.get(token); - - if (placeholder != null) { - return placeholder.process(player, data); - } else { - return null; - } - } - - public Integer getSkillLevel(PrimarySkillType skill, Player player) { - final McMMOPlayer user = UserManager.getPlayer(player); - if (user == null) return null; - return user.getSkillLevel(skill); - } - - public Integer getExpNeeded(PrimarySkillType skill, Player player) { - final McMMOPlayer user = UserManager.getPlayer(player); - if (user == null) return null; - return user.getXpToLevel(skill); - } - - public Integer getExp(PrimarySkillType skill, Player player) { - final McMMOPlayer user = UserManager.getPlayer(player); - if (user == null) return null; - - return user.getSkillXpLevel(skill); - } - - - public Integer getExpRemaining(PrimarySkillType skill, Player player) { - final McMMOPlayer user = UserManager.getPlayer(player); - if (user == null) return null; - int current = user.getSkillXpLevel(skill); - int needed = user.getXpToLevel(skill); - - return needed - current; - } - - public Integer getRank(PrimarySkillType skill, Player player) { + + // Non player-specific placeholders + if (params.equalsIgnoreCase("is_xp_event_active")) { + return mcMMO.p.isXPEventEnabled() ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); + }else if (params.equalsIgnoreCase("xprate")) { + return String.valueOf(ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()); + }else if (params.equalsIgnoreCase("power_level_cap")) { + return mcMMO.p.getGeneralConfig().getPowerLevelCap()+""; + } + + final McMMOPlayer user = UserManager.getPlayer(player); + if (user == null) return null; + + if (params.startsWith("level_")) { + PrimarySkillType skill = PrimarySkillType.valueOf(params.substring(6).toUpperCase()); + return skill == null ? null : user.getSkillLevel(skill)+""; + }else if (params.startsWith("xp_needed_")) { + PrimarySkillType skill = PrimarySkillType.valueOf(params.substring(10).toUpperCase()); + return skill == null ? null : user.getXpToLevel(skill)+""; + }else if (params.startsWith("xp_remaining_")) { + PrimarySkillType skill = PrimarySkillType.valueOf(params.substring(13).toUpperCase()); + return skill == null ? null : (user.getXpToLevel(skill) - user.getSkillXpLevel(skill))+""; + }else if (params.startsWith("xp_")) { + PrimarySkillType skill = PrimarySkillType.valueOf(params.substring(3).toUpperCase()); + return skill == null ? null : user.getSkillXpLevel(skill)+""; + }else if (params.startsWith("rank_")) { try { - return ExperienceAPI.getPlayerRankSkill(player.getUniqueId(), StringUtils.getCapitalized(skill.toString())); + return ExperienceAPI.getPlayerRankSkill(player.getUniqueId(), StringUtils.getCapitalized(params.substring(5)))+""; } catch (Exception ex) { - return null; + return null; } - } - - public Integer getPowerLevel(Player player) { - final McMMOPlayer user = UserManager.getPlayer(player); - if (user == null) return null; - return user.getPowerLevel(); - } - - public Integer getPowerCap(Player player) { - return mcMMO.p.getGeneralConfig().getPowerLevelCap(); - } - - public String getPartyName(Player player) { - final McMMOPlayer user = UserManager.getPlayer(player); - if (user == null) return null; - final Party party = user.getParty(); - - return (party == null) ? null : party.getName(); - } - - public String getPartyLeader(Player player) { - final McMMOPlayer user = UserManager.getPlayer(player); - if (user == null) return null; - final Party party = user.getParty(); - return (party == null) ? null : party.getLeader().getPlayerName(); - } - - public Integer getPartySize(Player player) { - final McMMOPlayer user = UserManager.getPlayer(player); - if (user == null) return null; - final Party party = user.getParty(); - return (party == null) ? null : party.getMembers().size(); - } - - public String getXpRate(Player player) { - return String.valueOf(ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()); - } - - public String getSkillXpRate(PrimarySkillType skill, Player player) { - final McMMOPlayer user = UserManager.getPlayer(player); - if (user == null) return null; - + }else if (params.startsWith("xprate_")) { + PrimarySkillType skill = PrimarySkillType.valueOf(params.substring(7).toUpperCase()); + if (skill == null) return null; double modifier = 1.0F; - if (Permissions.customXpBoost(player, skill)) modifier = ExperienceConfig.getInstance().getCustomXpPerkBoost(); else if (Permissions.quadrupleXp(player, skill)) @@ -162,69 +93,29 @@ else if (Permissions.oneAndOneHalfXp(player, skill)) modifier = 1.5; else if (Permissions.oneAndOneTenthXp(player, skill)) modifier = 1.1; - return String.valueOf(modifier); + }else if (params.equalsIgnoreCase("power_level")) { + return user.getPowerLevel()+""; + } + + + //Party placeholders + final Party party = user.getParty(); + + if (params.equalsIgnoreCase("in_party")) { + return (party==null) ? PlaceholderAPIPlugin.booleanFalse() : PlaceholderAPIPlugin.booleanTrue(); + }else if (params.equalsIgnoreCase("party_name")) { + return (party == null) ? "" : party.getName(); + }else if (params.equalsIgnoreCase("is_party_leader")) { + if (party == null) return ""; + return party.getLeader().getPlayerName().equals(player.getName()) ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); + }else if (params.equalsIgnoreCase("party_leader")) { + return (party == null) ? "" : party.getLeader().getPlayerName(); + }else if (params.equalsIgnoreCase("party_size")) { + return (party == null) ? "" : party.getMembers().size()+""; + } + + return null; } - public String isExpEventActive(Player player) { - return mcMMO.p.isXPEventEnabled() ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); - } - - public void registerPlaceholder(Placeholder placeholder) { - final Placeholder registered = placeholders.get(placeholder.getName()); - if (registered != null) - throw new IllegalStateException("Placeholder " + placeholder.getName() + " is already registered!"); - - placeholders.put(placeholder.getName(), placeholder); - } - - protected void init() { - - for (PrimarySkillType skill : PrimarySkillType.values()) { - // %mcmmo_level_% - registerPlaceholder(new SkillLevelPlaceholder(this, skill)); - - //%mcmmo_xp_needed_% - registerPlaceholder(new SkillExpNeededPlaceholder(this, skill)); - - //%mcmmo_xp_% - registerPlaceholder(new SkillExpPlaceholder(this, skill)); - - //%mcmmo_xp_remaining_% - registerPlaceholder(new SkillExpRemainingPlaceholder(this, skill)); - - //%mcmmo_rank_% - registerPlaceholder(new SkillRankPlaceholder(this, skill)); - - //%mcmmo_xprate_% - registerPlaceholder(new SkillXpRatePlaceholder(this, skill)); - } - - - //%mcmmo_power_level% - registerPlaceholder(new PowerLevelPlaceholder(this)); - - // %mcmmo_power_level_cap% - registerPlaceholder(new PowerLevelCapPlaceholder(this)); - - // %mcmmo_in_party% - registerPlaceholder(new PartyIsMemberPlaceholder(this)); - - /// %mcmmo_party_name% - registerPlaceholder(new PartyNamePlaceholder(this)); - - // %mcmmo_is_party_leader% - registerPlaceholder(new PartyIsLeaderPlaceholder(this)); - - // %mcmmo_party_leader% - registerPlaceholder(new PartyLeaderPlaceholder(this)); - - // %mcmmo_party_size% - registerPlaceholder(new PartySizePlaceholder(this)); - - // %mcmmo_is_xp_event_active% - registerPlaceholder(new XpEventActivePlaceholder(this)); - // %mcmmo_xprate% - registerPlaceholder(new XpRatePlaceholder(this)); - }; } diff --git a/src/main/java/com/gmail/nossr50/placeholders/PartyIsLeaderPlaceholder.java b/src/main/java/com/gmail/nossr50/placeholders/PartyIsLeaderPlaceholder.java deleted file mode 100644 index f10248f20f..0000000000 --- a/src/main/java/com/gmail/nossr50/placeholders/PartyIsLeaderPlaceholder.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.gmail.nossr50.placeholders; - -import org.bukkit.entity.Player; - -public class PartyIsLeaderPlaceholder implements Placeholder { - - private final PapiExpansion papiExpansion; - - public PartyIsLeaderPlaceholder(PapiExpansion papiExpansion) { - this.papiExpansion = papiExpansion; - } - - /** - * {@inheritDoc} - */ - @Override - public String process(Player player, String params) { - String leader = papiExpansion.getPartyLeader(player); - return (leader.equals(player.getName())) ? "true" : "false"; - } - - /** - * {@inheritDoc} - */ - @Override - public String getName() { - return "is_party_leader"; - } -} diff --git a/src/main/java/com/gmail/nossr50/placeholders/PartyIsMemberPlaceholder.java b/src/main/java/com/gmail/nossr50/placeholders/PartyIsMemberPlaceholder.java deleted file mode 100644 index ac385a4ba4..0000000000 --- a/src/main/java/com/gmail/nossr50/placeholders/PartyIsMemberPlaceholder.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.gmail.nossr50.placeholders; - -import org.bukkit.entity.Player; - -public class PartyIsMemberPlaceholder implements Placeholder { - - private final PapiExpansion papiExpansion; - public PartyIsMemberPlaceholder(PapiExpansion papiExpansion) { - this.papiExpansion = papiExpansion; - } - - @Override - public String process(Player player, String params) { - return (papiExpansion.getPartyName(player) == null) ? "false" : "true"; - } - - @Override - public String getName() { - return "in_party"; - } -} diff --git a/src/main/java/com/gmail/nossr50/placeholders/PartyLeaderPlaceholder.java b/src/main/java/com/gmail/nossr50/placeholders/PartyLeaderPlaceholder.java deleted file mode 100644 index 3f753bed9f..0000000000 --- a/src/main/java/com/gmail/nossr50/placeholders/PartyLeaderPlaceholder.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.gmail.nossr50.placeholders; - -import org.apache.commons.lang.StringUtils; -import org.bukkit.entity.Player; - -public class PartyLeaderPlaceholder implements Placeholder { - private final PapiExpansion papiExpansion; - - public PartyLeaderPlaceholder(PapiExpansion papiExpansion) { - this.papiExpansion = papiExpansion; - } - - @Override - public String process(Player player, String params) { - return StringUtils.stripToEmpty(papiExpansion.getPartyLeader(player)); - } - - @Override - public String getName() { - return "party_leader"; - } -} diff --git a/src/main/java/com/gmail/nossr50/placeholders/PartyNamePlaceholder.java b/src/main/java/com/gmail/nossr50/placeholders/PartyNamePlaceholder.java deleted file mode 100644 index 2cec030d67..0000000000 --- a/src/main/java/com/gmail/nossr50/placeholders/PartyNamePlaceholder.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.gmail.nossr50.placeholders; - -import org.apache.commons.lang.StringUtils; -import org.bukkit.entity.Player; - -public class PartyNamePlaceholder implements Placeholder { - private final PapiExpansion papiExpansion; - - public PartyNamePlaceholder(PapiExpansion papiExpansion) { - this.papiExpansion = papiExpansion; - } - - @Override - public String process(Player player, String params) { - return StringUtils.stripToEmpty(papiExpansion.getPartyName(player)); - } - - @Override - public String getName() { - return "party_name"; - } -} diff --git a/src/main/java/com/gmail/nossr50/placeholders/PartySizePlaceholder.java b/src/main/java/com/gmail/nossr50/placeholders/PartySizePlaceholder.java deleted file mode 100644 index 0d60d2786d..0000000000 --- a/src/main/java/com/gmail/nossr50/placeholders/PartySizePlaceholder.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.gmail.nossr50.placeholders; - -import org.bukkit.entity.Player; - -public class PartySizePlaceholder implements Placeholder { - private final PapiExpansion papiExpansion; - - public PartySizePlaceholder(PapiExpansion papiExpansion) { - this.papiExpansion = papiExpansion; - } - - @Override - public String process(Player player, String params) { - Integer partySize = papiExpansion.getPartySize(player); - return (partySize == null) ? "" : partySize.toString(); - } - - @Override - public String getName() { - return "party_size"; - } -} diff --git a/src/main/java/com/gmail/nossr50/placeholders/Placeholder.java b/src/main/java/com/gmail/nossr50/placeholders/Placeholder.java deleted file mode 100644 index 0df6973258..0000000000 --- a/src/main/java/com/gmail/nossr50/placeholders/Placeholder.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.gmail.nossr50.placeholders; - -import org.bukkit.entity.Player; - -public interface Placeholder { - - /** - * @param player the player to process the placeholder for - * @param params the paramaters to be passed to the placeholder - * @return the value of the placeholder - */ - String process(Player player, String params); - - /** - * @return the name of the placeholder - */ - String getName(); -} diff --git a/src/main/java/com/gmail/nossr50/placeholders/PowerLevelCapPlaceholder.java b/src/main/java/com/gmail/nossr50/placeholders/PowerLevelCapPlaceholder.java deleted file mode 100644 index ac4192a005..0000000000 --- a/src/main/java/com/gmail/nossr50/placeholders/PowerLevelCapPlaceholder.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.gmail.nossr50.placeholders; - -import org.bukkit.entity.Player; - -public class PowerLevelCapPlaceholder implements Placeholder { - private final PapiExpansion papiExpansion; - - public PowerLevelCapPlaceholder(PapiExpansion papiExpansion) { - this.papiExpansion = papiExpansion; - } - - @Override - public String process(Player player, String params) { - Integer cap = papiExpansion.getPowerCap(player); - return (cap == null) ? "" : cap.toString(); - } - - @Override - public String getName() { - return "power_level_cap"; - } -} diff --git a/src/main/java/com/gmail/nossr50/placeholders/PowerLevelPlaceholder.java b/src/main/java/com/gmail/nossr50/placeholders/PowerLevelPlaceholder.java deleted file mode 100644 index 1b2916c23c..0000000000 --- a/src/main/java/com/gmail/nossr50/placeholders/PowerLevelPlaceholder.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.gmail.nossr50.placeholders; - -import org.bukkit.entity.Player; - -public class PowerLevelPlaceholder implements Placeholder { - private final PapiExpansion papiExpansion; - - public PowerLevelPlaceholder(PapiExpansion papiExpansion) { - this.papiExpansion = papiExpansion; - } - - @Override - public String process(Player player, String params) { - Integer powerLevel = papiExpansion.getPowerLevel(player); - return (powerLevel == null) ? "" : powerLevel.toString(); - } - - @Override - public String getName() { - return "power_level"; - } -} diff --git a/src/main/java/com/gmail/nossr50/placeholders/SkillExpNeededPlaceholder.java b/src/main/java/com/gmail/nossr50/placeholders/SkillExpNeededPlaceholder.java deleted file mode 100644 index 93cc967e9c..0000000000 --- a/src/main/java/com/gmail/nossr50/placeholders/SkillExpNeededPlaceholder.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.gmail.nossr50.placeholders; - -import com.gmail.nossr50.datatypes.skills.PrimarySkillType; -import org.bukkit.entity.Player; - -public class SkillExpNeededPlaceholder implements Placeholder { - - private final PapiExpansion papiExpansion; - private final PrimarySkillType skillType; - - public SkillExpNeededPlaceholder(PapiExpansion papiExpansion, PrimarySkillType skillType) { - this.papiExpansion = papiExpansion; - this.skillType = skillType; - } - - @Override - public String process(Player player, String params) { - final Integer expNeeded = papiExpansion.getExpNeeded(skillType, player); - return (expNeeded == null) ? "" : expNeeded.toString(); - } - - @Override - public String getName() { - return "xp_needed_" + skillType.toString().toLowerCase(); - } -} diff --git a/src/main/java/com/gmail/nossr50/placeholders/SkillExpPlaceholder.java b/src/main/java/com/gmail/nossr50/placeholders/SkillExpPlaceholder.java deleted file mode 100644 index a6f9fd2bd2..0000000000 --- a/src/main/java/com/gmail/nossr50/placeholders/SkillExpPlaceholder.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.gmail.nossr50.placeholders; - -import com.gmail.nossr50.datatypes.skills.PrimarySkillType; -import org.bukkit.entity.Player; - -public class SkillExpPlaceholder implements Placeholder { - private final PapiExpansion papiExpansion; - private final PrimarySkillType skill; - - public SkillExpPlaceholder(PapiExpansion papiExpansion, PrimarySkillType skill) { - this.papiExpansion = papiExpansion; - this.skill = skill; - } - - - @Override - public String process(Player player, String params) { - Integer exp = papiExpansion.getExp(skill, player); - return (exp == null) ? "" : exp.toString(); - } - - @Override - public String getName() { - return "xp_" + skill.toString().toLowerCase(); - } -} diff --git a/src/main/java/com/gmail/nossr50/placeholders/SkillExpRemainingPlaceholder.java b/src/main/java/com/gmail/nossr50/placeholders/SkillExpRemainingPlaceholder.java deleted file mode 100644 index 6f8c617157..0000000000 --- a/src/main/java/com/gmail/nossr50/placeholders/SkillExpRemainingPlaceholder.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.gmail.nossr50.placeholders; - -import com.gmail.nossr50.datatypes.skills.PrimarySkillType; -import org.bukkit.entity.Player; - -public class SkillExpRemainingPlaceholder implements Placeholder { - private final PapiExpansion papiExpansion; - private final PrimarySkillType skill; - - public SkillExpRemainingPlaceholder(PapiExpansion papiExpansion, PrimarySkillType skill) { - this.papiExpansion = papiExpansion; - this.skill = skill; - } - - @Override - public String process(Player player, String params) { - final Integer expRemaining = papiExpansion.getExpRemaining(skill, player); - return (expRemaining == null) ? "" : expRemaining.toString(); - } - - @Override - public String getName() { - return "xp_remaining_" + skill.toString().toLowerCase(); - } -} diff --git a/src/main/java/com/gmail/nossr50/placeholders/SkillLevelPlaceholder.java b/src/main/java/com/gmail/nossr50/placeholders/SkillLevelPlaceholder.java deleted file mode 100644 index 3521a59695..0000000000 --- a/src/main/java/com/gmail/nossr50/placeholders/SkillLevelPlaceholder.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.gmail.nossr50.placeholders; - -import com.gmail.nossr50.datatypes.skills.PrimarySkillType; -import org.bukkit.entity.Player; - -public class SkillLevelPlaceholder implements Placeholder { - private final PapiExpansion papiExpansion; - private final PrimarySkillType skillType; - - public SkillLevelPlaceholder(PapiExpansion papiExpansion, PrimarySkillType skillType) { - this.papiExpansion = papiExpansion; - this.skillType = skillType; - } - - @Override - public String process(Player p, String params) { - final Integer skillLevel = papiExpansion.getSkillLevel(skillType, p); - return (skillLevel == null) ? "" : skillLevel.toString(); - } - - @Override - public String getName() { - return "level_" + skillType.toString().toLowerCase(); - } -} diff --git a/src/main/java/com/gmail/nossr50/placeholders/SkillRankPlaceholder.java b/src/main/java/com/gmail/nossr50/placeholders/SkillRankPlaceholder.java deleted file mode 100644 index 1deca8e8ac..0000000000 --- a/src/main/java/com/gmail/nossr50/placeholders/SkillRankPlaceholder.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.gmail.nossr50.placeholders; - -import com.gmail.nossr50.datatypes.skills.PrimarySkillType; -import org.bukkit.entity.Player; - -public class SkillRankPlaceholder implements Placeholder { - private final PapiExpansion papiExpansion; - private final PrimarySkillType skill; - - public SkillRankPlaceholder(PapiExpansion papiExpansion, PrimarySkillType skill) { - this.papiExpansion = papiExpansion; - this.skill = skill; - } - - @Override - public String process(Player player, String params) { - Integer rank = papiExpansion.getRank(skill, player); - return (rank == null) ? "" : rank.toString(); - } - - @Override - public String getName() { - return "rank_" + skill.toString().toLowerCase(); - } -} diff --git a/src/main/java/com/gmail/nossr50/placeholders/SkillXpRatePlaceholder.java b/src/main/java/com/gmail/nossr50/placeholders/SkillXpRatePlaceholder.java deleted file mode 100644 index 85fe7f461d..0000000000 --- a/src/main/java/com/gmail/nossr50/placeholders/SkillXpRatePlaceholder.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.gmail.nossr50.placeholders; - -import com.gmail.nossr50.datatypes.skills.PrimarySkillType; -import org.bukkit.entity.Player; - -public class SkillXpRatePlaceholder implements Placeholder { - private final PapiExpansion papiExpansion; - private final PrimarySkillType skillType; - - public SkillXpRatePlaceholder(PapiExpansion papiExpansion, PrimarySkillType skillType) { - this.papiExpansion = papiExpansion; - this.skillType = skillType; - } - - @Override - public String process(Player p, String params) { - final String skillLevel = papiExpansion.getSkillXpRate(skillType, p); - return (skillLevel == null) ? "" : skillLevel; - } - - @Override - public String getName() { - return "xprate_" + skillType.toString().toLowerCase(); - } -} diff --git a/src/main/java/com/gmail/nossr50/placeholders/XpEventActivePlaceholder.java b/src/main/java/com/gmail/nossr50/placeholders/XpEventActivePlaceholder.java deleted file mode 100644 index e55c47ed63..0000000000 --- a/src/main/java/com/gmail/nossr50/placeholders/XpEventActivePlaceholder.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.gmail.nossr50.placeholders; - -import com.gmail.nossr50.datatypes.skills.PrimarySkillType; -import org.bukkit.entity.Player; - -public class XpEventActivePlaceholder implements Placeholder { - private final PapiExpansion papiExpansion; - - public XpEventActivePlaceholder(PapiExpansion papiExpansion) { - this.papiExpansion = papiExpansion; - } - - @Override - public String process(Player player, String params) { - return papiExpansion.isExpEventActive(player); - } - - @Override - public String getName() { - return "is_xp_event_active"; - } -} diff --git a/src/main/java/com/gmail/nossr50/placeholders/XpRatePlaceholder.java b/src/main/java/com/gmail/nossr50/placeholders/XpRatePlaceholder.java deleted file mode 100644 index 907c3865e6..0000000000 --- a/src/main/java/com/gmail/nossr50/placeholders/XpRatePlaceholder.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.gmail.nossr50.placeholders; - -import com.gmail.nossr50.datatypes.skills.PrimarySkillType; -import org.bukkit.entity.Player; - -public class XpRatePlaceholder implements Placeholder { - private final PapiExpansion papiExpansion; - - public XpRatePlaceholder(PapiExpansion papiExpansion) { - this.papiExpansion = papiExpansion; - } - - @Override - public String process(Player player, String params) { - return papiExpansion.getXpRate(player); - } - - @Override - public String getName() { - return "xprate"; - } -} From 618dfa94fc97dee5c716dbaba83696ae3478bd20 Mon Sep 17 00:00:00 2001 From: cj89898 Date: Wed, 21 Jun 2023 16:43:54 -0500 Subject: [PATCH 2/2] Cleaned up formatting --- .../nossr50/placeholders/PapiExpansion.java | 72 +++++++++++-------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/placeholders/PapiExpansion.java b/src/main/java/com/gmail/nossr50/placeholders/PapiExpansion.java index 8db131b393..c89b9a6ab4 100644 --- a/src/main/java/com/gmail/nossr50/placeholders/PapiExpansion.java +++ b/src/main/java/com/gmail/nossr50/placeholders/PapiExpansion.java @@ -17,6 +17,22 @@ public class PapiExpansion extends PlaceholderExpansion { + + public static final String SKILL_LEVEL = "level_"; + public static final String SKILL_EXP_NEEDED = "xp_needed_"; + public static final String SKILL_EXP_REMAINING = "xp_remaining_"; + public static final String SKILL_EXP = "xp_"; + public static final String SKILL_RANK = "rank_"; + public static final String SKILL_EXP_RATE = "xprate_"; + public static final String POWER_LEVEL = "power_level"; + public static final String POWER_LEVEL_CAP = "power_level_cap"; + public static final String IN_PARTY = "in_party"; + public static final String PARTY_NAME = "party_name"; + public static final String IS_PARTY_LEADER = "is_party_leader"; + public static final String PARTY_LEADER = "party_leader"; + public static final String PARTY_SIZE = "party_size"; + public static final String EXP_RATE = "xprate"; + public static final String IS_EXP_EVENT_ACTIVE = "is_xp_event_active"; public PapiExpansion() { } @@ -46,37 +62,37 @@ public String getRequiredPlugin() { public String onPlaceholderRequest(final Player player, @NotNull final String params) { // Non player-specific placeholders - if (params.equalsIgnoreCase("is_xp_event_active")) { + if (params.equalsIgnoreCase(IS_EXP_EVENT_ACTIVE)) { return mcMMO.p.isXPEventEnabled() ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); - }else if (params.equalsIgnoreCase("xprate")) { + } else if (params.equalsIgnoreCase(EXP_RATE)) { return String.valueOf(ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()); - }else if (params.equalsIgnoreCase("power_level_cap")) { - return mcMMO.p.getGeneralConfig().getPowerLevelCap()+""; + } else if (params.equalsIgnoreCase(POWER_LEVEL_CAP)) { + return String.valueOf(mcMMO.p.getGeneralConfig().getPowerLevelCap()); } final McMMOPlayer user = UserManager.getPlayer(player); if (user == null) return null; - if (params.startsWith("level_")) { - PrimarySkillType skill = PrimarySkillType.valueOf(params.substring(6).toUpperCase()); - return skill == null ? null : user.getSkillLevel(skill)+""; - }else if (params.startsWith("xp_needed_")) { - PrimarySkillType skill = PrimarySkillType.valueOf(params.substring(10).toUpperCase()); - return skill == null ? null : user.getXpToLevel(skill)+""; - }else if (params.startsWith("xp_remaining_")) { - PrimarySkillType skill = PrimarySkillType.valueOf(params.substring(13).toUpperCase()); - return skill == null ? null : (user.getXpToLevel(skill) - user.getSkillXpLevel(skill))+""; - }else if (params.startsWith("xp_")) { - PrimarySkillType skill = PrimarySkillType.valueOf(params.substring(3).toUpperCase()); - return skill == null ? null : user.getSkillXpLevel(skill)+""; - }else if (params.startsWith("rank_")) { + if (params.startsWith(SKILL_LEVEL)) { + PrimarySkillType skill = PrimarySkillType.valueOf(params.substring(SKILL_LEVEL.length()).toUpperCase()); + return skill == null ? null : String.valueOf(user.getSkillLevel(skill)); + } else if (params.startsWith(SKILL_EXP_NEEDED)) { + PrimarySkillType skill = PrimarySkillType.valueOf(params.substring(SKILL_EXP_NEEDED.length()).toUpperCase()); + return skill == null ? null : String.valueOf(user.getXpToLevel(skill)); + } else if (params.startsWith(SKILL_EXP_REMAINING)) { + PrimarySkillType skill = PrimarySkillType.valueOf(params.substring(SKILL_EXP_REMAINING.length()).toUpperCase()); + return skill == null ? null : String.valueOf(user.getXpToLevel(skill) - user.getSkillXpLevel(skill)); + } else if (params.startsWith(SKILL_EXP)) { + PrimarySkillType skill = PrimarySkillType.valueOf(params.substring(SKILL_EXP.length()).toUpperCase()); + return skill == null ? null : String.valueOf(user.getSkillXpLevel(skill)); + } else if (params.startsWith(SKILL_RANK)) { try { - return ExperienceAPI.getPlayerRankSkill(player.getUniqueId(), StringUtils.getCapitalized(params.substring(5)))+""; + return String.valueOf(ExperienceAPI.getPlayerRankSkill(player.getUniqueId(), StringUtils.getCapitalized(params.substring(SKILL_RANK.length())))); } catch (Exception ex) { return null; } - }else if (params.startsWith("xprate_")) { - PrimarySkillType skill = PrimarySkillType.valueOf(params.substring(7).toUpperCase()); + } else if (params.startsWith(SKILL_EXP_RATE)) { + PrimarySkillType skill = PrimarySkillType.valueOf(params.substring(SKILL_EXP_RATE.length()).toUpperCase()); if (skill == null) return null; double modifier = 1.0F; if (Permissions.customXpBoost(player, skill)) @@ -94,25 +110,25 @@ else if (Permissions.oneAndOneHalfXp(player, skill)) else if (Permissions.oneAndOneTenthXp(player, skill)) modifier = 1.1; return String.valueOf(modifier); - }else if (params.equalsIgnoreCase("power_level")) { - return user.getPowerLevel()+""; + } else if (params.equalsIgnoreCase(POWER_LEVEL)) { + return String.valueOf(user.getPowerLevel()); } //Party placeholders final Party party = user.getParty(); - if (params.equalsIgnoreCase("in_party")) { + if (params.equalsIgnoreCase(IN_PARTY)) { return (party==null) ? PlaceholderAPIPlugin.booleanFalse() : PlaceholderAPIPlugin.booleanTrue(); - }else if (params.equalsIgnoreCase("party_name")) { + } else if (params.equalsIgnoreCase(PARTY_NAME)) { return (party == null) ? "" : party.getName(); - }else if (params.equalsIgnoreCase("is_party_leader")) { + } else if (params.equalsIgnoreCase(IS_PARTY_LEADER)) { if (party == null) return ""; return party.getLeader().getPlayerName().equals(player.getName()) ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); - }else if (params.equalsIgnoreCase("party_leader")) { + } else if (params.equalsIgnoreCase(PARTY_LEADER)) { return (party == null) ? "" : party.getLeader().getPlayerName(); - }else if (params.equalsIgnoreCase("party_size")) { - return (party == null) ? "" : party.getMembers().size()+""; + } else if (params.equalsIgnoreCase(PARTY_SIZE)) { + return (party == null) ? "" : String.valueOf(party.getMembers().size()); } return null;