Skip to content

Commit

Permalink
[Sorting] Remove runtime warn spam when configured sorting placeholde…
Browse files Browse the repository at this point in the history
…r is invalid (only keep startup warn)
  • Loading branch information
NEZNAMY committed Dec 12, 2024
1 parent 6a9cca3 commit 9fe1560
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package me.neznamy.tab.shared.features.sorting.types;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import me.neznamy.tab.shared.platform.TabPlayer;
import me.neznamy.tab.shared.TAB;
import me.neznamy.tab.shared.TabConstants;
import me.neznamy.tab.shared.features.sorting.Sorting;
import me.neznamy.tab.shared.platform.TabPlayer;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

/**
* Sorting by permission nodes
*/
Expand All @@ -27,7 +27,7 @@ public class Permissions extends SortingType {
* Permission nodes separated with ","
*/
public Permissions(Sorting sorting, String options) {
super(sorting, "PERMISSIONS");
super(sorting, "PERMISSIONS", true);
sortedGroups = convertSortingElements(options.split(","));
List<String> placeholders = new ArrayList<>();
for (String permission : sortedGroups.keySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ private static String getPlaceholder(String options) {

@Override
public String getChars(@NotNull TabPlayer p) {
if (!valid) return "";
String output = EnumChatFormat.color(setPlaceholders(p));
p.sortingData.teamNameNote += "\n-> " + sortingPlaceholder + " returned \"&e" + output + "&r\"";
int position;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public PlaceholderHighToLow(Sorting sorting, String sortingPlaceholder) {

@Override
public String getChars(@NotNull TabPlayer p) {
if (!valid) return "";
String output = setPlaceholders(p);
p.sortingData.teamNameNote += "\n-> " + sortingPlaceholder + " returned \"&e" + output + "&r\". &r";
return compressNumber(DEFAULT_NUMBER - parseDouble(sortingPlaceholder, output, 0, p));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public PlaceholderLowToHigh(Sorting sorting, String sortingPlaceholder) {

@Override
public String getChars(@NotNull TabPlayer p) {
if (!valid) return "";
String output = setPlaceholders(p);
p.sortingData.teamNameNote += "\n-> " + sortingPlaceholder + " returned \"&e" + output + "&r\". &r";
return compressNumber(DEFAULT_NUMBER + parseDouble(sortingPlaceholder, output, 0, p));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package me.neznamy.tab.shared.features.sorting.types;

import java.util.LinkedHashMap;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import me.neznamy.tab.shared.TAB;
import me.neznamy.tab.shared.chat.EnumChatFormat;
import me.neznamy.tab.shared.features.sorting.Sorting;
import me.neznamy.tab.shared.placeholders.types.TabPlaceholder;
import me.neznamy.tab.shared.platform.TabPlayer;
import me.neznamy.tab.shared.TAB;
import me.neznamy.tab.shared.features.sorting.Sorting;
import org.jetbrains.annotations.NotNull;

import java.util.LinkedHashMap;

/**
* Abstract class for sorting types.
*/
Expand All @@ -30,6 +30,9 @@ public abstract class SortingType {
/** Placeholder to sort by, if sorting type uses it */
protected String sortingPlaceholder;

/** Flag tracking if this sorting type is valid or not. If not, it is disabled. */
protected final boolean valid;

/**
* Constructs new instance with given parameter
*
Expand All @@ -41,9 +44,11 @@ protected SortingType(Sorting sorting, String displayName, String sortingPlaceho
this.displayName = displayName;
if (!sortingPlaceholder.startsWith("%") || !sortingPlaceholder.endsWith("%")) {
TAB.getInstance().getConfigHelper().startup().invalidSortingPlaceholder(sortingPlaceholder, this);
valid = false;
} else {
sorting.addUsedPlaceholder(sortingPlaceholder);
this.sortingPlaceholder = sortingPlaceholder;
valid = true;
}
}

Expand Down

0 comments on commit 9fe1560

Please sign in to comment.