Skip to content

Commit 8814230

Browse files
authored
Merge pull request #35 from BlitzOffline/breaking/baltop-removal
2 parents 63ddf69 + 2be80b5 commit 8814230

File tree

4 files changed

+4
-257
lines changed

4 files changed

+4
-257
lines changed

src/main/java/com/extendedclip/papi/expansion/vault/BalTopTask.java

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/main/java/com/extendedclip/papi/expansion/vault/TopPlayer.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/main/java/com/extendedclip/papi/expansion/vault/VaultEcoHook.java

Lines changed: 3 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,11 @@
2929
import java.text.DecimalFormat;
3030
import java.util.HashMap;
3131
import java.util.Map;
32-
import java.util.Map.Entry;
33-
import java.util.TreeMap;
3432
import java.util.regex.Matcher;
3533
import java.util.regex.Pattern;
3634

3735
public class VaultEcoHook implements VaultHook {
3836

39-
private static final Pattern TOP_BALANCE_FIXED_PATTERN = Pattern.compile("top_balance_fixed_");
40-
private static final Pattern TOP_BALANCE_FORMATTED_PATTERN = Pattern.compile("top_balance_formatted_");
41-
private static final Pattern TOP_BALANCE_COMMAS_PATTERN = Pattern.compile("top_balance_commas_");
42-
private static final Pattern TOP_BALANCE_PATTERN = Pattern.compile("top_balance_");
43-
private static final Pattern TOP_PLAYER_PATTERN = Pattern.compile("top_player_");
44-
4537
private static final Pattern BALANCE_DECIMAL_POINTS_PATTERN = Pattern.compile("balance_(?<points>\\d+)dp");
4638

4739
private final Map<Integer, DecimalFormat> decimalFormats = new HashMap<>();
@@ -52,24 +44,14 @@ public class VaultEcoHook implements VaultHook {
5244
private final String t;
5345
private final String q;
5446
private final DecimalFormat format = new DecimalFormat("#,###");
55-
private final boolean baltopEnabled;
56-
private final int taskDelay;
57-
private final int topSize;
58-
private final Map<Integer, TopPlayer> balTop = new TreeMap<>();
5947

6048
private final VaultExpansion expansion;
61-
private final VaultPermsHook perms;
6249

6350
private Economy eco;
64-
private BalTopTask balTopTask;
6551

66-
VaultEcoHook(VaultExpansion expansion, VaultPermsHook perms) {
52+
VaultEcoHook(VaultExpansion expansion) {
6753
this.expansion = expansion;
68-
this.perms = perms;
6954

70-
baltopEnabled = (Boolean) expansion.get("baltop.enabled", false);
71-
topSize = expansion.getInt("baltop.cache_size", 100);
72-
taskDelay = expansion.getInt("baltop.check_delay", 30);
7355
k = expansion.getString("formatting.thousands", "k");
7456
m = expansion.getString("formatting.millions", "m");
7557
b = expansion.getString("formatting.billions", "b");
@@ -79,29 +61,14 @@ public class VaultEcoHook implements VaultHook {
7961

8062
@Override
8163
public boolean setup() {
82-
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager()
83-
.getRegistration(Economy.class);
64+
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
8465

8566
if (rsp == null) {
8667
return false;
8768
}
8869

8970
eco = rsp.getProvider();
90-
91-
if (baltopEnabled) {
92-
this.balTopTask = new BalTopTask(this, perms);
93-
balTopTask.runTaskTimerAsynchronously(expansion.getPlaceholderAPI(), 20, 20 * taskDelay);
94-
}
95-
96-
return eco != null;
97-
}
98-
99-
public void clear() {
100-
balTop.clear();
101-
if (this.balTopTask != null) {
102-
this.balTopTask.cancel();
103-
this.balTopTask = null;
104-
}
71+
return true;
10572
}
10673

10774
protected Economy getEco() {
@@ -112,78 +79,8 @@ protected VaultExpansion getExpansion() {
11279
return this.expansion;
11380
}
11481

115-
protected Map<Integer, TopPlayer> getBalTop() {
116-
return balTop;
117-
}
118-
119-
void setBalTop(Map<String, Double> map) {
120-
this.balTop.clear();
121-
int count = 1;
122-
for (Entry<String, Double> entry : map.entrySet()) {
123-
if (count >= topSize) {
124-
break;
125-
}
126-
balTop.put(count, new TopPlayer(entry.getKey(), entry.getValue()));
127-
count++;
128-
}
129-
}
130-
13182
@Override
13283
public String onPlaceholderRequest(OfflinePlayer p, String identifier) {
133-
if (!baltopEnabled && identifier.startsWith("top_")) {
134-
return (identifier.startsWith("top_balance")) ? "0" : "";
135-
}
136-
137-
if (identifier.startsWith("top_balance_fixed_")) {
138-
String[] args = TOP_BALANCE_FIXED_PATTERN.split(identifier);
139-
140-
if (args.length > 1) {
141-
return toLong(getTopBalance(getInt(args[1])));
142-
}
143-
144-
return "0";
145-
}
146-
147-
if (identifier.startsWith("top_balance_formatted_")) {
148-
String[] args = TOP_BALANCE_FORMATTED_PATTERN.split(identifier);
149-
150-
if (args.length > 1) {
151-
return fixMoney(getTopBalance(getInt(args[1])));
152-
}
153-
154-
return "0";
155-
}
156-
157-
if (identifier.startsWith("top_balance_commas_")) {
158-
String[] args = TOP_BALANCE_COMMAS_PATTERN.split(identifier);
159-
160-
if (args.length > 1) {
161-
return format.format(getTopBalance(getInt(args[1])));
162-
}
163-
164-
return "0";
165-
}
166-
167-
if (identifier.startsWith("top_balance_")) {
168-
String[] args = TOP_BALANCE_PATTERN.split(identifier);
169-
170-
if (args.length > 1) {
171-
return String.valueOf(getTopBalance(getInt(args[1])));
172-
}
173-
174-
return "0";
175-
}
176-
177-
if (identifier.startsWith("top_player_")) {
178-
String[] args = TOP_PLAYER_PATTERN.split(identifier);
179-
180-
if (args.length > 1) {
181-
return getTopPlayer(getInt(args[1]));
182-
}
183-
184-
return "";
185-
}
186-
18784
if (p == null) {
18885
return "";
18986
}
@@ -205,8 +102,6 @@ public String onPlaceholderRequest(OfflinePlayer p, String identifier) {
205102
return fixMoney(getBalance(p));
206103
case "balance_commas":
207104
return format.format(getBalance(p));
208-
case "top_rank":
209-
return getRank(p.getName());
210105
}
211106
return null;
212107
}
@@ -262,36 +157,6 @@ private String setDecimalPoints(double d, int points) {
262157
return eco == null ? 0 : eco.getBalance(p);
263158
}
264159

265-
private String getTopPlayer(int rank) {
266-
if (!baltopEnabled) {
267-
return "";
268-
}
269-
270-
final TopPlayer topPlayer = balTop.get(rank);
271-
return topPlayer.getName();
272-
}
273-
274-
private double getTopBalance(int rank) {
275-
if (!baltopEnabled) {
276-
return 0;
277-
}
278-
279-
final TopPlayer topPlayer = balTop.get(rank);
280-
return topPlayer == null ? 0 : topPlayer.getBal();
281-
}
282-
283-
private String getRank(String player) {
284-
if (!baltopEnabled) {
285-
return null;
286-
}
287-
288-
return balTop.entrySet().stream()
289-
.filter(e -> e.getValue().getName().equals(player))
290-
.findFirst()
291-
.map(e -> e.getKey().toString())
292-
.orElse("");
293-
}
294-
295160
private int getInt(String string) {
296161
final Integer integer = Ints.tryParse(string);
297162
return integer == null ? 0 : integer;

src/main/java/com/extendedclip/papi/expansion/vault/VaultExpansion.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,18 @@ public class VaultExpansion extends PlaceholderExpansion implements Cacheable, C
3737

3838
public VaultExpansion() {
3939
perms = new VaultPermsHook();
40-
eco = new VaultEcoHook(this, perms);
40+
eco = new VaultEcoHook(this);
4141
}
4242

4343
@Override
4444
public void clear() {
45-
if (eco != null) {
46-
eco.clear();
47-
}
4845
eco = null;
4946
perms = null;
5047
}
5148

5249
@Override
5350
public Map<String, Object> getDefaults() {
5451
final Map<String, Object> defaults = new HashMap<>();
55-
defaults.put("baltop.enabled", false);
56-
defaults.put("baltop.cache_size", 100);
57-
defaults.put("baltop.check_delay", 30);
5852
defaults.put("formatting.thousands", "k");
5953
defaults.put("formatting.millions", "M");
6054
defaults.put("formatting.billions", "B");

0 commit comments

Comments
 (0)