Minor reformatting / improvements
This commit is contained in:
1 parent
575c058a86
commit
acb0766316
4 files changed
+33
-37
No files matched your search
@@ -249,9 +249,7 @@ public class Kits {
|
||||
}
|
||||
|
||||
public Kit getKitByName(String kitName) {
|
||||
|
||||
return loadKitFromCacheOrCreate(kitName);
|
||||
|
||||
}
|
||||
|
||||
private String trimName(String kitNameWithFileEnding) {
|
||||
@@ -272,14 +270,12 @@ public class Kits {
|
||||
}
|
||||
|
||||
public Kit getKitOfPlayer(String playerName) {
|
||||
|
||||
String kitName = kits.get(playerName);
|
||||
if (kitName == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return loadKitFromCacheOrCreate(kitName);
|
||||
|
||||
}
|
||||
|
||||
private Kit loadKitFromCacheOrCreate(String kitName) {
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.cryptomorin.xseries.XSound;
|
||||
import com.planetgallium.kitpvp.Game;
|
||||
import com.planetgallium.kitpvp.game.Arena;
|
||||
import com.planetgallium.kitpvp.util.Resource;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
@@ -21,7 +21,7 @@ public class CacheManager {
|
||||
public static Map<String, PlayerData> getStatsCache() { return statsCache; }
|
||||
|
||||
public static Map<String, Long> getPlayerAbilityCooldowns(String username) {
|
||||
if (abilityCooldowns.get(username) == null) {
|
||||
if (!abilityCooldowns.containsKey(username)) {
|
||||
abilityCooldowns.put(username, new HashMap<>());
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.bukkit.entity.Player;
|
||||
import com.planetgallium.kitpvp.game.Arena;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -14,12 +15,10 @@ import java.util.Map;
|
||||
public class Placeholders extends PlaceholderExpansion {
|
||||
|
||||
private final Arena arena;
|
||||
private final Resources resources;
|
||||
private final Map<String, String> placeholderAPItoBuiltIn;
|
||||
|
||||
public Placeholders(Game plugin) {
|
||||
this.arena = plugin.getArena();
|
||||
this.resources = plugin.getResources();
|
||||
this.placeholderAPItoBuiltIn = new HashMap<>();
|
||||
|
||||
placeholderAPItoBuiltIn.put("stats_kills", "%kills%");
|
||||
@@ -35,55 +34,57 @@ public class Placeholders extends PlaceholderExpansion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onPlaceholderRequest(Player p, String identifier) {
|
||||
|
||||
public String onPlaceholderRequest(Player p, @NotNull String identifier) {
|
||||
if (p == null) return null;
|
||||
|
||||
if (identifier.contains("top")) {
|
||||
String[] queries = identifier.split("_");
|
||||
String topType = queries[1]; // ex: kills
|
||||
String topIdentifier = queries[2]; // ex: amount, player
|
||||
String possibleTopValue = queries[3]; // 1, 15
|
||||
int topValue = 1;
|
||||
|
||||
if (StringUtils.isNumeric(possibleTopValue)) {
|
||||
topValue = Integer.parseInt(possibleTopValue);
|
||||
} else {
|
||||
Toolkit.printToConsole("%prefix% &cFailed to properly parse placeholder, expected number but received: " + possibleTopValue);
|
||||
}
|
||||
|
||||
TopEntry entry = arena.getLeaderboards().getTopN(topType, topValue);
|
||||
boolean isUsernamePlaceholder = topIdentifier.equals("player");
|
||||
|
||||
return isUsernamePlaceholder ? entry.getIdentifier() : String.valueOf(entry.getValue());
|
||||
return handleLeaderboardPlaceholder(identifier);
|
||||
}
|
||||
|
||||
return translatePlaceholderAPIPlaceholders(identifier, p.getName());
|
||||
|
||||
}
|
||||
|
||||
private String handleLeaderboardPlaceholder(String identifier) {
|
||||
String[] queries = identifier.split("_");
|
||||
String topType = queries[1]; // ex: kills
|
||||
String topIdentifier = queries[2]; // ex: amount, player
|
||||
String possibleTopValue = queries[3]; // 1, 15
|
||||
int topValue = 1; // if number parsing fails, use top player
|
||||
|
||||
if (StringUtils.isNumeric(possibleTopValue)) {
|
||||
topValue = Integer.parseInt(possibleTopValue);
|
||||
} else {
|
||||
Toolkit.printToConsole("%prefix% &cFailed to properly parse placeholder, " +
|
||||
"expected number but received: " + possibleTopValue);
|
||||
}
|
||||
|
||||
TopEntry entry = arena.getLeaderboards().getTopN(topType, topValue);
|
||||
boolean isUsernamePlaceholder = topIdentifier.equals("player");
|
||||
|
||||
return isUsernamePlaceholder ? entry.getIdentifier() : String.valueOf(entry.getValue());
|
||||
}
|
||||
|
||||
public String translatePlaceholderAPIPlaceholders(String placeholderAPIIdentifier, String username) {
|
||||
|
||||
if (!placeholderAPItoBuiltIn.containsKey(placeholderAPIIdentifier)) {
|
||||
Toolkit.printToConsole(String.format("&7[&b&lKIT-PVP&7] &cUnknown placeholder identifier [%s]. Please see plugin page.",
|
||||
placeholderAPIIdentifier));
|
||||
if (placeholderAPItoBuiltIn.containsKey(placeholderAPIIdentifier)) {
|
||||
String toBuiltInPlaceholder = placeholderAPItoBuiltIn.get(placeholderAPIIdentifier);
|
||||
return arena.replaceBuiltInPlaceholdersIfPresent(toBuiltInPlaceholder, username);
|
||||
} else {
|
||||
Toolkit.printToConsole(String.format("&7[&b&lKIT-PVP&7] &cUnknown placeholder identifier [%s]. " +
|
||||
"Please see plugin page.", placeholderAPIIdentifier));
|
||||
return "invalid-placeholder";
|
||||
}
|
||||
|
||||
return arena.replaceBuiltInPlaceholdersIfPresent(placeholderAPItoBuiltIn.get(placeholderAPIIdentifier), username);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRegister() { return true; }
|
||||
|
||||
@Override
|
||||
public String getAuthor() { return "Cervinakuy"; }
|
||||
public @NotNull String getAuthor() { return "Cervinakuy"; }
|
||||
|
||||
@Override
|
||||
public String getIdentifier() { return "kitpvp"; }
|
||||
public @NotNull String getIdentifier() { return "kitpvp"; }
|
||||
|
||||
@Override
|
||||
public String getVersion() { return "1.0.0"; }
|
||||
public @NotNull String getVersion() { return "1.0.0"; }
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user