From 2be80b521c68408629d4e52a7a638c45fc8c5664 Mon Sep 17 00:00:00 2001 From: BlitzOffline <52609756+BlitzOffline@users.noreply.github.com> Date: Thu, 26 May 2022 21:54:57 +0300 Subject: [PATCH] Removed the baltop placeholders --- .../papi/expansion/vault/BalTopTask.java | 64 -------- .../papi/expansion/vault/TopPlayer.java | 48 ------ .../papi/expansion/vault/VaultEcoHook.java | 141 +----------------- .../papi/expansion/vault/VaultExpansion.java | 8 +- 4 files changed, 4 insertions(+), 257 deletions(-) delete mode 100644 src/main/java/com/extendedclip/papi/expansion/vault/BalTopTask.java delete mode 100644 src/main/java/com/extendedclip/papi/expansion/vault/TopPlayer.java diff --git a/src/main/java/com/extendedclip/papi/expansion/vault/BalTopTask.java b/src/main/java/com/extendedclip/papi/expansion/vault/BalTopTask.java deleted file mode 100644 index a2e330c..0000000 --- a/src/main/java/com/extendedclip/papi/expansion/vault/BalTopTask.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * - * Vault-Expansion - * Copyright (C) 2018-2020 Ryan McCarthy - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * - */ -package com.extendedclip.papi.expansion.vault; - -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.scheduler.BukkitRunnable; - -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Map.Entry; - -import static java.util.stream.Collectors.toMap; - -class BalTopTask extends BukkitRunnable { - - private final VaultEcoHook eco; - private final VaultPermsHook perms; - - public BalTopTask(VaultEcoHook eco, VaultPermsHook perms) { - this.eco = eco; - this.perms = perms; - } - - @Override - public void run() { - final Map top = new LinkedHashMap<>(); - - for (OfflinePlayer player : Bukkit.getOfflinePlayers()) { - if (player == null || player.getName() == null) { - continue; - } - - if (!perms.hasPerm(player, "essentials.balancetop.exclude") || !Bukkit.getPluginManager().isPluginEnabled("Essentials")) { - top.put(player.getName(), eco.getBalance(player)); - } - } - - eco.setBalTop( - top.entrySet().stream() - .sorted(Collections.reverseOrder(Entry.comparingByValue())) - .collect(toMap(Entry::getKey, Entry::getValue, (player, balance) -> balance, LinkedHashMap::new)) - ); - } -} diff --git a/src/main/java/com/extendedclip/papi/expansion/vault/TopPlayer.java b/src/main/java/com/extendedclip/papi/expansion/vault/TopPlayer.java deleted file mode 100644 index bd560d7..0000000 --- a/src/main/java/com/extendedclip/papi/expansion/vault/TopPlayer.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * - * Vault-Expansion - * Copyright (C) 2018-2020 Ryan McCarthy - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * - */ -package com.extendedclip.papi.expansion.vault; - -class TopPlayer { - - private String name; - private double bal; - - public TopPlayer(String name, double bal) { - setName(name); - setBal(bal); - } - - public String getName() { - return name; - } - - private void setName(String name) { - this.name = name; - } - - public double getBal() { - return bal; - } - - private void setBal(double bal) { - this.bal = bal; - } -} diff --git a/src/main/java/com/extendedclip/papi/expansion/vault/VaultEcoHook.java b/src/main/java/com/extendedclip/papi/expansion/vault/VaultEcoHook.java index b7690d9..942e454 100644 --- a/src/main/java/com/extendedclip/papi/expansion/vault/VaultEcoHook.java +++ b/src/main/java/com/extendedclip/papi/expansion/vault/VaultEcoHook.java @@ -29,19 +29,11 @@ import java.text.DecimalFormat; import java.util.HashMap; import java.util.Map; -import java.util.Map.Entry; -import java.util.TreeMap; import java.util.regex.Matcher; import java.util.regex.Pattern; public class VaultEcoHook implements VaultHook { - private static final Pattern TOP_BALANCE_FIXED_PATTERN = Pattern.compile("top_balance_fixed_"); - private static final Pattern TOP_BALANCE_FORMATTED_PATTERN = Pattern.compile("top_balance_formatted_"); - private static final Pattern TOP_BALANCE_COMMAS_PATTERN = Pattern.compile("top_balance_commas_"); - private static final Pattern TOP_BALANCE_PATTERN = Pattern.compile("top_balance_"); - private static final Pattern TOP_PLAYER_PATTERN = Pattern.compile("top_player_"); - private static final Pattern BALANCE_DECIMAL_POINTS_PATTERN = Pattern.compile("balance_(?\\d+)dp"); private final Map decimalFormats = new HashMap<>(); @@ -52,24 +44,14 @@ public class VaultEcoHook implements VaultHook { private final String t; private final String q; private final DecimalFormat format = new DecimalFormat("#,###"); - private final boolean baltopEnabled; - private final int taskDelay; - private final int topSize; - private final Map balTop = new TreeMap<>(); private final VaultExpansion expansion; - private final VaultPermsHook perms; private Economy eco; - private BalTopTask balTopTask; - VaultEcoHook(VaultExpansion expansion, VaultPermsHook perms) { + VaultEcoHook(VaultExpansion expansion) { this.expansion = expansion; - this.perms = perms; - baltopEnabled = (Boolean) expansion.get("baltop.enabled", false); - topSize = expansion.getInt("baltop.cache_size", 100); - taskDelay = expansion.getInt("baltop.check_delay", 30); k = expansion.getString("formatting.thousands", "k"); m = expansion.getString("formatting.millions", "m"); b = expansion.getString("formatting.billions", "b"); @@ -79,29 +61,14 @@ public class VaultEcoHook implements VaultHook { @Override public boolean setup() { - RegisteredServiceProvider rsp = Bukkit.getServer().getServicesManager() - .getRegistration(Economy.class); + RegisteredServiceProvider rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class); if (rsp == null) { return false; } eco = rsp.getProvider(); - - if (baltopEnabled) { - this.balTopTask = new BalTopTask(this, perms); - balTopTask.runTaskTimerAsynchronously(expansion.getPlaceholderAPI(), 20, 20 * taskDelay); - } - - return eco != null; - } - - public void clear() { - balTop.clear(); - if (this.balTopTask != null) { - this.balTopTask.cancel(); - this.balTopTask = null; - } + return true; } protected Economy getEco() { @@ -112,78 +79,8 @@ protected VaultExpansion getExpansion() { return this.expansion; } - protected Map getBalTop() { - return balTop; - } - - void setBalTop(Map map) { - this.balTop.clear(); - int count = 1; - for (Entry entry : map.entrySet()) { - if (count >= topSize) { - break; - } - balTop.put(count, new TopPlayer(entry.getKey(), entry.getValue())); - count++; - } - } - @Override public String onPlaceholderRequest(OfflinePlayer p, String identifier) { - if (!baltopEnabled && identifier.startsWith("top_")) { - return (identifier.startsWith("top_balance")) ? "0" : ""; - } - - if (identifier.startsWith("top_balance_fixed_")) { - String[] args = TOP_BALANCE_FIXED_PATTERN.split(identifier); - - if (args.length > 1) { - return toLong(getTopBalance(getInt(args[1]))); - } - - return "0"; - } - - if (identifier.startsWith("top_balance_formatted_")) { - String[] args = TOP_BALANCE_FORMATTED_PATTERN.split(identifier); - - if (args.length > 1) { - return fixMoney(getTopBalance(getInt(args[1]))); - } - - return "0"; - } - - if (identifier.startsWith("top_balance_commas_")) { - String[] args = TOP_BALANCE_COMMAS_PATTERN.split(identifier); - - if (args.length > 1) { - return format.format(getTopBalance(getInt(args[1]))); - } - - return "0"; - } - - if (identifier.startsWith("top_balance_")) { - String[] args = TOP_BALANCE_PATTERN.split(identifier); - - if (args.length > 1) { - return String.valueOf(getTopBalance(getInt(args[1]))); - } - - return "0"; - } - - if (identifier.startsWith("top_player_")) { - String[] args = TOP_PLAYER_PATTERN.split(identifier); - - if (args.length > 1) { - return getTopPlayer(getInt(args[1])); - } - - return ""; - } - if (p == null) { return ""; } @@ -205,8 +102,6 @@ public String onPlaceholderRequest(OfflinePlayer p, String identifier) { return fixMoney(getBalance(p)); case "balance_commas": return format.format(getBalance(p)); - case "top_rank": - return getRank(p.getName()); } return null; } @@ -262,36 +157,6 @@ private String setDecimalPoints(double d, int points) { return eco == null ? 0 : eco.getBalance(p); } - private String getTopPlayer(int rank) { - if (!baltopEnabled) { - return ""; - } - - final TopPlayer topPlayer = balTop.get(rank); - return topPlayer.getName(); - } - - private double getTopBalance(int rank) { - if (!baltopEnabled) { - return 0; - } - - final TopPlayer topPlayer = balTop.get(rank); - return topPlayer == null ? 0 : topPlayer.getBal(); - } - - private String getRank(String player) { - if (!baltopEnabled) { - return null; - } - - return balTop.entrySet().stream() - .filter(e -> e.getValue().getName().equals(player)) - .findFirst() - .map(e -> e.getKey().toString()) - .orElse(""); - } - private int getInt(String string) { final Integer integer = Ints.tryParse(string); return integer == null ? 0 : integer; diff --git a/src/main/java/com/extendedclip/papi/expansion/vault/VaultExpansion.java b/src/main/java/com/extendedclip/papi/expansion/vault/VaultExpansion.java index fd424a7..78e65c3 100644 --- a/src/main/java/com/extendedclip/papi/expansion/vault/VaultExpansion.java +++ b/src/main/java/com/extendedclip/papi/expansion/vault/VaultExpansion.java @@ -37,14 +37,11 @@ public class VaultExpansion extends PlaceholderExpansion implements Cacheable, C public VaultExpansion() { perms = new VaultPermsHook(); - eco = new VaultEcoHook(this, perms); + eco = new VaultEcoHook(this); } @Override public void clear() { - if (eco != null) { - eco.clear(); - } eco = null; perms = null; } @@ -52,9 +49,6 @@ public void clear() { @Override public Map getDefaults() { final Map defaults = new HashMap<>(); - defaults.put("baltop.enabled", false); - defaults.put("baltop.cache_size", 100); - defaults.put("baltop.check_delay", 30); defaults.put("formatting.thousands", "k"); defaults.put("formatting.millions", "M"); defaults.put("formatting.billions", "B");