Skip to content

Commit

Permalink
[wip] placeholders sorted properly
Browse files Browse the repository at this point in the history
  • Loading branch information
QarthO committed Aug 11, 2024
1 parent 26f8e5e commit 83ff1c2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/main/java/gg/quartzdev/qxpboosts/boost/Boost.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/gg/quartzdev/qxpboosts/util/BoostUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
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;
import org.bukkit.permissions.PermissionAttachmentInfo;

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;
Expand Down Expand Up @@ -81,6 +84,7 @@ public static List<Boost> getSortedBoosts(Player player){
if(boost == null) continue;
boosts.add(boost);
}
boosts.sort(Collections.reverseOrder());
return boosts;
}
}

0 comments on commit 83ff1c2

Please sign in to comment.