2011-04-07 04:21:10 +02:00
|
|
|
package com.earth2me.essentials;
|
|
|
|
|
2013-06-08 23:31:19 +02:00
|
|
|
import com.earth2me.essentials.utils.NumberUtil;
|
2013-10-11 04:44:41 +02:00
|
|
|
import com.earth2me.essentials.utils.StringUtil;
|
2016-06-28 04:40:47 +02:00
|
|
|
import com.google.common.collect.ImmutableMap;
|
2013-10-11 04:44:41 +02:00
|
|
|
import net.ess3.api.IEssentials;
|
2013-11-07 03:22:32 +01:00
|
|
|
import net.ess3.api.InvalidWorldException;
|
2014-02-02 17:07:32 +01:00
|
|
|
import net.ess3.api.MaxMoneyException;
|
2011-04-07 04:21:10 +02:00
|
|
|
import org.bukkit.Location;
|
2017-12-13 07:06:25 +01:00
|
|
|
import org.bukkit.Material;
|
2012-09-02 19:11:29 +02:00
|
|
|
import org.bukkit.configuration.ConfigurationSection;
|
2011-04-07 04:21:10 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.math.BigDecimal;
|
2020-10-03 19:46:05 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Map;
|
2016-06-28 04:40:47 +02:00
|
|
|
import java.util.Map.Entry;
|
2020-10-03 19:46:05 +02:00
|
|
|
import java.util.Set;
|
|
|
|
import java.util.UUID;
|
2016-06-28 04:40:47 +02:00
|
|
|
import java.util.regex.Pattern;
|
2019-10-05 07:24:01 +02:00
|
|
|
import java.util.stream.Collectors;
|
2015-04-15 06:06:16 +02:00
|
|
|
|
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
|
|
|
|
|
|
|
public abstract class UserData extends PlayerExtension implements IConf {
|
|
|
|
protected final transient IEssentials ess;
|
|
|
|
private final EssentialsUserConf config;
|
2020-10-03 19:46:05 +02:00
|
|
|
private BigDecimal money;
|
|
|
|
private Map<String, Object> homes;
|
|
|
|
private String nickname;
|
|
|
|
private Set<Material> unlimited;
|
|
|
|
private Map<String, Object> powertools;
|
|
|
|
private Location lastLocation;
|
|
|
|
private Location logoutLocation;
|
|
|
|
private long lastTeleportTimestamp;
|
|
|
|
private long lastHealTimestamp;
|
|
|
|
private String jail;
|
|
|
|
private List<String> mails;
|
|
|
|
private boolean teleportEnabled;
|
|
|
|
private boolean autoTeleportEnabled;
|
|
|
|
private List<UUID> ignoredPlayers;
|
|
|
|
private boolean godmode;
|
|
|
|
private boolean muted;
|
|
|
|
private String muteReason;
|
|
|
|
private long muteTimeout;
|
|
|
|
private boolean jailed;
|
|
|
|
private long jailTimeout;
|
|
|
|
private long lastLogin;
|
|
|
|
private long lastLogout;
|
|
|
|
private String lastLoginAddress;
|
|
|
|
private boolean afk;
|
|
|
|
private boolean newplayer;
|
|
|
|
private String geolocation;
|
|
|
|
private boolean isSocialSpyEnabled;
|
|
|
|
private boolean isNPC;
|
|
|
|
private String lastAccountName = null;
|
|
|
|
private boolean arePowerToolsEnabled;
|
|
|
|
private Map<String, Long> kitTimestamps;
|
|
|
|
// Pattern, Date. Pattern for less pattern creations
|
|
|
|
private Map<Pattern, Long> commandCooldowns;
|
|
|
|
private boolean acceptingPay = true; // players accept pay by default
|
|
|
|
private Boolean confirmPay;
|
|
|
|
private Boolean confirmClear;
|
|
|
|
private boolean lastMessageReplyRecipient;
|
2021-02-15 16:43:10 +01:00
|
|
|
private boolean baltopExemptCache;
|
2015-04-15 06:06:16 +02:00
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
protected UserData(final Player base, final IEssentials ess) {
|
2015-04-15 06:06:16 +02:00
|
|
|
super(base);
|
|
|
|
this.ess = ess;
|
2020-10-03 19:46:05 +02:00
|
|
|
final File folder = new File(ess.getDataFolder(), "userdata");
|
2015-04-15 06:06:16 +02:00
|
|
|
if (!folder.exists()) {
|
|
|
|
folder.mkdirs();
|
|
|
|
}
|
|
|
|
|
|
|
|
String filename;
|
|
|
|
try {
|
|
|
|
filename = base.getUniqueId().toString();
|
2020-10-03 19:46:05 +02:00
|
|
|
} catch (final Throwable ex) {
|
2015-04-15 06:06:16 +02:00
|
|
|
ess.getLogger().warning("Falling back to old username system for " + base.getName());
|
|
|
|
filename = base.getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
config = new EssentialsUserConf(base.getName(), base.getUniqueId(), new File(folder, filename + ".yml"));
|
|
|
|
reloadConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
public final void reset() {
|
|
|
|
config.forceSave();
|
|
|
|
config.getFile().delete();
|
|
|
|
if (config.username != null) {
|
|
|
|
ess.getUserMap().removeUser(config.username);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public final void cleanup() {
|
|
|
|
config.cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public final void reloadConfig() {
|
|
|
|
config.load();
|
|
|
|
money = _getMoney();
|
|
|
|
unlimited = _getUnlimited();
|
|
|
|
powertools = _getPowertools();
|
|
|
|
homes = _getHomes();
|
|
|
|
lastLocation = _getLastLocation();
|
|
|
|
lastTeleportTimestamp = _getLastTeleportTimestamp();
|
|
|
|
lastHealTimestamp = _getLastHealTimestamp();
|
|
|
|
jail = _getJail();
|
|
|
|
mails = _getMails();
|
|
|
|
teleportEnabled = _getTeleportEnabled();
|
|
|
|
godmode = _getGodModeEnabled();
|
|
|
|
muted = _getMuted();
|
|
|
|
muteTimeout = _getMuteTimeout();
|
2017-12-27 01:09:46 +01:00
|
|
|
muteReason = _getMuteReason();
|
2015-04-15 06:06:16 +02:00
|
|
|
jailed = _getJailed();
|
|
|
|
jailTimeout = _getJailTimeout();
|
2021-01-08 21:43:32 +01:00
|
|
|
onlineJailed = _getOnlineJailedTime();
|
2015-04-15 06:06:16 +02:00
|
|
|
lastLogin = _getLastLogin();
|
|
|
|
lastLogout = _getLastLogout();
|
|
|
|
lastLoginAddress = _getLastLoginAddress();
|
|
|
|
afk = _getAfk();
|
|
|
|
geolocation = _getGeoLocation();
|
|
|
|
isSocialSpyEnabled = _isSocialSpyEnabled();
|
|
|
|
isNPC = _isNPC();
|
|
|
|
arePowerToolsEnabled = _arePowerToolsEnabled();
|
|
|
|
kitTimestamps = _getKitTimestamps();
|
|
|
|
nickname = _getNickname();
|
|
|
|
ignoredPlayers = _getIgnoredPlayers();
|
|
|
|
logoutLocation = _getLogoutLocation();
|
|
|
|
lastAccountName = _getLastAccountName();
|
2016-06-28 04:40:47 +02:00
|
|
|
commandCooldowns = _getCommandCooldowns();
|
2016-07-26 17:23:34 +02:00
|
|
|
acceptingPay = _getAcceptingPay();
|
2016-12-25 19:08:16 +01:00
|
|
|
confirmPay = _getConfirmPay();
|
2017-11-12 17:44:53 +01:00
|
|
|
confirmClear = _getConfirmClear();
|
2019-03-10 00:39:45 +01:00
|
|
|
lastMessageReplyRecipient = _getLastMessageReplyRecipient();
|
2021-02-15 16:43:10 +01:00
|
|
|
baltopExemptCache = _getBaltopExcludeCache();
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private BigDecimal _getMoney() {
|
|
|
|
BigDecimal result = ess.getSettings().getStartingBalance();
|
2020-10-03 19:46:05 +02:00
|
|
|
final BigDecimal maxMoney = ess.getSettings().getMaxMoney();
|
|
|
|
final BigDecimal minMoney = ess.getSettings().getMinMoney();
|
2017-12-29 15:33:04 +01:00
|
|
|
|
2016-06-27 22:45:31 +02:00
|
|
|
// NPC banks are not actual player banks, as such they do not have player starting balance.
|
|
|
|
if (isNPC()) {
|
|
|
|
result = BigDecimal.ZERO;
|
|
|
|
}
|
2015-04-15 06:06:16 +02:00
|
|
|
|
|
|
|
if (config.hasProperty("money")) {
|
|
|
|
result = config.getBigDecimal("money", result);
|
|
|
|
}
|
|
|
|
if (result.compareTo(maxMoney) > 0) {
|
|
|
|
result = maxMoney;
|
|
|
|
}
|
|
|
|
if (result.compareTo(minMoney) < 0) {
|
|
|
|
result = minMoney;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public BigDecimal getMoney() {
|
|
|
|
return money;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setMoney(final BigDecimal value, final boolean throwError) throws MaxMoneyException {
|
|
|
|
final BigDecimal maxMoney = ess.getSettings().getMaxMoney();
|
|
|
|
final BigDecimal minMoney = ess.getSettings().getMinMoney();
|
2015-04-15 06:06:16 +02:00
|
|
|
if (value.compareTo(maxMoney) > 0) {
|
|
|
|
if (throwError) {
|
|
|
|
throw new MaxMoneyException();
|
|
|
|
}
|
|
|
|
money = maxMoney;
|
|
|
|
} else {
|
|
|
|
money = value;
|
|
|
|
}
|
|
|
|
if (money.compareTo(minMoney) < 0) {
|
|
|
|
money = minMoney;
|
|
|
|
}
|
|
|
|
config.setProperty("money", money);
|
|
|
|
stopTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Map<String, Object> _getHomes() {
|
|
|
|
if (config.isConfigurationSection("homes")) {
|
|
|
|
return config.getConfigurationSection("homes").getValues(false);
|
|
|
|
}
|
2020-04-25 14:08:57 +02:00
|
|
|
return new HashMap<>();
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private String getHomeName(String search) {
|
|
|
|
if (NumberUtil.isInt(search)) {
|
|
|
|
try {
|
|
|
|
search = getHomes().get(Integer.parseInt(search) - 1);
|
2020-10-03 19:46:05 +02:00
|
|
|
} catch (final NumberFormatException | IndexOutOfBoundsException ignored) {
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return search;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public Location getHome(final String name) throws Exception {
|
|
|
|
final String search = getHomeName(name);
|
2015-04-15 06:06:16 +02:00
|
|
|
return config.getLocation("homes." + search, this.getBase().getServer());
|
|
|
|
}
|
|
|
|
|
|
|
|
public Location getHome(final Location world) {
|
|
|
|
try {
|
|
|
|
if (getHomes().isEmpty()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
Location loc;
|
2020-10-03 19:46:05 +02:00
|
|
|
for (final String home : getHomes()) {
|
2015-04-15 06:06:16 +02:00
|
|
|
loc = config.getLocation("homes." + home, this.getBase().getServer());
|
|
|
|
if (world.getWorld() == loc.getWorld()) {
|
|
|
|
return loc;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
loc = config.getLocation("homes." + getHomes().get(0), this.getBase().getServer());
|
|
|
|
return loc;
|
2020-10-03 19:46:05 +02:00
|
|
|
} catch (final InvalidWorldException ex) {
|
2015-04-15 06:06:16 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<String> getHomes() {
|
2020-04-25 14:08:57 +02:00
|
|
|
return new ArrayList<>(homes.keySet());
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setHome(String name, final Location loc) {
|
2015-04-15 06:06:16 +02:00
|
|
|
//Invalid names will corrupt the yaml
|
|
|
|
name = StringUtil.safeString(name);
|
|
|
|
homes.put(name, loc);
|
|
|
|
config.setProperty("homes." + name, loc);
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void delHome(final String name) throws Exception {
|
2015-04-15 06:06:16 +02:00
|
|
|
String search = getHomeName(name);
|
|
|
|
if (!homes.containsKey(search)) {
|
|
|
|
search = StringUtil.safeString(search);
|
|
|
|
}
|
|
|
|
if (homes.containsKey(search)) {
|
|
|
|
homes.remove(search);
|
|
|
|
config.removeProperty("homes." + search);
|
|
|
|
config.save();
|
|
|
|
} else {
|
|
|
|
throw new Exception(tl("invalidHome", search));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasHome() {
|
2015-06-03 22:11:56 +02:00
|
|
|
return config.hasProperty("home");
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public boolean hasHome(final String name) {
|
2020-07-01 23:03:22 +02:00
|
|
|
return config.hasProperty("homes." + name);
|
|
|
|
}
|
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
public String _getNickname() {
|
|
|
|
return config.getString("nickname");
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getNickname() {
|
|
|
|
return nickname;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setNickname(final String nick) {
|
2015-04-15 06:06:16 +02:00
|
|
|
nickname = nick;
|
|
|
|
config.setProperty("nickname", nick);
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
2019-10-05 07:24:01 +02:00
|
|
|
private Set<Material> _getUnlimited() {
|
2020-10-03 19:46:05 +02:00
|
|
|
final Set<Material> retlist = new HashSet<>();
|
|
|
|
final List<String> configList = config.getStringList("unlimited");
|
|
|
|
for (final String s : configList) {
|
|
|
|
final Material mat = Material.matchMaterial(s);
|
|
|
|
if (mat != null) {
|
2017-12-13 07:06:25 +01:00
|
|
|
retlist.add(mat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return retlist;
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
|
2019-10-05 07:24:01 +02:00
|
|
|
public Set<Material> getUnlimited() {
|
2015-04-15 06:06:16 +02:00
|
|
|
return unlimited;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public boolean hasUnlimited(final ItemStack stack) {
|
2017-12-13 07:06:25 +01:00
|
|
|
return unlimited.contains(stack.getType());
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setUnlimited(final ItemStack stack, final boolean state) {
|
|
|
|
final boolean wasUpdated;
|
2015-04-15 06:06:16 +02:00
|
|
|
if (state) {
|
2019-10-05 07:24:01 +02:00
|
|
|
wasUpdated = unlimited.add(stack.getType());
|
|
|
|
} else {
|
|
|
|
wasUpdated = unlimited.remove(stack.getType());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wasUpdated) {
|
|
|
|
applyUnlimited();
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
2019-10-05 07:24:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void applyUnlimited() {
|
|
|
|
config.setProperty("unlimited", unlimited.stream().map(Enum::name).collect(Collectors.toList()));
|
2015-04-15 06:06:16 +02:00
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Map<String, Object> _getPowertools() {
|
|
|
|
if (config.isConfigurationSection("powertools")) {
|
|
|
|
return config.getConfigurationSection("powertools").getValues(false);
|
|
|
|
}
|
2017-12-13 07:06:25 +01:00
|
|
|
return new HashMap<>();
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void clearAllPowertools() {
|
|
|
|
powertools.clear();
|
|
|
|
config.setProperty("powertools", powertools);
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2020-10-03 19:46:05 +02:00
|
|
|
public List<String> getPowertool(final ItemStack stack) {
|
2017-12-13 07:06:25 +01:00
|
|
|
return (List<String>) powertools.get(stack.getType().name().toLowerCase(Locale.ENGLISH));
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2020-10-03 19:46:05 +02:00
|
|
|
public List<String> getPowertool(final Material material) {
|
2017-12-13 07:06:25 +01:00
|
|
|
return (List<String>) powertools.get(material.name().toLowerCase(Locale.ENGLISH));
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setPowertool(final ItemStack stack, final List<String> commandList) {
|
2015-04-15 06:06:16 +02:00
|
|
|
if (commandList == null || commandList.isEmpty()) {
|
2017-12-13 07:06:25 +01:00
|
|
|
powertools.remove(stack.getType().name().toLowerCase(Locale.ENGLISH));
|
2015-04-15 06:06:16 +02:00
|
|
|
} else {
|
2017-12-13 07:06:25 +01:00
|
|
|
powertools.put(stack.getType().name().toLowerCase(Locale.ENGLISH), commandList);
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
config.setProperty("powertools", powertools);
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasPowerTools() {
|
|
|
|
return !powertools.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Location _getLastLocation() {
|
|
|
|
try {
|
|
|
|
return config.getLocation("lastlocation", this.getBase().getServer());
|
2020-10-03 19:46:05 +02:00
|
|
|
} catch (final InvalidWorldException e) {
|
2015-04-15 06:06:16 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Location getLastLocation() {
|
|
|
|
return lastLocation;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setLastLocation(final Location loc) {
|
2015-04-15 06:06:16 +02:00
|
|
|
if (loc == null || loc.getWorld() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastLocation = loc;
|
|
|
|
config.setProperty("lastlocation", loc);
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Location _getLogoutLocation() {
|
|
|
|
try {
|
|
|
|
return config.getLocation("logoutlocation", this.getBase().getServer());
|
2020-10-03 19:46:05 +02:00
|
|
|
} catch (final InvalidWorldException e) {
|
2015-04-15 06:06:16 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Location getLogoutLocation() {
|
|
|
|
return logoutLocation;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setLogoutLocation(final Location loc) {
|
2015-04-15 06:06:16 +02:00
|
|
|
if (loc == null || loc.getWorld() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
logoutLocation = loc;
|
|
|
|
config.setProperty("logoutlocation", loc);
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
private long _getLastTeleportTimestamp() {
|
|
|
|
return config.getLong("timestamps.lastteleport", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getLastTeleportTimestamp() {
|
|
|
|
return lastTeleportTimestamp;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setLastTeleportTimestamp(final long time) {
|
2015-04-15 06:06:16 +02:00
|
|
|
lastTeleportTimestamp = time;
|
|
|
|
config.setProperty("timestamps.lastteleport", time);
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
private long _getLastHealTimestamp() {
|
|
|
|
return config.getLong("timestamps.lastheal", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getLastHealTimestamp() {
|
|
|
|
return lastHealTimestamp;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setLastHealTimestamp(final long time) {
|
2015-04-15 06:06:16 +02:00
|
|
|
lastHealTimestamp = time;
|
|
|
|
config.setProperty("timestamps.lastheal", time);
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
private String _getJail() {
|
|
|
|
return config.getString("jail");
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getJail() {
|
|
|
|
return jail;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setJail(final String jail) {
|
2015-04-15 06:06:16 +02:00
|
|
|
if (jail == null || jail.isEmpty()) {
|
|
|
|
this.jail = null;
|
|
|
|
config.removeProperty("jail");
|
|
|
|
} else {
|
|
|
|
this.jail = jail;
|
|
|
|
config.setProperty("jail", jail);
|
|
|
|
}
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<String> _getMails() {
|
|
|
|
return config.getStringList("mail");
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<String> getMails() {
|
|
|
|
return mails;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMails(List<String> mails) {
|
|
|
|
if (mails == null) {
|
|
|
|
config.removeProperty("mail");
|
|
|
|
mails = _getMails();
|
|
|
|
} else {
|
|
|
|
config.setProperty("mail", mails);
|
|
|
|
}
|
|
|
|
this.mails = mails;
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void addMail(final String mail) {
|
2015-04-15 06:06:16 +02:00
|
|
|
mails.add(mail);
|
|
|
|
setMails(mails);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean _getTeleportEnabled() {
|
|
|
|
return config.getBoolean("teleportenabled", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isTeleportEnabled() {
|
|
|
|
return teleportEnabled;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setTeleportEnabled(final boolean set) {
|
2015-04-15 06:06:16 +02:00
|
|
|
teleportEnabled = set;
|
|
|
|
config.setProperty("teleportenabled", set);
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
2018-12-19 11:50:30 +01:00
|
|
|
private boolean _getAutoTeleportEnabled() {
|
2018-12-21 10:58:44 +01:00
|
|
|
return config.getBoolean("teleportauto", false);
|
2018-12-19 11:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isAutoTeleportEnabled() {
|
|
|
|
return autoTeleportEnabled;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setAutoTeleportEnabled(final boolean set) {
|
2018-12-19 11:50:30 +01:00
|
|
|
autoTeleportEnabled = set;
|
2018-12-21 10:58:44 +01:00
|
|
|
config.setProperty("teleportauto", set);
|
2018-12-19 11:50:30 +01:00
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
2020-05-04 12:06:09 +02:00
|
|
|
public List<UUID> _getIgnoredPlayers() {
|
2020-10-03 19:46:05 +02:00
|
|
|
final List<UUID> players = new ArrayList<>();
|
|
|
|
for (final String uuid : config.getStringList("ignore")) {
|
2020-05-04 12:06:09 +02:00
|
|
|
try {
|
|
|
|
players.add(UUID.fromString(uuid));
|
2020-10-03 19:46:05 +02:00
|
|
|
} catch (final IllegalArgumentException ignored) {
|
|
|
|
}
|
2020-05-04 12:06:09 +02:00
|
|
|
}
|
|
|
|
return Collections.synchronizedList(players);
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
|
2020-05-04 12:06:09 +02:00
|
|
|
@Deprecated
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setIgnoredPlayers(final List<String> players) {
|
|
|
|
final List<UUID> uuids = new ArrayList<>();
|
|
|
|
for (final String player : players) {
|
|
|
|
final User user = ess.getOfflineUser(player);
|
2020-05-04 12:06:09 +02:00
|
|
|
if (user == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uuids.add(user.getBase().getUniqueId());
|
|
|
|
}
|
|
|
|
setIgnoredPlayerUUIDs(uuids);
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setIgnoredPlayerUUIDs(final List<UUID> players) {
|
2015-04-15 06:06:16 +02:00
|
|
|
if (players == null || players.isEmpty()) {
|
2020-04-25 14:08:57 +02:00
|
|
|
ignoredPlayers = Collections.synchronizedList(new ArrayList<>());
|
2015-04-15 06:06:16 +02:00
|
|
|
config.removeProperty("ignore");
|
|
|
|
} else {
|
|
|
|
ignoredPlayers = players;
|
2020-10-03 19:46:05 +02:00
|
|
|
final List<String> uuids = new ArrayList<>();
|
|
|
|
for (final UUID uuid : players) {
|
2020-05-04 12:06:09 +02:00
|
|
|
uuids.add(uuid.toString());
|
|
|
|
}
|
|
|
|
config.setProperty("ignore", uuids);
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
public boolean isIgnoredPlayer(final String userName) {
|
|
|
|
final IUser user = ess.getUser(userName);
|
|
|
|
if (user == null || !user.getBase().isOnline()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return isIgnoredPlayer(user);
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public boolean isIgnoredPlayer(final IUser user) {
|
2020-05-04 12:06:09 +02:00
|
|
|
return ignoredPlayers.contains(user.getBase().getUniqueId()) && !user.isIgnoreExempt();
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setIgnoredPlayer(final IUser user, final boolean set) {
|
|
|
|
final UUID uuid = user.getBase().getUniqueId();
|
2015-04-15 06:06:16 +02:00
|
|
|
if (set) {
|
2020-05-04 12:06:09 +02:00
|
|
|
if (!ignoredPlayers.contains(uuid)) {
|
|
|
|
ignoredPlayers.add(uuid);
|
|
|
|
}
|
2015-04-15 06:06:16 +02:00
|
|
|
} else {
|
2020-05-04 12:06:09 +02:00
|
|
|
ignoredPlayers.remove(uuid);
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
2020-05-04 12:06:09 +02:00
|
|
|
setIgnoredPlayerUUIDs(ignoredPlayers);
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean _getGodModeEnabled() {
|
|
|
|
return config.getBoolean("godmode", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isGodModeEnabled() {
|
|
|
|
return godmode;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setGodModeEnabled(final boolean set) {
|
2015-04-15 06:06:16 +02:00
|
|
|
godmode = set;
|
|
|
|
config.setProperty("godmode", set);
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean _getMuted() {
|
|
|
|
return config.getBoolean("muted", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getMuted() {
|
|
|
|
return muted;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isMuted() {
|
|
|
|
return muted;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setMuted(final boolean set) {
|
2015-04-15 06:06:16 +02:00
|
|
|
muted = set;
|
|
|
|
config.setProperty("muted", set);
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
2017-09-03 05:04:16 +02:00
|
|
|
public String _getMuteReason() {
|
|
|
|
return config.getString("muteReason");
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getMuteReason() {
|
2017-12-27 01:09:46 +01:00
|
|
|
return muteReason;
|
2017-09-03 05:04:16 +02:00
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setMuteReason(final String reason) {
|
2017-12-27 01:09:46 +01:00
|
|
|
if (reason == null) {
|
|
|
|
config.removeProperty("muteReason");
|
2017-09-04 06:13:00 +02:00
|
|
|
muteReason = null;
|
2017-09-03 23:41:32 +02:00
|
|
|
} else {
|
|
|
|
muteReason = reason;
|
2017-12-27 01:09:46 +01:00
|
|
|
config.setProperty("muteReason", reason);
|
2017-09-03 23:41:32 +02:00
|
|
|
}
|
2017-09-03 05:04:16 +02:00
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public boolean hasMuteReason() {
|
2017-12-27 01:09:46 +01:00
|
|
|
return muteReason != null;
|
2017-12-03 02:46:46 +01:00
|
|
|
}
|
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
private long _getMuteTimeout() {
|
|
|
|
return config.getLong("timestamps.mute", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getMuteTimeout() {
|
|
|
|
return muteTimeout;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setMuteTimeout(final long time) {
|
2015-04-15 06:06:16 +02:00
|
|
|
muteTimeout = time;
|
|
|
|
config.setProperty("timestamps.mute", time);
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean _getJailed() {
|
|
|
|
return config.getBoolean("jailed", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isJailed() {
|
|
|
|
return jailed;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setJailed(final boolean set) {
|
2015-04-15 06:06:16 +02:00
|
|
|
jailed = set;
|
|
|
|
config.setProperty("jailed", set);
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean toggleJailed() {
|
2020-10-03 19:46:05 +02:00
|
|
|
final boolean ret = !isJailed();
|
2015-04-15 06:06:16 +02:00
|
|
|
setJailed(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
private long _getJailTimeout() {
|
|
|
|
return config.getLong("timestamps.jail", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getJailTimeout() {
|
|
|
|
return jailTimeout;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setJailTimeout(final long time) {
|
2015-04-15 06:06:16 +02:00
|
|
|
jailTimeout = time;
|
|
|
|
config.setProperty("timestamps.jail", time);
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
2021-01-08 21:43:32 +01:00
|
|
|
private long onlineJailed;
|
|
|
|
|
|
|
|
private long _getOnlineJailedTime() {
|
|
|
|
return config.getLong("timestamps.onlinejail", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getOnlineJailedTime() {
|
|
|
|
return onlineJailed;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOnlineJailedTime(long onlineJailed) {
|
|
|
|
this.onlineJailed = onlineJailed;
|
|
|
|
config.setProperty("timestamps.onlinejail", onlineJailed);
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
private long _getLastLogin() {
|
|
|
|
return config.getLong("timestamps.login", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getLastLogin() {
|
|
|
|
return lastLogin;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setLastLogin(final long time) {
|
2015-04-15 06:06:16 +02:00
|
|
|
_setLastLogin(time);
|
|
|
|
if (base.getAddress() != null && base.getAddress().getAddress() != null) {
|
|
|
|
_setLastLoginAddress(base.getAddress().getAddress().getHostAddress());
|
|
|
|
}
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
private void _setLastLogin(final long time) {
|
|
|
|
lastLogin = time;
|
|
|
|
config.setProperty("timestamps.login", time);
|
|
|
|
}
|
2015-04-15 06:06:16 +02:00
|
|
|
|
|
|
|
private long _getLastLogout() {
|
|
|
|
return config.getLong("timestamps.logout", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getLastLogout() {
|
|
|
|
return lastLogout;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setLastLogout(final long time) {
|
2015-04-15 06:06:16 +02:00
|
|
|
lastLogout = time;
|
|
|
|
config.setProperty("timestamps.logout", time);
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
private String _getLastLoginAddress() {
|
|
|
|
return config.getString("ipAddress", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getLastLoginAddress() {
|
|
|
|
return lastLoginAddress;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
private void _setLastLoginAddress(final String address) {
|
2015-04-15 06:06:16 +02:00
|
|
|
lastLoginAddress = address;
|
|
|
|
config.setProperty("ipAddress", address);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean _getAfk() {
|
|
|
|
return config.getBoolean("afk", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isAfk() {
|
|
|
|
return afk;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void _setAfk(final boolean set) {
|
2015-04-15 06:06:16 +02:00
|
|
|
afk = set;
|
|
|
|
config.setProperty("afk", set);
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
private String _getGeoLocation() {
|
|
|
|
return config.getString("geolocation");
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getGeoLocation() {
|
|
|
|
return geolocation;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setGeoLocation(final String geolocation) {
|
2015-04-15 06:06:16 +02:00
|
|
|
if (geolocation == null || geolocation.isEmpty()) {
|
|
|
|
this.geolocation = null;
|
|
|
|
config.removeProperty("geolocation");
|
|
|
|
} else {
|
|
|
|
this.geolocation = geolocation;
|
|
|
|
config.setProperty("geolocation", geolocation);
|
|
|
|
}
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean _isSocialSpyEnabled() {
|
|
|
|
return config.getBoolean("socialspy", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isSocialSpyEnabled() {
|
|
|
|
return isSocialSpyEnabled;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setSocialSpyEnabled(final boolean status) {
|
2015-04-15 06:06:16 +02:00
|
|
|
isSocialSpyEnabled = status;
|
|
|
|
config.setProperty("socialspy", status);
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean _isNPC() {
|
|
|
|
return config.getBoolean("npc", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isNPC() {
|
|
|
|
return isNPC;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setNPC(final boolean set) {
|
|
|
|
isNPC = set;
|
|
|
|
config.setProperty("npc", set);
|
|
|
|
config.save();
|
|
|
|
}
|
2015-04-15 06:06:16 +02:00
|
|
|
|
|
|
|
public String getLastAccountName() {
|
|
|
|
return lastAccountName;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setLastAccountName(final String lastAccountName) {
|
2015-04-15 06:06:16 +02:00
|
|
|
this.lastAccountName = lastAccountName;
|
|
|
|
config.setProperty("lastAccountName", lastAccountName);
|
|
|
|
config.save();
|
|
|
|
ess.getUserMap().trackUUID(getConfigUUID(), lastAccountName, true);
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public String _getLastAccountName() {
|
|
|
|
return config.getString("lastAccountName", null);
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean arePowerToolsEnabled() {
|
|
|
|
return arePowerToolsEnabled;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setPowerToolsEnabled(final boolean set) {
|
2015-04-15 06:06:16 +02:00
|
|
|
arePowerToolsEnabled = set;
|
|
|
|
config.setProperty("powertoolsenabled", set);
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean togglePowerToolsEnabled() {
|
2020-10-03 19:46:05 +02:00
|
|
|
final boolean ret = !arePowerToolsEnabled();
|
2015-04-15 06:06:16 +02:00
|
|
|
setPowerToolsEnabled(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean _arePowerToolsEnabled() {
|
|
|
|
return config.getBoolean("powertoolsenabled", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private Map<String, Long> _getKitTimestamps() {
|
|
|
|
|
|
|
|
if (config.isConfigurationSection("timestamps.kits")) {
|
|
|
|
final ConfigurationSection section = config.getConfigurationSection("timestamps.kits");
|
2020-04-25 14:08:57 +02:00
|
|
|
final Map<String, Long> timestamps = new HashMap<>();
|
2020-10-03 19:46:05 +02:00
|
|
|
for (final String command : section.getKeys(false)) {
|
2015-04-15 06:06:16 +02:00
|
|
|
if (section.isLong(command)) {
|
|
|
|
timestamps.put(command.toLowerCase(Locale.ENGLISH), section.getLong(command));
|
|
|
|
} else if (section.isInt(command)) {
|
|
|
|
timestamps.put(command.toLowerCase(Locale.ENGLISH), (long) section.getInt(command));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return timestamps;
|
|
|
|
}
|
2020-04-25 14:08:57 +02:00
|
|
|
return new HashMap<>();
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public long getKitTimestamp(String name) {
|
2019-06-26 13:54:00 +02:00
|
|
|
name = name.replace('.', '_').replace('/', '_').toLowerCase(Locale.ENGLISH);
|
2015-04-15 06:06:16 +02:00
|
|
|
if (kitTimestamps != null && kitTimestamps.containsKey(name)) {
|
|
|
|
return kitTimestamps.get(name);
|
|
|
|
}
|
2019-06-26 13:54:00 +02:00
|
|
|
return 0L;
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
|
2019-06-26 13:54:00 +02:00
|
|
|
public void setKitTimestamp(String name, final long time) {
|
|
|
|
name = name.replace('.', '_').replace('/', '_').toLowerCase(Locale.ENGLISH);
|
|
|
|
kitTimestamps.put(name, time);
|
2015-04-15 06:06:16 +02:00
|
|
|
config.setProperty("timestamps.kits", kitTimestamps);
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setConfigProperty(String node, final Object object) {
|
2015-04-15 06:06:16 +02:00
|
|
|
final String prefix = "info.";
|
|
|
|
node = prefix + node;
|
|
|
|
if (object instanceof Map) {
|
|
|
|
config.setProperty(node, (Map) object);
|
|
|
|
} else if (object instanceof List) {
|
|
|
|
config.setProperty(node, (List<String>) object);
|
|
|
|
} else if (object instanceof Location) {
|
|
|
|
config.setProperty(node, (Location) object);
|
|
|
|
} else if (object instanceof ItemStack) {
|
|
|
|
config.setProperty(node, (ItemStack) object);
|
|
|
|
} else {
|
|
|
|
config.setProperty(node, object);
|
|
|
|
}
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Set<String> getConfigKeys() {
|
|
|
|
if (config.isConfigurationSection("info")) {
|
|
|
|
return config.getConfigurationSection("info").getKeys(true);
|
|
|
|
}
|
2020-04-25 14:08:57 +02:00
|
|
|
return new HashSet<>();
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public Map<String, Object> getConfigMap() {
|
|
|
|
if (config.isConfigurationSection("info")) {
|
|
|
|
return config.getConfigurationSection("info").getValues(true);
|
|
|
|
}
|
2020-04-25 14:08:57 +02:00
|
|
|
return new HashMap<>();
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public Map<String, Object> getConfigMap(final String node) {
|
2015-04-15 06:06:16 +02:00
|
|
|
if (config.isConfigurationSection("info." + node)) {
|
|
|
|
return config.getConfigurationSection("info." + node).getValues(true);
|
|
|
|
}
|
2020-04-25 14:08:57 +02:00
|
|
|
return new HashMap<>();
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
|
2016-06-28 04:40:47 +02:00
|
|
|
private Map<Pattern, Long> _getCommandCooldowns() {
|
2019-12-18 22:02:37 +01:00
|
|
|
if (!config.contains("timestamps.command-cooldowns")) {
|
2016-06-28 04:40:47 +02:00
|
|
|
return null;
|
|
|
|
}
|
2017-12-29 15:33:04 +01:00
|
|
|
|
2016-06-28 04:40:47 +02:00
|
|
|
// See saveCommandCooldowns() for deserialization explanation
|
2020-10-03 19:46:05 +02:00
|
|
|
final List<Map<?, ?>> section = config.getMapList("timestamps.command-cooldowns");
|
|
|
|
final HashMap<Pattern, Long> result = new HashMap<>();
|
|
|
|
for (final Map<?, ?> map : section) {
|
|
|
|
final Pattern pattern = Pattern.compile(map.get("pattern").toString());
|
|
|
|
final long expiry = ((Number) map.get("expiry")).longValue();
|
2016-06-28 04:40:47 +02:00
|
|
|
result.put(pattern, expiry);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Map<Pattern, Long> getCommandCooldowns() {
|
|
|
|
if (this.commandCooldowns == null) {
|
|
|
|
return Collections.emptyMap();
|
|
|
|
}
|
|
|
|
return Collections.unmodifiableMap(this.commandCooldowns);
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public Date getCommandCooldownExpiry(final String label) {
|
2016-06-28 04:40:47 +02:00
|
|
|
if (commandCooldowns != null) {
|
2020-10-03 19:46:05 +02:00
|
|
|
for (final Entry<Pattern, Long> entry : this.commandCooldowns.entrySet()) {
|
2016-06-28 04:40:47 +02:00
|
|
|
if (entry.getKey().matcher(label).matches()) {
|
|
|
|
return new Date(entry.getValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void addCommandCooldown(final Pattern pattern, final Date expiresAt, final boolean save) {
|
2016-06-28 04:40:47 +02:00
|
|
|
if (this.commandCooldowns == null) {
|
|
|
|
this.commandCooldowns = new HashMap<>();
|
|
|
|
}
|
|
|
|
this.commandCooldowns.put(pattern, expiresAt.getTime());
|
|
|
|
if (save) {
|
|
|
|
saveCommandCooldowns();
|
|
|
|
}
|
|
|
|
}
|
2017-12-29 15:33:04 +01:00
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public boolean clearCommandCooldown(final Pattern pattern) {
|
2016-06-28 04:40:47 +02:00
|
|
|
if (this.commandCooldowns == null) {
|
|
|
|
return false; // false for no modification
|
|
|
|
}
|
2017-12-29 15:33:04 +01:00
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
if (this.commandCooldowns.remove(pattern) != null) {
|
2016-06-28 04:40:47 +02:00
|
|
|
saveCommandCooldowns();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2017-12-29 15:33:04 +01:00
|
|
|
|
2016-06-28 04:40:47 +02:00
|
|
|
private void saveCommandCooldowns() {
|
|
|
|
// Serialization explanation:
|
|
|
|
//
|
|
|
|
// Serialization is done as a map list instead of a config section due to limitations.
|
|
|
|
// When serializing patterns (which commonly include full stops .) Bukkit/Essentials config framework
|
|
|
|
// interprets it as a path separator, thus it breaks up the regex into sub nodes causing invalid syntax.
|
|
|
|
// Thus each command cooldown is instead stored as a Map of {pattern: .., expiry: ..} to work around this.
|
2020-10-03 19:46:05 +02:00
|
|
|
final List<Object> serialized = new ArrayList<>();
|
|
|
|
for (final Entry<Pattern, Long> entry : this.commandCooldowns.entrySet()) {
|
2016-06-28 04:40:47 +02:00
|
|
|
// Don't save expired cooldowns
|
|
|
|
if (entry.getValue() < System.currentTimeMillis()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
final Map<?, ?> map = ImmutableMap.builder()
|
2016-06-28 04:40:47 +02:00
|
|
|
.put("pattern", entry.getKey().pattern())
|
|
|
|
.put("expiry", entry.getValue())
|
|
|
|
.build();
|
|
|
|
serialized.add(map);
|
|
|
|
}
|
|
|
|
config.setProperty("timestamps.command-cooldowns", serialized);
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
|
2016-07-26 17:23:34 +02:00
|
|
|
public boolean _getAcceptingPay() {
|
|
|
|
return config.getBoolean("acceptingPay", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isAcceptingPay() {
|
|
|
|
return acceptingPay;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setAcceptingPay(final boolean acceptingPay) {
|
2016-07-26 17:23:34 +02:00
|
|
|
this.acceptingPay = acceptingPay;
|
|
|
|
config.setProperty("acceptingPay", acceptingPay);
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
|
2018-01-28 17:47:17 +01:00
|
|
|
private Boolean _getConfirmPay() {
|
|
|
|
return (Boolean) config.get("confirm-pay");
|
2016-12-25 19:08:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isPromptingPayConfirm() {
|
2018-01-28 17:47:17 +01:00
|
|
|
return confirmPay != null ? confirmPay : ess.getSettings().isConfirmCommandEnabledByDefault("pay");
|
2016-12-25 19:08:16 +01:00
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setPromptingPayConfirm(final boolean prompt) {
|
2016-12-25 19:08:16 +01:00
|
|
|
this.confirmPay = prompt;
|
|
|
|
config.setProperty("confirm-pay", prompt);
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
|
2018-01-28 17:47:17 +01:00
|
|
|
private Boolean _getConfirmClear() {
|
|
|
|
return (Boolean) config.get("confirm-clear");
|
2017-11-12 17:44:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isPromptingClearConfirm() {
|
2018-01-28 17:47:17 +01:00
|
|
|
return confirmClear != null ? confirmClear : ess.getSettings().isConfirmCommandEnabledByDefault("clearinventory");
|
2017-11-12 17:44:53 +01:00
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setPromptingClearConfirm(final boolean prompt) {
|
2017-11-12 17:44:53 +01:00
|
|
|
this.confirmClear = prompt;
|
|
|
|
config.setProperty("confirm-clear", prompt);
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
|
2019-03-10 00:39:45 +01:00
|
|
|
private boolean _getLastMessageReplyRecipient() {
|
|
|
|
return config.getBoolean("last-message-reply-recipient", ess.getSettings().isLastMessageReplyRecipient());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isLastMessageReplyRecipient() {
|
|
|
|
return this.lastMessageReplyRecipient;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
public void setLastMessageReplyRecipient(final boolean enabled) {
|
2019-03-10 00:39:45 +01:00
|
|
|
this.lastMessageReplyRecipient = enabled;
|
|
|
|
config.setProperty("last-message-reply-recipient", enabled);
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
|
2021-02-15 16:43:10 +01:00
|
|
|
public boolean _getBaltopExcludeCache() {
|
|
|
|
return config.getBoolean("baltop-exempt", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isBaltopExcludeCache() {
|
|
|
|
return baltopExemptCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setBaltopExemptCache(boolean baltopExempt) {
|
|
|
|
this.baltopExemptCache = baltopExempt;
|
|
|
|
config.setProperty("baltop-exempt", baltopExempt);
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
public UUID getConfigUUID() {
|
|
|
|
return config.uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void save() {
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void startTransaction() {
|
|
|
|
config.startTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void stopTransaction() {
|
|
|
|
config.stopTransaction();
|
|
|
|
}
|
2011-04-07 04:21:10 +02:00
|
|
|
}
|