Merge from upstream #1
No files matched your search
@@ -147,3 +147,4 @@ dist/
|
||||
nbdist/
|
||||
.nb-gradle/
|
||||
nbactions.xml
|
||||
/.gradle/
|
||||
+1
-1
@@ -3,7 +3,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "at.helpch"
|
||||
version = "1.6.0"
|
||||
version = "2.0.0"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[versions]
|
||||
spigot = "1.20.5-R0.1-SNAPSHOT"
|
||||
spigot = "26.1.2-R0.1-SNAPSHOT"
|
||||
papi = "2.12.2"
|
||||
ess = "2.21.2"
|
||||
|
||||
|
||||
@@ -0,0 +1,433 @@
|
||||
/*
|
||||
*
|
||||
* Essentials-Expansion
|
||||
* Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package at.helpch.essentialsexpansion;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.Kit;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.DescParseTickFormat;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import com.google.common.primitives.Ints;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.expansion.Configurable;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.expansion.Taskable;
|
||||
import net.essentialsx.api.v2.services.BalanceTop;
|
||||
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
public class EssentialsExpansion extends PlaceholderExpansion implements Taskable, Configurable {
|
||||
|
||||
private static final NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
|
||||
private static final DecimalFormat commasFormat = new DecimalFormat("#,###");
|
||||
private static final DecimalFormat coordsFormat = commasFormat;
|
||||
private static final List<String> placeholders;
|
||||
|
||||
static {
|
||||
placeholders = Stream.of(
|
||||
Stream.of(
|
||||
"balance",
|
||||
"balance_commas",
|
||||
"balance_fixed",
|
||||
"balance_formatted",
|
||||
"player_stripped",
|
||||
"player"
|
||||
).map(placeholder -> "baltop_" + placeholder + "_<rank>"),
|
||||
|
||||
Stream.of(
|
||||
"baltop_rank",
|
||||
"is_clearinventory_confirm",
|
||||
"is_pay_confirm",
|
||||
"is_pay_enabled",
|
||||
"is_teleport_enabled",
|
||||
"muted",
|
||||
"vanished",
|
||||
|
||||
"afk",
|
||||
"afk_reason",
|
||||
"afk_player_count",
|
||||
|
||||
"msg_ignore",
|
||||
"fly",
|
||||
|
||||
"nickname",
|
||||
"nickname_stripped",
|
||||
|
||||
"muted_time_remaining",
|
||||
"geolocation",
|
||||
"godmode",
|
||||
"unique",
|
||||
|
||||
"jailed",
|
||||
"jailed_time_remaining",
|
||||
|
||||
"pm_recipient",
|
||||
"safe_online",
|
||||
"tp_cooldown",
|
||||
|
||||
"world_date",
|
||||
"world_time",
|
||||
"world_time_24",
|
||||
|
||||
"worth",
|
||||
"worth_<material>"
|
||||
),
|
||||
|
||||
Stream.of(
|
||||
"last_use",
|
||||
"is_available",
|
||||
"time_until_available",
|
||||
"has"
|
||||
).map(placeholder -> "kit_" + placeholder + "_<kit>"),
|
||||
|
||||
Stream.of(
|
||||
Stream.of(
|
||||
"total",
|
||||
"max",
|
||||
"name_<index>",
|
||||
"has_<name>"
|
||||
),
|
||||
Stream.of(
|
||||
"world",
|
||||
"x",
|
||||
"y",
|
||||
"z"
|
||||
).map(placeholder -> placeholder + "_<name|index>")
|
||||
).flatMap(s->s).map(placeholder -> "home_" + placeholder)
|
||||
|
||||
).flatMap(s->s).map(placeholder -> "%essentials_" + placeholder + "%").toList();
|
||||
System.out.println(placeholders);
|
||||
}
|
||||
|
||||
private Map<Long, String> formats;
|
||||
|
||||
private Essentials essentials;
|
||||
private BalanceTop baltop;
|
||||
|
||||
@Override
|
||||
public @NotNull String getAuthor() {
|
||||
return "clip";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "essentials";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getVersion() {
|
||||
return "2.0.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getRequiredPlugin() {
|
||||
return "Essentials";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> getPlaceholders() {
|
||||
return placeholders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getDefaults() {
|
||||
return Map.of(
|
||||
"formatting.thousands", "k",
|
||||
"formatting.millions", "m",
|
||||
"formatting.billions", "b",
|
||||
"formatting.trillions", "t",
|
||||
"formatting.quadrillions", "q"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
formats = new LinkedHashMap<>() {{
|
||||
put(1000000000000000L, getString("formatting.quadrillions", "q"));
|
||||
put(1000000000000L, getString("formatting.trillions", "t"));
|
||||
put(1000000000L, getString("formatting.billions", "b"));
|
||||
put(1000000L, getString("formatting.millions", "m"));
|
||||
put(1000L, getString("formatting.thousands", "k"));
|
||||
}};
|
||||
essentials = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials");
|
||||
assert essentials != null;
|
||||
baltop = essentials.getBalanceTop();
|
||||
baltop.calculateBalanceTopMapAsync();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {}
|
||||
|
||||
@Override
|
||||
public String onRequest(OfflinePlayer player, String params) {
|
||||
|
||||
// Put this before the null check as most of it doesn't require a player
|
||||
if (params.startsWith("baltop_")) {
|
||||
Map<UUID, BalanceTop.Entry> baltopCache = baltop.getBalanceTopCache();
|
||||
params = params.substring("baltop_".length());
|
||||
|
||||
String[] args = params.split("_");
|
||||
return switch (args[0]) {
|
||||
case "balance", "player" -> {
|
||||
if (args.length == 1) yield null;
|
||||
|
||||
Integer rank = Ints.tryParse(args[args.length > 2 ? 2 : 1]);
|
||||
if (rank == null) yield "Invalid rank";
|
||||
|
||||
BalanceTop.Entry[] entries = baltopCache.values().toArray(new BalanceTop.Entry[0]);
|
||||
if (rank >= entries.length) yield "0";
|
||||
|
||||
if (args[0].equals("balance")) {
|
||||
yield switch (args[1]) {
|
||||
case "fixed" -> String.valueOf(entries[rank].getBalance().longValue());
|
||||
case "formatted" -> fixMoney(entries[rank].getBalance().doubleValue());
|
||||
case "commas" -> commasFormat.format(entries[rank].getBalance().doubleValue());
|
||||
default -> String.valueOf(entries[rank].getBalance().doubleValue());
|
||||
};
|
||||
}
|
||||
|
||||
if (args[1].equals("stripped")) {
|
||||
User user = essentials.getUser(entries[rank].getUuid());
|
||||
yield user != null ? user.getName() : null;
|
||||
}
|
||||
yield entries[rank].getDisplayName();
|
||||
}
|
||||
case "rank" -> {
|
||||
// Another null check because it's above the normal one
|
||||
if (player == null) yield "";
|
||||
|
||||
if (!baltopCache.containsKey(player.getUniqueId())) yield "";
|
||||
|
||||
yield String.valueOf(new ArrayList<>(baltopCache.keySet()).indexOf(player.getUniqueId()) + 1);
|
||||
}
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
if (player == null) return "";
|
||||
|
||||
Object output = request(player, params);
|
||||
return switch (output) {
|
||||
case null -> null;
|
||||
case Boolean bool -> bool ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse();
|
||||
default -> output.toString();
|
||||
};
|
||||
}
|
||||
|
||||
private Object request(OfflinePlayer player, String params) {
|
||||
User user = essentials.getUser(player.getUniqueId());
|
||||
return switch (params) {
|
||||
case "is_clearinventory_confirm" -> user.isPromptingClearConfirm();
|
||||
case "is_pay_confirm" -> user.isPromptingPayConfirm();
|
||||
case "is_pay_enabled" -> user.isAcceptingPay();
|
||||
case "is_teleport_enabled" -> user.isTeleportEnabled();
|
||||
case "muted", "is_muted" -> user.isMuted();
|
||||
case "vanished" -> user.isVanished();
|
||||
|
||||
case "afk" -> user.isAfk();
|
||||
case "afk_reason" -> user.getAfkMessage() == null ? "" : ChatColor.translateAlternateColorCodes('&', user.getAfkMessage());
|
||||
case "afk_player_count" -> String.valueOf(essentials
|
||||
.getUsers()
|
||||
.getAllUserUUIDs()
|
||||
.stream()
|
||||
.map(essentials::getUser)
|
||||
.filter(User::isAfk)
|
||||
.count());
|
||||
|
||||
case "msg_ignore" -> user.isIgnoreMsg();
|
||||
case "fly" -> user.getBase().getAllowFlight();
|
||||
|
||||
case "nickname" -> user.getNickname() != null ? user.getNickname() : player.getName();
|
||||
case "nickname_stripped" -> ChatColor.stripColor(user.getNickname() != null ? user.getNickname() : player.getName());
|
||||
|
||||
case "muted_time_remaining" -> user.isMuted() ? DateUtil.formatDateDiff(user.getMuteTimeout()) : "";
|
||||
case "geolocation" -> user.getGeoLocation() != null ? user.getGeoLocation() : "";
|
||||
case "godmode" -> user.isGodModeEnabled();
|
||||
case "unique" -> NumberFormat.getInstance().format(essentials.getUsers().getUserCount());
|
||||
|
||||
case "jailed" -> user.isJailed();
|
||||
case "jailed_time_remaining" -> user.isJailed() ? user.getFormattedJailTime() : "";
|
||||
|
||||
case "pm_recipient" -> user.getReplyRecipient() != null ? user.getReplyRecipient().getName() : "";
|
||||
case "safe_online" -> String.valueOf(StreamSupport
|
||||
.stream(essentials.getOnlineUsers().spliterator(), false)
|
||||
.filter(user1 -> !user1.isHidden())
|
||||
.count());
|
||||
case "tp_cooldown" -> {
|
||||
final double cooldown = essentials.getSettings().getTeleportCooldown();
|
||||
|
||||
final long now = System.currentTimeMillis();
|
||||
final long lastTeleport = user.getLastTeleportTimestamp();
|
||||
|
||||
long diff = TimeUnit.MILLISECONDS.toSeconds(now - lastTeleport);
|
||||
|
||||
yield diff < cooldown ? String.valueOf((int) (cooldown - diff)) :"0";
|
||||
}
|
||||
|
||||
case "world_date" -> DateFormat.getDateInstance(DateFormat.MEDIUM, essentials.getI18n().getCurrentLocale())
|
||||
.format(DescParseTickFormat.ticksToDate(user.getWorld() == null ? 0 : user.getWorld().getFullTime()));
|
||||
case "world_time" -> DescParseTickFormat.format12(user.getWorld() == null ? 0 : user.getWorld().getTime());
|
||||
case "world_time_24" -> DescParseTickFormat.format24(user.getWorld() == null ? 0 : user.getWorld().getTime());
|
||||
default -> {
|
||||
String[] args = params.split("_");
|
||||
params = params.substring(args[0].length() + (params.contains("_") ? 1 : 0));
|
||||
|
||||
yield switch (args[0]) {
|
||||
case "kit" -> {
|
||||
if (params.startsWith("last_use_")) {
|
||||
String kitName = params.substring("last_use_".length()).toLowerCase();
|
||||
|
||||
try {
|
||||
Kit kit = new Kit(kitName, essentials);
|
||||
long time = user.getKitTimestamp(kit.getName());
|
||||
yield time <= 0 ? "0" : PlaceholderAPIPlugin.getDateFormat().format(new Date(time));
|
||||
} catch (Exception e) {
|
||||
yield "Invalid kit name";
|
||||
}
|
||||
}
|
||||
|
||||
if (params.startsWith("is_available_")) {
|
||||
String kitName = params.substring("is_available_".length()).toLowerCase();
|
||||
|
||||
try {
|
||||
Kit kit = new Kit(kitName, essentials);
|
||||
try {
|
||||
long time = kit.getNextUse(user);
|
||||
yield time == 0;
|
||||
} catch (Exception e) {
|
||||
yield false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
yield "Invalid kit name";
|
||||
}
|
||||
}
|
||||
if (params.startsWith("time_until_available_")) {
|
||||
String kitName = params.substring("time_until_available_".length()).toLowerCase();
|
||||
boolean raw = false;
|
||||
|
||||
if (kitName.startsWith("raw_")) {
|
||||
raw = true;
|
||||
kitName = kitName.substring(4);
|
||||
|
||||
}
|
||||
if (kitName.isEmpty()) yield "Invalid kit name";
|
||||
|
||||
try {
|
||||
Kit kit = new Kit(kitName, essentials);
|
||||
try {
|
||||
long time = kit.getNextUse(user);
|
||||
if (time <= System.currentTimeMillis()) yield raw ? "0" : DateUtil.formatDateDiff(System.currentTimeMillis());
|
||||
yield raw ? String.valueOf(Instant.now().until(Instant.ofEpochMilli(time), ChronoUnit.MILLIS)) : DateUtil.formatDateDiff(time);
|
||||
} catch (Exception e) {
|
||||
yield "-1";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
yield "Invalid kit name";
|
||||
}
|
||||
}
|
||||
|
||||
if (params.startsWith("has_")) {
|
||||
Player p = player.getPlayer();
|
||||
yield p != null && p.hasPermission("essentials.kits." + params.substring("has_".length()));
|
||||
}
|
||||
yield null;
|
||||
}
|
||||
case "home" -> {
|
||||
String type = args[1];
|
||||
|
||||
List<String> homes = user.getHomes();
|
||||
|
||||
String homeName = params.substring(type.length() + (params.contains("_") ? 1 : 0));
|
||||
Integer homeNumber = Ints.tryParse(homeName);
|
||||
|
||||
yield switch (type) {
|
||||
case "total" -> homes.size() + "";
|
||||
case "max" -> essentials.getSettings().getHomeLimit(user);
|
||||
case "has" -> user.hasHome(homeName);
|
||||
case "name" -> homeNumber == null || homeNumber < 0 || homeNumber >= homes.size() ? "" : user.getHomes().get(homeNumber);
|
||||
default -> {
|
||||
if (homeNumber != null && (homeNumber < 0 || homeNumber >= user.getHomes().size())) yield "Invalid home";
|
||||
|
||||
Location home = user.getHome(homeNumber == null ? homeName : user.getHomes().get(homeNumber));
|
||||
if (home == null) yield "Invalid home";
|
||||
|
||||
Object output = switch (type) {
|
||||
case "w", "world" -> home.getWorld() == null ? "null" : home.getWorld().getName();
|
||||
case "x" -> home.getX();
|
||||
case "y" -> home.getY();
|
||||
case "z" -> home.getZ();
|
||||
default -> null;
|
||||
};
|
||||
yield output instanceof Double coords ? coordsFormat.format(coords) : output;
|
||||
}
|
||||
};
|
||||
}
|
||||
case "worth" -> {
|
||||
ItemStack item;
|
||||
if (args.length == 1) {
|
||||
Player p = player.getPlayer();
|
||||
if (p == null) yield "Player offline and no material provided";
|
||||
|
||||
item = p.getInventory().getItemInMainHand();
|
||||
} else {
|
||||
Material material = Material.getMaterial(params.toUpperCase());
|
||||
if (material == null) yield "Invalid material";
|
||||
|
||||
item = new ItemStack(material);
|
||||
}
|
||||
if (item.getType() == Material.AIR) yield "No worth";
|
||||
|
||||
BigDecimal worth = essentials.getWorth().getPrice(essentials, item);
|
||||
yield worth == null ? "No worth" : worth.doubleValue();
|
||||
}
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private String fixMoney(double d) {
|
||||
for (Map.Entry<Long, String> format : formats.entrySet()) {
|
||||
System.out.println(d + " >= " + format.getKey() + " | " + d / format.getKey());
|
||||
if (d < format.getKey()) continue;
|
||||
numberFormat.setMaximumFractionDigits(2);
|
||||
numberFormat.setMinimumFractionDigits(0);
|
||||
return numberFormat.format(d / format.getKey()) + format.getValue();
|
||||
}
|
||||
return numberFormat.format(d);
|
||||
}
|
||||
}
|
||||
@@ -1,464 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Essentials-Expansion
|
||||
* Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package com.extendedclip.papi.expansion.essentials;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
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;
|
||||
import net.essentialsx.api.v2.services.BalanceTop;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
public class EssentialsExpansion extends PlaceholderExpansion {
|
||||
|
||||
private String k;
|
||||
private String m;
|
||||
private String b;
|
||||
private String t;
|
||||
private String q;
|
||||
private final DecimalFormat format = new DecimalFormat("#,###");
|
||||
|
||||
private final DecimalFormat coordsFormat = new DecimalFormat("#.###");
|
||||
|
||||
private Essentials essentials;
|
||||
private BalanceTop baltop;
|
||||
|
||||
@Override
|
||||
public boolean canRegister() {
|
||||
return Bukkit.getPluginManager().getPlugin("Essentials") != null && Bukkit.getPluginManager().getPlugin("Essentials").isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean register() {
|
||||
k = getString("formatting.thousands", "k");
|
||||
m = getString("formatting.millions", "m");
|
||||
b = getString("formatting.billions", "b");
|
||||
t = getString("formatting.trillions", "t");
|
||||
q = getString("formatting.quadrillions", "q");
|
||||
|
||||
essentials = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials");
|
||||
if (essentials != null && essentials.isEnabled()) {
|
||||
baltop = essentials.getBalanceTop();
|
||||
baltop.calculateBalanceTopMapAsync();
|
||||
return super.register();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "clip";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "essentials";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "1.6.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onRequest(OfflinePlayer player, String identifier) {
|
||||
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;
|
||||
|
||||
try {
|
||||
kit = new Kit(kitName, essentials);
|
||||
} catch (Exception e) {
|
||||
return "Invalid kit name";
|
||||
}
|
||||
|
||||
long time = essentials.getUser(player.getUniqueId()).getKitTimestamp(kit.getName());
|
||||
|
||||
if (time == 1 || time <= 0) {
|
||||
return "1";
|
||||
}
|
||||
return PlaceholderAPIPlugin.getDateFormat().format(new Date(time));
|
||||
}
|
||||
|
||||
if (identifier.startsWith("kit_is_available_")) {
|
||||
String kitName = identifier.split("kit_is_available_")[1].toLowerCase();
|
||||
Kit kit;
|
||||
User user = essentials.getUser(player.getUniqueId());
|
||||
long time;
|
||||
|
||||
try {
|
||||
kit = new Kit(kitName, essentials);
|
||||
} catch (Exception e) {
|
||||
return "Invalid kit name";
|
||||
}
|
||||
|
||||
try {
|
||||
time = kit.getNextUse(user);
|
||||
} catch (Exception e) {
|
||||
return papiFalse;
|
||||
}
|
||||
|
||||
return time == 0 ? papiTrue : papiFalse;
|
||||
}
|
||||
|
||||
if (identifier.startsWith("kit_time_until_available_")) {
|
||||
String kitName = identifier.split("kit_time_until_available_")[1].toLowerCase();
|
||||
boolean raw = false;
|
||||
User user = essentials.getUser(player.getUniqueId());
|
||||
Kit kit;
|
||||
long time;
|
||||
|
||||
if (kitName.startsWith("raw_")) {
|
||||
raw = true;
|
||||
kitName = kitName.substring(4);
|
||||
|
||||
if (kitName.isEmpty()) {
|
||||
return "Invalid kit name";
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
kit = new Kit(kitName, essentials);
|
||||
} catch (Exception e) {
|
||||
return "Invalid kit name";
|
||||
}
|
||||
|
||||
try {
|
||||
time = kit.getNextUse(user);
|
||||
} catch (Exception e) {
|
||||
return "-1";
|
||||
}
|
||||
|
||||
if (time <= System.currentTimeMillis()) {
|
||||
return raw ? "0" : DateUtil.formatDateDiff(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
if (raw) {
|
||||
return String.valueOf(Instant.now().until(Instant.ofEpochMilli(time), ChronoUnit.MILLIS));
|
||||
} else {
|
||||
return DateUtil.formatDateDiff(time);
|
||||
}
|
||||
}
|
||||
|
||||
if (identifier.startsWith("has_kit_")) {
|
||||
Player oPlayer = player.getPlayer();
|
||||
if (oPlayer == null) return papiFalse;
|
||||
|
||||
String kit = identifier.split("has_kit_")[1];
|
||||
return oPlayer.hasPermission("essentials.kits." + kit) ? papiTrue : papiFalse;
|
||||
}
|
||||
|
||||
if (identifier.startsWith("home_")) {
|
||||
final User user = essentials.getUser(player.getUniqueId());
|
||||
|
||||
// Removes all the letters from the identifier to get the home slot.
|
||||
// Checks if the number slot is an integer or not.
|
||||
int prefix = "home_".length();
|
||||
int last_ = identifier.lastIndexOf("_");
|
||||
String homeName = identifier.substring(prefix, last_ <= prefix ? identifier.length() : last_);
|
||||
Integer homeNumber = Ints.tryParse(homeName);
|
||||
|
||||
// Since it is easier for users to type from 1-x I subtract one from the original number to work from 0-x.
|
||||
if (homeNumber != null) {
|
||||
--homeNumber;
|
||||
// checks if the home is out of bounds and returns and empty string if it is.
|
||||
if (homeNumber >= user.getHomes().size() || homeNumber < 0) return "";
|
||||
|
||||
// checks if the identifier matches the pattern home_%d
|
||||
if (identifier.equals("home_" + homeName)) return user.getHomes().get(homeNumber);
|
||||
}
|
||||
|
||||
final Location home = user.getHome(homeNumber == null ? homeName : user.getHomes().get(homeNumber));
|
||||
if (home == null) return "";
|
||||
|
||||
return switch (identifier.charAt(identifier.length() - 1)) {
|
||||
case 'w' -> home.getWorld().getName();
|
||||
case 'x' -> coordsFormat.format(home.getX());
|
||||
case 'y' -> coordsFormat.format(home.getY());
|
||||
case 'z' -> coordsFormat.format(home.getZ());
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
if (identifier.startsWith("worth")) {
|
||||
ItemStack item;
|
||||
|
||||
if (identifier.contains(":")){
|
||||
Material material = Material.getMaterial(identifier.replace("worth:", "").toUpperCase());
|
||||
|
||||
if (material == null) return "";
|
||||
item = new ItemStack(material,1);
|
||||
} else {
|
||||
Player oPlayer = player.getPlayer();
|
||||
if (oPlayer == null) return "";
|
||||
|
||||
if (oPlayer.getItemInHand().getType() == Material.AIR) return "";
|
||||
item = oPlayer.getItemInHand();
|
||||
}
|
||||
|
||||
BigDecimal worth = essentials.getWorth().getPrice(essentials, item);
|
||||
if (worth == null) return "";
|
||||
return String.valueOf(worth.doubleValue());
|
||||
}
|
||||
|
||||
final User user = essentials.getUser(player.getUniqueId());
|
||||
|
||||
switch (identifier) {
|
||||
case "is_clearinventory_confirm":
|
||||
return user.isPromptingClearConfirm() ? papiTrue : papiFalse;
|
||||
case "is_pay_confirm":
|
||||
return user.isPromptingPayConfirm() ? papiTrue : papiFalse;
|
||||
case "is_pay_enabled":
|
||||
return user.isAcceptingPay() ? papiTrue : papiFalse;
|
||||
case "is_teleport_enabled":
|
||||
return user.isTeleportEnabled() ? papiTrue : papiFalse;
|
||||
case "is_muted":
|
||||
return user.isMuted() ? papiTrue : papiFalse;
|
||||
case "vanished":
|
||||
return user.isVanished() ? papiTrue : papiFalse;
|
||||
case "afk":
|
||||
return user.isAfk() ? papiTrue : papiFalse;
|
||||
case "afk_reason":
|
||||
if (user.getAfkMessage() == null) return "";
|
||||
return ChatColor.translateAlternateColorCodes('&', user.getAfkMessage());
|
||||
case "afk_player_count":
|
||||
return String.valueOf(essentials.getUserMap().getAllUniqueUsers().stream()
|
||||
.map(UUID -> essentials.getUser(UUID)).filter(User::isAfk)
|
||||
.count());
|
||||
case "msg_ignore":
|
||||
return user.isIgnoreMsg() ? papiTrue : papiFalse;
|
||||
case "fly":
|
||||
return user.getBase().getAllowFlight() ? papiTrue : papiFalse;
|
||||
case "nickname":
|
||||
return user.getNickname() != null ? essentials.getUser(player.getUniqueId()).getNickname() : player.getName();
|
||||
case "nickname_stripped":
|
||||
return ChatColor.stripColor(user.getNickname() != null ? essentials.getUser(player.getUniqueId()).getNickname() : player.getName());
|
||||
case "muted_time_remaining":
|
||||
return user.isMuted() ? DateUtil.formatDateDiff(user.getMuteTimeout()) : "";
|
||||
case "geolocation":
|
||||
return user.getGeoLocation() != null ? user.getGeoLocation() : "";
|
||||
case "godmode":
|
||||
return user.isGodModeEnabled() ? papiTrue : papiFalse;
|
||||
case "unique":
|
||||
return NumberFormat.getInstance().format(essentials.getUserMap().getUniqueUsers());
|
||||
case "homes_set":
|
||||
return user.getHomes().isEmpty() ? "0" : String.valueOf(user.getHomes().size());
|
||||
case "homes_max":
|
||||
return String.valueOf(essentials.getSettings().getHomeLimit(user));
|
||||
case "jailed":
|
||||
return user.isJailed() ? papiTrue : papiFalse;
|
||||
case "jailed_time_remaining":
|
||||
return user.isJailed() ? user.getFormattedJailTime() : "";
|
||||
case "pm_recipient":
|
||||
return user.getReplyRecipient() != null ? user.getReplyRecipient().getName() : "";
|
||||
case "safe_online":
|
||||
return String.valueOf(StreamSupport.stream(essentials.getOnlineUsers().spliterator(), false)
|
||||
.filter(user1 -> !user1.isHidden())
|
||||
.count());
|
||||
case "world_date":
|
||||
return DateFormat.getDateInstance(DateFormat.MEDIUM, essentials.getI18n().getCurrentLocale())
|
||||
.format(DescParseTickFormat.ticksToDate(user.getWorld() == null ? 0 : user.getWorld().getFullTime()));
|
||||
case "world_time":
|
||||
return DescParseTickFormat.format12(user.getWorld() == null ? 0 : user.getWorld().getTime());
|
||||
case "world_time_24":
|
||||
return DescParseTickFormat.format24(user.getWorld() == null ? 0 : user.getWorld().getTime());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String format(double d) {
|
||||
NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH);
|
||||
format.setMaximumFractionDigits(2);
|
||||
format.setMinimumFractionDigits(0);
|
||||
return format.format(d);
|
||||
}
|
||||
|
||||
private String fixMoney(double d) {
|
||||
|
||||
if (d < 1000L) {
|
||||
return format(d);
|
||||
}
|
||||
if (d < 1000000L) {
|
||||
return format(d / 1000L) + k;
|
||||
}
|
||||
if (d < 1000000000L) {
|
||||
return format(d / 1000000L) + m;
|
||||
}
|
||||
if (d < 1000000000000L) {
|
||||
return format(d / 1000000000L) + b;
|
||||
}
|
||||
if (d < 1000000000000000L) {
|
||||
return format(d / 1000000000000L) + t;
|
||||
}
|
||||
if (d < 1000000000000000000L) {
|
||||
return format(d / 1000000000000000L) + q;
|
||||
}
|
||||
|
||||
return String.valueOf(d);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user