2011-04-07 04:21:10 +02:00
package com.earth2me.essentials ;
2021-06-07 14:49:33 +02:00
import com.earth2me.essentials.config.ConfigurateUtil ;
import com.earth2me.essentials.config.EssentialsUserConfiguration ;
import com.earth2me.essentials.config.entities.CommandCooldown ;
2021-06-07 21:52:12 +02:00
import com.earth2me.essentials.config.entities.LazyLocation ;
2021-06-07 14:49:33 +02:00
import com.earth2me.essentials.config.holders.UserConfigHolder ;
2022-09-04 16:42:43 +02:00
import com.earth2me.essentials.userstorage.ModernUserMap ;
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 ;
2021-06-01 21:47:39 +02:00
import com.google.common.base.Charsets ;
2013-10-11 04:44:41 +02:00
import net.ess3.api.IEssentials ;
2014-02-02 17:07:32 +01:00
import net.ess3.api.MaxMoneyException ;
2021-07-01 17:23:32 +02:00
import net.essentialsx.api.v2.services.mail.MailMessage ;
import org.bukkit.ChatColor ;
2011-04-07 04:21:10 +02:00
import org.bukkit.Location ;
2017-12-13 07:06:25 +01:00
import org.bukkit.Material ;
2011-04-07 04:21:10 +02:00
import org.bukkit.entity.Player ;
import org.bukkit.inventory.ItemStack ;
2021-06-07 14:49:33 +02:00
import org.spongepowered.configurate.serialize.SerializationException ;
2011-04-07 04:21:10 +02:00
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.Date ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Locale ;
import java.util.Map ;
import java.util.Set ;
import java.util.UUID ;
2021-06-07 14:49:33 +02:00
import java.util.logging.Level ;
2016-06-28 04:40:47 +02:00
import java.util.regex.Pattern ;
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 ;
2021-06-07 14:49:33 +02:00
private final EssentialsUserConfiguration config ;
private UserConfigHolder holder ;
2020-10-03 19:46:05 +02:00
private BigDecimal money ;
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 " ) ;
2022-09-04 16:42:43 +02:00
if ( ! folder . exists ( ) & & ! folder . mkdirs ( ) ) {
throw new RuntimeException ( " Unable to create userdata folder! " ) ;
2015-04-15 06:06:16 +02:00
}
2022-09-04 16:42:43 +02:00
config = new EssentialsUserConfiguration ( base . getName ( ) , base . getUniqueId ( ) , new File ( folder , base . getUniqueId ( ) + " .yml " ) ) ;
config . setSaveHook ( ( ) - > {
config . setRootHolder ( UserConfigHolder . class , holder ) ;
} ) ;
2015-04-15 06:06:16 +02:00
reloadConfig ( ) ;
2021-06-01 21:47:39 +02:00
2021-06-07 14:49:33 +02:00
if ( config . getUsername ( ) = = null ) {
2021-06-01 21:47:39 +02:00
config . setUsername ( getLastAccountName ( ) ) ;
}
2015-04-15 06:06:16 +02:00
}
public final void reset ( ) {
2021-06-07 14:49:33 +02:00
config . blockingSave ( ) ;
2022-09-04 16:42:43 +02:00
if ( ! config . getFile ( ) . delete ( ) ) {
ess . getLogger ( ) . warning ( " Unable to delete data file for " + config . getFile ( ) . getName ( ) ) ;
}
2021-06-07 14:49:33 +02:00
if ( config . getUsername ( ) ! = null ) {
2022-09-04 16:42:43 +02:00
final ModernUserMap users = ( ModernUserMap ) ess . getUsers ( ) ;
users . invalidate ( config . getUuid ( ) ) ;
2021-06-01 21:47:39 +02:00
if ( isNPC ( ) ) {
2022-09-04 16:42:43 +02:00
final String name = ess . getSettings ( ) . isSafeUsermap ( ) ? StringUtil . safeString ( config . getUsername ( ) ) : config . getUsername ( ) ;
users . invalidate ( UUID . nameUUIDFromBytes ( ( " NPC: " + name ) . getBytes ( Charsets . UTF_8 ) ) ) ;
2021-06-01 21:47:39 +02:00
}
2015-04-15 06:06:16 +02:00
}
}
public final void cleanup ( ) {
2021-06-07 14:49:33 +02:00
config . blockingSave ( ) ;
2015-04-15 06:06:16 +02:00
}
@Override
public final void reloadConfig ( ) {
config . load ( ) ;
2021-06-07 14:49:33 +02:00
try {
holder = config . getRootNode ( ) . get ( UserConfigHolder . class ) ;
} catch ( SerializationException e ) {
2022-06-22 00:01:25 +02:00
ess . getLogger ( ) . log ( Level . SEVERE , " Error while reading user config: " + config . getFile ( ) . getName ( ) , e ) ;
2021-06-07 14:49:33 +02:00
throw new RuntimeException ( e ) ;
}
2015-04-15 06:06:16 +02:00
money = _getMoney ( ) ;
}
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
2021-06-07 14:49:33 +02:00
if ( holder . money ( ) ! = null ) {
result = holder . money ( ) ;
2015-04-15 06:06:16 +02:00
}
if ( result . compareTo ( maxMoney ) > 0 ) {
result = maxMoney ;
}
if ( result . compareTo ( minMoney ) < 0 ) {
result = minMoney ;
}
2021-06-07 14:49:33 +02:00
holder . money ( result ) ;
return holder . money ( ) ;
2015-04-15 06:06:16 +02:00
}
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 ;
}
2021-06-07 14:49:33 +02:00
holder . money ( money ) ;
2015-04-15 06:06:16 +02:00
stopTransaction ( ) ;
}
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 ;
}
2021-06-17 21:28:07 +02:00
public Location getHome ( final String name ) {
2020-10-03 19:46:05 +02:00
final String search = getHomeName ( name ) ;
2021-06-14 13:28:42 +02:00
final LazyLocation loc = holder . homes ( ) . get ( search ) ;
return loc ! = null ? loc . location ( ) : null ;
2015-04-15 06:06:16 +02:00
}
2021-08-02 17:23:40 +02:00
public boolean hasValidHomes ( ) {
for ( final LazyLocation loc : holder . homes ( ) . values ( ) ) {
if ( loc ! = null & & loc . location ( ) ! = null ) {
return true ;
}
}
return false ;
}
2015-04-15 06:06:16 +02:00
public Location getHome ( final Location world ) {
2021-06-07 14:49:33 +02:00
if ( getHomes ( ) . isEmpty ( ) ) {
return null ;
}
for ( final String home : getHomes ( ) ) {
2021-06-07 21:52:12 +02:00
final Location loc = holder . homes ( ) . get ( home ) . location ( ) ;
if ( loc ! = null & & world . getWorld ( ) = = loc . getWorld ( ) ) {
2021-06-07 14:49:33 +02:00
return loc ;
2015-04-15 06:06:16 +02:00
}
}
2021-06-07 21:52:12 +02:00
return holder . homes ( ) . get ( getHomes ( ) . get ( 0 ) ) . location ( ) ;
2015-04-15 06:06:16 +02:00
}
public List < String > getHomes ( ) {
2021-06-07 14:49:33 +02:00
return new ArrayList < > ( holder . 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 ) ;
2021-06-07 21:52:12 +02:00
holder . homes ( ) . put ( name , LazyLocation . fromLocation ( loc ) ) ;
2015-04-15 06:06:16 +02:00
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 ) ;
2021-06-07 14:49:33 +02:00
if ( ! holder . homes ( ) . containsKey ( search ) ) {
2015-04-15 06:06:16 +02:00
search = StringUtil . safeString ( search ) ;
}
2021-06-07 14:49:33 +02:00
if ( holder . homes ( ) . containsKey ( search ) ) {
holder . homes ( ) . remove ( search ) ;
2015-04-15 06:06:16 +02:00
config . save ( ) ;
} else {
throw new Exception ( tl ( " invalidHome " , search ) ) ;
}
}
public boolean hasHome ( ) {
2021-06-07 14:49:33 +02:00
return ! holder . homes ( ) . isEmpty ( ) ;
2015-04-15 06:06:16 +02:00
}
2020-10-03 19:46:05 +02:00
public boolean hasHome ( final String name ) {
2021-06-07 14:49:33 +02:00
return holder . homes ( ) . containsKey ( name ) ;
2015-04-15 06:06:16 +02:00
}
public String getNickname ( ) {
2021-06-07 14:49:33 +02:00
return holder . nickname ( ) ;
2015-04-15 06:06:16 +02:00
}
2020-10-03 19:46:05 +02:00
public void setNickname ( final String nick ) {
2021-06-07 14:49:33 +02:00
holder . nickname ( nick ) ;
2015-04-15 06:06:16 +02:00
config . save ( ) ;
}
2019-10-05 07:24:01 +02:00
public Set < Material > getUnlimited ( ) {
2021-06-07 14:49:33 +02:00
return holder . unlimited ( ) ;
2015-04-15 06:06:16 +02:00
}
2020-10-03 19:46:05 +02:00
public boolean hasUnlimited ( final ItemStack stack ) {
2021-06-07 14:49:33 +02:00
return holder . 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 ) {
2021-06-07 14:49:33 +02:00
wasUpdated = holder . unlimited ( ) . add ( stack . getType ( ) ) ;
2019-10-05 07:24:01 +02:00
} else {
2021-06-07 14:49:33 +02:00
wasUpdated = holder . unlimited ( ) . remove ( stack . getType ( ) ) ;
2019-10-05 07:24:01 +02:00
}
if ( wasUpdated ) {
2021-06-07 14:49:33 +02:00
config . save ( ) ;
2015-04-15 06:06:16 +02:00
}
}
public void clearAllPowertools ( ) {
2021-06-07 14:49:33 +02:00
holder . powertools ( ) . clear ( ) ;
2015-04-15 06:06:16 +02:00
config . save ( ) ;
}
2020-10-03 19:46:05 +02:00
public List < String > getPowertool ( final ItemStack stack ) {
2021-06-07 14:49:33 +02:00
return getPowertool ( stack . getType ( ) ) ;
2015-04-15 06:06:16 +02:00
}
2020-10-03 19:46:05 +02:00
public List < String > getPowertool ( final Material material ) {
2021-06-07 14:49:33 +02:00
return holder . 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 ( ) ) {
2021-06-07 14:49:33 +02:00
holder . powertools ( ) . remove ( stack . getType ( ) . name ( ) . toLowerCase ( Locale . ENGLISH ) ) ;
2015-04-15 06:06:16 +02:00
} else {
2021-06-07 14:49:33 +02:00
holder . powertools ( ) . put ( stack . getType ( ) . name ( ) . toLowerCase ( Locale . ENGLISH ) , commandList ) ;
2015-04-15 06:06:16 +02:00
}
config . save ( ) ;
}
public boolean hasPowerTools ( ) {
2021-06-07 14:49:33 +02:00
return ! holder . powertools ( ) . isEmpty ( ) ;
2015-04-15 06:06:16 +02:00
}
public Location getLastLocation ( ) {
2021-06-23 14:44:47 +02:00
final LazyLocation lastLocation = holder . lastLocation ( ) ;
return lastLocation ! = null ? lastLocation . location ( ) : null ;
2015-04-15 06:06:16 +02:00
}
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 ;
}
2021-06-07 14:49:33 +02:00
holder . lastLocation ( loc ) ;
2015-04-15 06:06:16 +02:00
config . save ( ) ;
}
public Location getLogoutLocation ( ) {
2021-07-10 15:17:26 +02:00
final LazyLocation logoutLocation = holder . logoutLocation ( ) ;
return logoutLocation ! = null ? logoutLocation . location ( ) : null ;
2015-04-15 06:06:16 +02:00
}
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 ;
}
2021-06-07 14:49:33 +02:00
holder . logoutLocation ( loc ) ;
2015-04-15 06:06:16 +02:00
config . save ( ) ;
}
public long getLastTeleportTimestamp ( ) {
2021-06-07 14:49:33 +02:00
return holder . timestamps ( ) . lastTeleport ( ) ;
2015-04-15 06:06:16 +02:00
}
2020-10-03 19:46:05 +02:00
public void setLastTeleportTimestamp ( final long time ) {
2021-06-07 14:49:33 +02:00
holder . timestamps ( ) . lastTeleport ( time ) ;
2015-04-15 06:06:16 +02:00
config . save ( ) ;
}
public long getLastHealTimestamp ( ) {
2021-06-07 14:49:33 +02:00
return holder . timestamps ( ) . lastHeal ( ) ;
2015-04-15 06:06:16 +02:00
}
2020-10-03 19:46:05 +02:00
public void setLastHealTimestamp ( final long time ) {
2021-06-07 14:49:33 +02:00
holder . timestamps ( ) . lastHeal ( time ) ;
2015-04-15 06:06:16 +02:00
config . save ( ) ;
}
public String getJail ( ) {
2021-06-07 14:49:33 +02:00
return holder . jail ( ) ;
2015-04-15 06:06:16 +02:00
}
2020-10-03 19:46:05 +02:00
public void setJail ( final String jail ) {
2021-06-07 14:49:33 +02:00
holder . jail ( jail ) ;
2015-04-15 06:06:16 +02:00
config . save ( ) ;
}
2021-07-01 17:23:32 +02:00
/ * *
* @deprecated Mails are no longer just strings , this method is therefore misleading .
* /
@Deprecated
2015-04-15 06:06:16 +02:00
public List < String > getMails ( ) {
2021-07-01 17:23:32 +02:00
final List < String > list = new ArrayList < > ( ) ;
if ( getMailAmount ( ) ! = 0 ) {
for ( MailMessage mail : getMailMessages ( ) ) {
// I hate this code btw
list . add ( mail . isLegacy ( ) ? mail . getMessage ( ) : ChatColor . GOLD + " [ " + ChatColor . RESET + mail . getSenderUsername ( ) + ChatColor . GOLD + " ] " + ChatColor . RESET + mail . getMessage ( ) ) ;
}
}
return list ;
2015-04-15 06:06:16 +02:00
}
2021-07-01 17:23:32 +02:00
/ * *
* @deprecated This method does not support the new mail system and will fail at runtime .
* /
@Deprecated
2015-04-15 06:06:16 +02:00
public void setMails ( List < String > mails ) {
2021-07-01 17:23:32 +02:00
throw new UnsupportedOperationException ( " UserData#setMails(List<String>) is deprecated and can no longer be used. Please tell the plugin author to update this! " ) ;
}
public int getMailAmount ( ) {
return holder . mail ( ) = = null ? 0 : holder . mail ( ) . size ( ) ;
}
public int getUnreadMailAmount ( ) {
if ( holder . mail ( ) = = null | | holder . mail ( ) . isEmpty ( ) ) {
return 0 ;
}
int unread = 0 ;
for ( MailMessage element : holder . mail ( ) ) {
if ( ! element . isRead ( ) ) {
unread + + ;
}
}
return unread ;
}
/ * *
* @deprecated This method does not support the new mail system and should not be used .
* /
@Deprecated
abstract void addMail ( final String mail ) ;
public ArrayList < MailMessage > getMailMessages ( ) {
return new ArrayList < > ( holder . mail ( ) ) ;
2015-04-15 06:06:16 +02:00
}
2021-07-01 17:23:32 +02:00
public void setMailList ( ArrayList < MailMessage > messages ) {
holder . mail ( messages ) ;
2021-06-07 14:49:33 +02:00
config . save ( ) ;
2015-04-15 06:06:16 +02:00
}
public boolean isTeleportEnabled ( ) {
2021-06-07 14:49:33 +02:00
return holder . teleportEnabled ( ) ;
2015-04-15 06:06:16 +02:00
}
2020-10-03 19:46:05 +02:00
public void setTeleportEnabled ( final boolean set ) {
2021-06-07 14:49:33 +02:00
holder . teleportEnabled ( set ) ;
2015-04-15 06:06:16 +02:00
config . save ( ) ;
}
2018-12-19 11:50:30 +01:00
public boolean isAutoTeleportEnabled ( ) {
2021-06-07 14:49:33 +02:00
return holder . teleportAuto ( ) ;
2018-12-19 11:50:30 +01:00
}
2020-10-03 19:46:05 +02:00
public void setAutoTeleportEnabled ( final boolean set ) {
2021-06-07 14:49:33 +02:00
holder . teleportAuto ( set ) ;
2018-12-19 11:50:30 +01:00
config . save ( ) ;
}
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 ) {
2021-06-07 14:49:33 +02:00
holder . ignore ( players ) ;
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 ) {
2021-06-07 14:49:33 +02:00
return holder . ignore ( ) . contains ( user . getBase ( ) . getUniqueId ( ) ) & & ! user . isIgnoreExempt ( ) ;
}
public List < UUID > _getIgnoredPlayers ( ) {
return holder . ignore ( ) ;
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 ) {
2021-06-07 14:49:33 +02:00
if ( ! holder . ignore ( ) . contains ( uuid ) ) {
holder . ignore ( ) . add ( uuid ) ;
2020-05-04 12:06:09 +02:00
}
2015-04-15 06:06:16 +02:00
} else {
2021-06-07 14:49:33 +02:00
holder . ignore ( ) . remove ( uuid ) ;
2015-04-15 06:06:16 +02:00
}
2021-06-07 14:49:33 +02:00
config . save ( ) ;
2015-04-15 06:06:16 +02:00
}
public boolean isGodModeEnabled ( ) {
2021-06-07 14:49:33 +02:00
return holder . godMode ( ) ;
2015-04-15 06:06:16 +02:00
}
2020-10-03 19:46:05 +02:00
public void setGodModeEnabled ( final boolean set ) {
2021-06-07 14:49:33 +02:00
holder . godMode ( set ) ;
2015-04-15 06:06:16 +02:00
config . save ( ) ;
}
public boolean getMuted ( ) {
2021-06-07 14:49:33 +02:00
return holder . muted ( ) ;
2015-04-15 06:06:16 +02:00
}
public boolean isMuted ( ) {
2021-06-07 14:49:33 +02:00
return getMuted ( ) ;
2015-04-15 06:06:16 +02:00
}
2020-10-03 19:46:05 +02:00
public void setMuted ( final boolean set ) {
2021-06-07 14:49:33 +02:00
holder . muted ( set ) ;
2015-04-15 06:06:16 +02:00
config . save ( ) ;
}
2017-09-03 05:04:16 +02:00
public String getMuteReason ( ) {
2021-06-07 14:49:33 +02:00
return holder . muteReason ( ) ;
2017-09-03 05:04:16 +02:00
}
2020-10-03 19:46:05 +02:00
public void setMuteReason ( final String reason ) {
2021-06-07 14:49:33 +02:00
holder . muteReason ( reason ) ;
2017-09-03 05:04:16 +02:00
config . save ( ) ;
}
2020-10-03 19:46:05 +02:00
public boolean hasMuteReason ( ) {
2021-06-07 14:49:33 +02:00
return holder . muteReason ( ) ! = null ;
2015-04-15 06:06:16 +02:00
}
public long getMuteTimeout ( ) {
2021-06-07 14:49:33 +02:00
return holder . timestamps ( ) . mute ( ) ;
2015-04-15 06:06:16 +02:00
}
2020-10-03 19:46:05 +02:00
public void setMuteTimeout ( final long time ) {
2021-06-07 14:49:33 +02:00
holder . timestamps ( ) . mute ( time ) ;
2015-04-15 06:06:16 +02:00
config . save ( ) ;
}
public boolean isJailed ( ) {
2021-06-07 14:49:33 +02:00
return holder . jailed ( ) ;
2015-04-15 06:06:16 +02:00
}
2020-10-03 19:46:05 +02:00
public void setJailed ( final boolean set ) {
2021-06-07 14:49:33 +02:00
holder . jailed ( set ) ;
2015-04-15 06:06:16 +02:00
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 ;
}
public long getJailTimeout ( ) {
2021-06-07 14:49:33 +02:00
return holder . timestamps ( ) . jail ( ) ;
2015-04-15 06:06:16 +02:00
}
2020-10-03 19:46:05 +02:00
public void setJailTimeout ( final long time ) {
2021-06-07 14:49:33 +02:00
holder . timestamps ( ) . jail ( time ) ;
2015-04-15 06:06:16 +02:00
config . save ( ) ;
}
2021-01-08 21:43:32 +01:00
public long getOnlineJailedTime ( ) {
2021-06-07 14:49:33 +02:00
return holder . timestamps ( ) . onlineJail ( ) ;
2021-01-08 21:43:32 +01:00
}
public void setOnlineJailedTime ( long onlineJailed ) {
2021-06-07 14:49:33 +02:00
holder . timestamps ( ) . onlineJail ( onlineJailed ) ;
2021-01-08 21:43:32 +01:00
config . save ( ) ;
}
2015-04-15 06:06:16 +02:00
public long getLastLogin ( ) {
2021-06-07 14:49:33 +02:00
return holder . timestamps ( ) . login ( ) ;
2015-04-15 06:06:16 +02:00
}
2020-10-03 19:46:05 +02:00
public void setLastLogin ( final long time ) {
2021-06-07 14:49:33 +02:00
holder . timestamps ( ) . login ( time ) ;
2015-04-15 06:06:16 +02:00
if ( base . getAddress ( ) ! = null & & base . getAddress ( ) . getAddress ( ) ! = null ) {
2021-06-07 14:49:33 +02:00
holder . ipAddress ( base . getAddress ( ) . getAddress ( ) . getHostAddress ( ) ) ;
2015-04-15 06:06:16 +02:00
}
config . save ( ) ;
}
public long getLastLogout ( ) {
2021-06-07 14:49:33 +02:00
return holder . timestamps ( ) . logout ( ) ;
2015-04-15 06:06:16 +02:00
}
2020-10-03 19:46:05 +02:00
public void setLastLogout ( final long time ) {
2021-06-07 14:49:33 +02:00
holder . timestamps ( ) . logout ( time ) ;
2015-04-15 06:06:16 +02:00
config . save ( ) ;
}
public String getLastLoginAddress ( ) {
2021-06-07 14:49:33 +02:00
return holder . ipAddress ( ) ;
2015-04-15 06:06:16 +02:00
}
public boolean isAfk ( ) {
2021-06-07 14:49:33 +02:00
return holder . afk ( ) ;
2015-04-15 06:06:16 +02:00
}
2020-10-03 19:46:05 +02:00
public void _setAfk ( final boolean set ) {
2021-06-07 14:49:33 +02:00
holder . afk ( set ) ;
2015-04-15 06:06:16 +02:00
config . save ( ) ;
}
public String getGeoLocation ( ) {
2021-06-07 14:49:33 +02:00
return holder . geolocation ( ) ;
2015-04-15 06:06:16 +02:00
}
2020-10-03 19:46:05 +02:00
public void setGeoLocation ( final String geolocation ) {
2021-06-07 14:49:33 +02:00
holder . geolocation ( geolocation ) ;
2015-04-15 06:06:16 +02:00
config . save ( ) ;
}
public boolean isSocialSpyEnabled ( ) {
2021-06-07 14:49:33 +02:00
return holder . socialSpy ( ) ;
2015-04-15 06:06:16 +02:00
}
2020-10-03 19:46:05 +02:00
public void setSocialSpyEnabled ( final boolean status ) {
2021-06-07 14:49:33 +02:00
holder . socialSpy ( status ) ;
2015-04-15 06:06:16 +02:00
config . save ( ) ;
}
public boolean isNPC ( ) {
2021-06-07 14:49:33 +02:00
return holder . npc ( ) ;
2015-04-15 06:06:16 +02:00
}
2020-10-03 19:46:05 +02:00
public void setNPC ( final boolean set ) {
2021-06-07 14:49:33 +02:00
holder . npc ( set ) ;
2020-10-03 19:46:05 +02:00
config . save ( ) ;
}
2015-04-15 06:06:16 +02:00
public String getLastAccountName ( ) {
2021-06-07 14:49:33 +02:00
return holder . lastAccountName ( ) ;
2015-04-15 06:06:16 +02:00
}
2020-10-03 19:46:05 +02:00
public void setLastAccountName ( final String lastAccountName ) {
2022-09-04 16:42:43 +02:00
if ( getLastAccountName ( ) ! = null & & ! getLastAccountName ( ) . equals ( lastAccountName ) ) {
final List < String > usernames = holder . pastUsernames ( ) ;
usernames . add ( 0 , getLastAccountName ( ) ) ;
holder . pastUsernames ( usernames ) ;
}
2021-06-07 14:49:33 +02:00
holder . lastAccountName ( lastAccountName ) ;
2015-04-15 06:06:16 +02:00
config . save ( ) ;
}
public boolean arePowerToolsEnabled ( ) {
2021-06-07 14:49:33 +02:00
return holder . powerToolsEnabled ( ) ;
2015-04-15 06:06:16 +02:00
}
2020-10-03 19:46:05 +02:00
public void setPowerToolsEnabled ( final boolean set ) {
2021-06-07 14:49:33 +02:00
holder . powerToolsEnabled ( set ) ;
2015-04-15 06:06:16 +02:00
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 ;
}
public long getKitTimestamp ( String name ) {
2019-06-26 13:54:00 +02:00
name = name . replace ( '.' , '_' ) . replace ( '/' , '_' ) . toLowerCase ( Locale . ENGLISH ) ;
2021-06-07 14:49:33 +02:00
if ( holder . timestamps ( ) . kits ( ) ! = null & & holder . timestamps ( ) . kits ( ) . containsKey ( name ) ) {
return holder . timestamps ( ) . kits ( ) . get ( name ) ;
2015-04-15 06:06:16 +02:00
}
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 ) ;
2021-06-07 14:49:33 +02:00
holder . timestamps ( ) . kits ( ) . put ( name , time ) ;
2015-04-15 06:06:16 +02:00
config . save ( ) ;
}
2021-06-07 14:49:33 +02:00
public List < CommandCooldown > getCooldownsList ( ) {
return holder . timestamps ( ) . commandCooldowns ( ) ;
2016-06-28 04:40:47 +02:00
}
public Map < Pattern , Long > getCommandCooldowns ( ) {
2021-06-07 14:49:33 +02:00
final Map < Pattern , Long > map = new HashMap < > ( ) ;
for ( final CommandCooldown c : getCooldownsList ( ) ) {
2021-08-02 14:32:41 +02:00
if ( c = = null | | c . isIncomplete ( ) ) {
2021-06-10 03:20:51 +02:00
// stupid solution to stupid problem
continue ;
}
2021-06-07 14:49:33 +02:00
map . put ( c . pattern ( ) , c . value ( ) ) ;
2016-06-28 04:40:47 +02:00
}
2021-06-07 14:49:33 +02:00
return map ;
2016-06-28 04:40:47 +02:00
}
2020-10-03 19:46:05 +02:00
public Date getCommandCooldownExpiry ( final String label ) {
2021-06-07 14:49:33 +02:00
for ( CommandCooldown cooldown : getCooldownsList ( ) ) {
2021-08-02 14:32:41 +02:00
if ( cooldown = = null | | cooldown . isIncomplete ( ) ) {
2021-06-10 03:20:51 +02:00
// stupid solution to stupid problem
continue ;
}
2021-06-07 14:49:33 +02:00
if ( cooldown . pattern ( ) . matcher ( label ) . matches ( ) ) {
return new Date ( cooldown . value ( ) ) ;
2016-06-28 04:40:47 +02:00
}
}
return null ;
}
2020-10-03 19:46:05 +02:00
public void addCommandCooldown ( final Pattern pattern , final Date expiresAt , final boolean save ) {
2021-06-07 14:49:33 +02:00
final CommandCooldown cooldown = new CommandCooldown ( ) ;
cooldown . pattern ( pattern ) ;
cooldown . value ( expiresAt . getTime ( ) ) ;
2021-06-19 01:28:10 +02:00
if ( cooldown . isIncomplete ( ) ) {
return ;
}
2021-06-07 14:49:33 +02:00
holder . timestamps ( ) . commandCooldowns ( ) . add ( cooldown ) ;
2016-06-28 04:40:47 +02:00
if ( save ) {
2021-06-07 14:49:33 +02:00
save ( ) ;
2016-06-28 04:40:47 +02:00
}
}
2017-12-29 15:33:04 +01:00
2020-10-03 19:46:05 +02:00
public boolean clearCommandCooldown ( final Pattern pattern ) {
2021-06-07 14:49:33 +02:00
if ( holder . timestamps ( ) . commandCooldowns ( ) . isEmpty ( ) ) {
2016-06-28 04:40:47 +02:00
return false ; // false for no modification
}
2017-12-29 15:33:04 +01:00
2021-08-02 14:32:41 +02:00
if ( getCooldownsList ( ) . removeIf ( cooldown - > cooldown ! = null & & ! cooldown . isIncomplete ( ) & & cooldown . pattern ( ) . equals ( pattern ) ) ) {
2021-06-07 14:49:33 +02:00
save ( ) ;
2016-06-28 04:40:47 +02:00
return true ;
}
return false ;
}
2017-12-29 15:33:04 +01:00
2016-07-26 17:23:34 +02:00
public boolean isAcceptingPay ( ) {
2021-06-07 14:49:33 +02:00
return holder . acceptingPay ( ) ;
2016-07-26 17:23:34 +02:00
}
2020-10-03 19:46:05 +02:00
public void setAcceptingPay ( final boolean acceptingPay ) {
2021-06-07 14:49:33 +02:00
holder . acceptingPay ( acceptingPay ) ;
2016-07-26 17:23:34 +02:00
save ( ) ;
}
2016-12-25 19:08:16 +01:00
public boolean isPromptingPayConfirm ( ) {
2021-06-07 14:49:33 +02:00
return holder . confirmPay ( ) ! = null ? holder . 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 ) {
2021-06-07 14:49:33 +02:00
holder . confirmPay ( prompt ) ;
2016-12-25 19:08:16 +01:00
save ( ) ;
}
2017-11-12 17:44:53 +01:00
public boolean isPromptingClearConfirm ( ) {
2021-06-07 14:49:33 +02:00
return holder . confirmClear ( ) ! = null ? holder . 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 ) {
2021-06-07 14:49:33 +02:00
holder . confirmClear ( prompt ) ;
2017-11-12 17:44:53 +01:00
save ( ) ;
}
2019-03-10 00:39:45 +01:00
public boolean isLastMessageReplyRecipient ( ) {
2021-06-07 14:49:33 +02:00
return holder . lastMessageReplyRecipient ( ) ! = null ? holder . lastMessageReplyRecipient ( ) : ess . getSettings ( ) . isLastMessageReplyRecipient ( ) ;
2019-03-10 00:39:45 +01:00
}
2020-10-03 19:46:05 +02:00
public void setLastMessageReplyRecipient ( final boolean enabled ) {
2021-06-07 14:49:33 +02:00
holder . lastMessageReplyRecipient ( enabled ) ;
2019-03-10 00:39:45 +01:00
save ( ) ;
}
2021-02-15 16:43:10 +01:00
public boolean isBaltopExcludeCache ( ) {
2021-06-07 14:49:33 +02:00
return holder . baltopExempt ( ) ;
2021-02-15 16:43:10 +01:00
}
public void setBaltopExemptCache ( boolean baltopExempt ) {
2021-06-07 14:49:33 +02:00
holder . baltopExempt ( baltopExempt ) ;
2021-02-15 16:43:10 +01:00
config . save ( ) ;
}
2022-09-04 16:42:43 +02:00
public List < String > getPastUsernames ( ) {
return holder . pastUsernames ( ) ;
}
public void addPastUsername ( String username ) {
final List < String > usernames = holder . pastUsernames ( ) ;
usernames . add ( 0 , username ) ;
holder . pastUsernames ( usernames ) ;
config . save ( ) ;
}
2021-09-29 02:31:44 +02:00
public boolean isShouting ( ) {
if ( holder . shouting ( ) = = null ) {
holder . shouting ( ess . getSettings ( ) . isShoutDefault ( ) ) ;
}
return holder . shouting ( ) ;
}
public void setShouting ( boolean shouting ) {
holder . shouting ( shouting ) ;
config . save ( ) ;
}
2015-04-15 06:06:16 +02:00
public UUID getConfigUUID ( ) {
2021-06-07 14:49:33 +02:00
return config . getUuid ( ) ;
2015-04-15 06:06:16 +02:00
}
public void save ( ) {
config . save ( ) ;
}
public void startTransaction ( ) {
config . startTransaction ( ) ;
}
public void stopTransaction ( ) {
config . stopTransaction ( ) ;
}
2021-06-07 14:49:33 +02:00
public void setConfigProperty ( String node , Object object ) {
setConfigPropertyRaw ( " info. " + node , object ) ;
}
public void setConfigPropertyRaw ( String node , Object object ) {
config . setRaw ( node , object ) ;
config . save ( ) ;
}
public Set < String > getConfigKeys ( ) {
return ConfigurateUtil . getKeys ( config . getSection ( " info " ) ) ;
}
public Map < String , Object > getConfigMap ( ) {
return ConfigurateUtil . getRawMap ( config . getSection ( " info " ) ) ;
}
public Map < String , Object > getConfigMap ( final String node ) {
return ConfigurateUtil . getRawMap ( config . getSection ( " info. " + node ) ) ;
}
2011-04-07 04:21:10 +02:00
}