Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51eb4f6890 | ||
|
|
4cd6514724 | ||
|
|
3fe272a3f9 | ||
|
|
e15055744a | ||
|
|
176d883d69 | ||
|
|
6cf35e8771 | ||
|
|
f80ab04cda | ||
|
|
370ef8f8df | ||
|
|
218e1cd5ee | ||
|
|
676c19d394 | ||
|
|
3dc5c88765 | ||
|
|
08012e057e | ||
|
|
33878de93c | ||
|
|
048314c31f | ||
|
|
704e07d042 | ||
|
|
2518f64fe1 |
No files matched your search
@@ -2,7 +2,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.extendedclip.papi.expansion.essentials</groupId>
|
||||
<artifactId>essentials-expansion</artifactId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.5.1</version>
|
||||
<name>PAPI-Expansion-Essentials</name>
|
||||
<description>PlaceholderAPI expansion for Essentials placeholders</description>
|
||||
|
||||
|
||||
+132
-105
@@ -25,6 +25,7 @@ import com.earth2me.essentials.Kit;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.DescParseTickFormat;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
@@ -40,10 +41,9 @@ import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
public class EssentialsExpansion extends PlaceholderExpansion {
|
||||
@@ -102,8 +102,132 @@ public class EssentialsExpansion extends PlaceholderExpansion {
|
||||
final String papiTrue = PlaceholderAPIPlugin.booleanTrue();
|
||||
final String papiFalse = PlaceholderAPIPlugin.booleanFalse();
|
||||
|
||||
// Put this before the null check as most of it is not required
|
||||
if (identifier.startsWith("baltop_")) {
|
||||
Map<UUID, BalanceTop.Entry> baltopCache = baltop.getBalanceTopCache();
|
||||
identifier = identifier.substring(7);
|
||||
|
||||
if (identifier.startsWith("balance_")) {
|
||||
identifier = identifier.substring(8);
|
||||
|
||||
if (identifier.startsWith("fixed_")) {
|
||||
identifier = identifier.substring(6);
|
||||
|
||||
Integer id = Ints.tryParse(identifier);
|
||||
if (id == null) {
|
||||
return "Invalid ID";
|
||||
}
|
||||
|
||||
BalanceTop.Entry[] entries = baltopCache.values().toArray(new BalanceTop.Entry[0]);
|
||||
if (id >= entries.length) {
|
||||
return "0";
|
||||
}
|
||||
return String.valueOf(entries[id].getBalance().longValue());
|
||||
}
|
||||
|
||||
if (identifier.startsWith("formatted_")) {
|
||||
identifier = identifier.substring(10);
|
||||
|
||||
Integer id = Ints.tryParse(identifier);
|
||||
if (id == null) {
|
||||
return "Invalid ID";
|
||||
}
|
||||
|
||||
BalanceTop.Entry[] entries = baltopCache.values().toArray(new BalanceTop.Entry[0]);
|
||||
if (id >= entries.length) {
|
||||
return "0";
|
||||
}
|
||||
return fixMoney(entries[id].getBalance().doubleValue());
|
||||
}
|
||||
|
||||
if (identifier.startsWith("commas_")) {
|
||||
identifier = identifier.substring(7);
|
||||
|
||||
Integer id = Ints.tryParse(identifier);
|
||||
if (id == null) {
|
||||
return "Invalid ID";
|
||||
}
|
||||
|
||||
BalanceTop.Entry[] entries = baltopCache.values().toArray(new BalanceTop.Entry[0]);
|
||||
if (id >= entries.length) {
|
||||
return "0";
|
||||
}
|
||||
return format.format(entries[id].getBalance().doubleValue());
|
||||
}
|
||||
|
||||
Integer id = Ints.tryParse(identifier);
|
||||
if (id == null) {
|
||||
return "Invalid ID";
|
||||
}
|
||||
|
||||
BalanceTop.Entry[] entries = baltopCache.values().toArray(new BalanceTop.Entry[0]);
|
||||
if (id >= entries.length) {
|
||||
return "0";
|
||||
}
|
||||
return String.valueOf(entries[id].getBalance().doubleValue());
|
||||
}
|
||||
|
||||
if (identifier.startsWith("player_")) {
|
||||
identifier = identifier.substring(7);
|
||||
|
||||
boolean stripped = false;
|
||||
|
||||
if (identifier.startsWith("stripped_")) {
|
||||
identifier = identifier.substring(9);
|
||||
stripped = true;
|
||||
}
|
||||
|
||||
Integer id = Ints.tryParse(identifier);
|
||||
if (id == null) {
|
||||
return "Invalid ID";
|
||||
}
|
||||
|
||||
BalanceTop.Entry[] entries = baltopCache.values().toArray(new BalanceTop.Entry[0]);
|
||||
if (id >= entries.length) {
|
||||
return "0";
|
||||
}
|
||||
|
||||
if (stripped) {
|
||||
User user = essentials.getUser(entries[id].getUuid());
|
||||
if (user != null) {
|
||||
return user.getName();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return entries[id].getDisplayName();
|
||||
}
|
||||
}
|
||||
|
||||
if (identifier.equals("rank")) {
|
||||
// Another null check because it is above the normal one
|
||||
if (player == null) return "";
|
||||
|
||||
if (!baltopCache.containsKey(player.getUniqueId())) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return String.valueOf(new ArrayList<>(baltopCache.keySet()).indexOf(player.getUniqueId()) + 1);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (player == null) return "";
|
||||
|
||||
if (identifier.equals("tp_cooldown")) {
|
||||
final double cooldown = essentials.getSettings().getTeleportCooldown();
|
||||
|
||||
final long d1 = System.currentTimeMillis();
|
||||
final long d2 = essentials.getUser(player.getUniqueId()).getLastTeleportTimestamp();
|
||||
|
||||
long diff = TimeUnit.MILLISECONDS.toSeconds(d1 - d2);
|
||||
|
||||
if(diff < cooldown) return String.valueOf((int) (cooldown - diff));
|
||||
|
||||
return "0";
|
||||
}
|
||||
|
||||
if (identifier.startsWith("kit_last_use_")) {
|
||||
String kitName = identifier.split("kit_last_use_")[1].toLowerCase();
|
||||
Kit kit;
|
||||
@@ -190,103 +314,6 @@ public class EssentialsExpansion extends PlaceholderExpansion {
|
||||
return oPlayer.hasPermission("essentials.kits." + kit) ? papiTrue : papiFalse;
|
||||
}
|
||||
|
||||
if (identifier.startsWith("baltop_")) {
|
||||
Map<UUID, BalanceTop.Entry> baltopCache = baltop.getBalanceTopCache();
|
||||
identifier = identifier.substring(7);
|
||||
|
||||
if (identifier.startsWith("balance_")) {
|
||||
identifier = identifier.substring(8);
|
||||
|
||||
if (identifier.startsWith("fixed_")) {
|
||||
identifier = identifier.substring(6);
|
||||
|
||||
Integer id = Ints.tryParse(identifier);
|
||||
if (id == null) {
|
||||
return "Invalid ID";
|
||||
}
|
||||
|
||||
BalanceTop.Entry[] entries = baltopCache.values().toArray(new BalanceTop.Entry[0]);
|
||||
if (id >= entries.length) {
|
||||
return "0";
|
||||
}
|
||||
return String.valueOf(entries[id].getBalance().longValue());
|
||||
}
|
||||
|
||||
if (identifier.startsWith("formatted_")) {
|
||||
identifier = identifier.substring(10);
|
||||
|
||||
Integer id = Ints.tryParse(identifier);
|
||||
if (id == null) {
|
||||
return "Invalid ID";
|
||||
}
|
||||
|
||||
BalanceTop.Entry[] entries = baltopCache.values().toArray(new BalanceTop.Entry[0]);
|
||||
if (id >= entries.length) {
|
||||
return "0";
|
||||
}
|
||||
return fixMoney(entries[id].getBalance().doubleValue());
|
||||
}
|
||||
|
||||
if (identifier.startsWith("commas_")) {
|
||||
identifier = identifier.substring(7);
|
||||
|
||||
Integer id = Ints.tryParse(identifier);
|
||||
if (id == null) {
|
||||
return "Invalid ID";
|
||||
}
|
||||
|
||||
BalanceTop.Entry[] entries = baltopCache.values().toArray(new BalanceTop.Entry[0]);
|
||||
if (id >= entries.length) {
|
||||
return "0";
|
||||
}
|
||||
return format.format(entries[id].getBalance().doubleValue());
|
||||
}
|
||||
|
||||
Integer id = Ints.tryParse(identifier);
|
||||
if (id == null) {
|
||||
return "Invalid ID";
|
||||
}
|
||||
|
||||
BalanceTop.Entry[] entries = baltopCache.values().toArray(new BalanceTop.Entry[0]);
|
||||
if (id >= entries.length) {
|
||||
return "0";
|
||||
}
|
||||
return String.valueOf(entries[id].getBalance().doubleValue());
|
||||
}
|
||||
|
||||
if (identifier.startsWith("player_")) {
|
||||
identifier = identifier.substring(7);
|
||||
|
||||
Integer id = Ints.tryParse(identifier);
|
||||
if (id == null) {
|
||||
return "Invalid ID";
|
||||
}
|
||||
|
||||
BalanceTop.Entry[] entries = baltopCache.values().toArray(new BalanceTop.Entry[0]);
|
||||
if (id >= entries.length) {
|
||||
return "0";
|
||||
}
|
||||
return entries[id].getDisplayName();
|
||||
}
|
||||
|
||||
if (identifier.equals("rank")) {
|
||||
if (!baltopCache.containsKey(player.getUniqueId())) {
|
||||
return "";
|
||||
}
|
||||
|
||||
int index = 1;
|
||||
for (Map.Entry<UUID, BalanceTop.Entry> entry : baltopCache.entrySet()) {
|
||||
if (entry.getKey() == player.getUniqueId()) {
|
||||
return String.valueOf(index);
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (identifier.startsWith("home_")) {
|
||||
Integer homeNumber;
|
||||
final User user = essentials.getUser(player.getUniqueId());
|
||||
@@ -302,10 +329,10 @@ public class EssentialsExpansion extends PlaceholderExpansion {
|
||||
if (homeNumber >= user.getHomes().size() || homeNumber < 0) return "";
|
||||
|
||||
// checks if the identifier matches the pattern home_%d
|
||||
if (identifier.matches("(\\w+_)(\\d)")) return user.getHomes().get(homeNumber);
|
||||
if (identifier.matches("(\\w+_)(\\d+)")) return user.getHomes().get(homeNumber);
|
||||
|
||||
//checks if the identifier matches the pattern home_%d_(x/y/z)
|
||||
if (identifier.matches("(\\w+_)(\\d)(_\\w)")) {
|
||||
if (identifier.matches("(\\w+_)(\\d+)(_\\w)")) {
|
||||
|
||||
try {
|
||||
final Location home = user.getHome(user.getHomes().get(homeNumber));
|
||||
@@ -313,13 +340,13 @@ public class EssentialsExpansion extends PlaceholderExpansion {
|
||||
|
||||
switch (identifier.charAt(identifier.length() - 1)) {
|
||||
case 'x':
|
||||
stringBuilder.append(home.getX()).append(".5";
|
||||
stringBuilder.append(home.getX());
|
||||
break;
|
||||
case 'y':
|
||||
stringBuilder.append((int) home.getY());
|
||||
break;
|
||||
case 'z':
|
||||
stringBuilder.append(home.getZ()).append(".5");
|
||||
stringBuilder.append(home.getZ());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user