From 83ff1c2eeac87251bd9cc7efbe1c99da1beacb29 Mon Sep 17 00:00:00 2001 From: QarthO Date: Sun, 11 Aug 2024 08:44:20 -0400 Subject: [PATCH] [wip] placeholders sorted properly --- .../gg/quartzdev/qxpboosts/boost/Boost.java | 17 ++++++++++++++++- .../qxpboosts/papi/BoostExpansion.java | 2 +- .../gg/quartzdev/qxpboosts/util/BoostUtil.java | 4 ++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/gg/quartzdev/qxpboosts/boost/Boost.java b/src/main/java/gg/quartzdev/qxpboosts/boost/Boost.java index 66064ad..fa80856 100644 --- a/src/main/java/gg/quartzdev/qxpboosts/boost/Boost.java +++ b/src/main/java/gg/quartzdev/qxpboosts/boost/Boost.java @@ -157,10 +157,25 @@ public void disable() return map; } + @Override + public String toString() + { + return "{" + name + ", " + multiplier + "x, " + chance + "%}"; + } @Override public int compareTo(@NotNull Boost boost) { - return Integer.compare(this.sortWeight, boost.sortWeight); + +// Sort by chance + if(this.chance > boost.chance) return 1; + if(this.chance < boost.chance) return -1; + +// If chance is the same, sort by multiplier + if (this.multiplier > boost.multiplier) return 1; + if (this.multiplier < boost.multiplier) return -1; + +// If multiplier is the same, sort by name + return this.name.compareTo(boost.name); } } diff --git a/src/main/java/gg/quartzdev/qxpboosts/papi/BoostExpansion.java b/src/main/java/gg/quartzdev/qxpboosts/papi/BoostExpansion.java index c583e5f..3f19b8a 100644 --- a/src/main/java/gg/quartzdev/qxpboosts/papi/BoostExpansion.java +++ b/src/main/java/gg/quartzdev/qxpboosts/papi/BoostExpansion.java @@ -69,7 +69,7 @@ private int getBoostIndex(String firstParam) { String[] split = firstParam.split(":"); try { - return Integer.parseInt(split[1]); + return Integer.parseInt(split[1])-1; } catch (NumberFormatException | ArrayIndexOutOfBoundsException ignored) { return 0; } diff --git a/src/main/java/gg/quartzdev/qxpboosts/util/BoostUtil.java b/src/main/java/gg/quartzdev/qxpboosts/util/BoostUtil.java index cd0f358..f4e3518 100644 --- a/src/main/java/gg/quartzdev/qxpboosts/util/BoostUtil.java +++ b/src/main/java/gg/quartzdev/qxpboosts/util/BoostUtil.java @@ -3,6 +3,7 @@ import gg.quartzdev.qxpboosts.boost.Boost; import gg.quartzdev.qxpboosts.qPermission; import gg.quartzdev.qxpboosts.qXpBoosts; +import org.bukkit.Bukkit; import org.bukkit.Sound; import org.bukkit.entity.ExperienceOrb; import org.bukkit.entity.Player; @@ -10,6 +11,8 @@ import java.text.DecimalFormat; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -81,6 +84,7 @@ public static List getSortedBoosts(Player player){ if(boost == null) continue; boosts.add(boost); } + boosts.sort(Collections.reverseOrder()); return boosts; } }