2011-05-13 19:58:30 +00:00
/ *
* Essentials - a bukkit plugin
* Copyright ( C ) 2011 Essentials Team
2011-11-21 01:55:26 +00:00
*
2011-05-13 19:58:30 +00:00
* 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 .
2011-11-21 01:55:26 +00:00
*
2011-05-13 19:58:30 +00:00
* 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 .
2011-11-21 01:55:26 +00:00
*
2011-05-13 19:58:30 +00:00
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
* /
2011-03-30 04:03:21 +00:00
package com.earth2me.essentials ;
2014-03-20 15:54:07 +00:00
import static com.earth2me.essentials.I18n.tl ;
2013-07-02 06:16:42 +00:00
import com.earth2me.essentials.commands.EssentialsCommand ;
2011-03-30 04:03:21 +00:00
import com.earth2me.essentials.commands.IEssentialsCommand ;
2011-08-30 01:15:50 +00:00
import com.earth2me.essentials.commands.NoChargeException ;
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
import com.earth2me.essentials.commands.NotEnoughArgumentsException ;
2013-09-28 16:21:16 +00:00
import com.earth2me.essentials.commands.QuietAbortException ;
2012-03-15 03:49:17 +00:00
import com.earth2me.essentials.metrics.Metrics ;
2012-03-15 00:49:22 +00:00
import com.earth2me.essentials.metrics.MetricsListener ;
import com.earth2me.essentials.metrics.MetricsStarter ;
2011-08-30 21:26:23 +00:00
import com.earth2me.essentials.perm.PermissionsHandler ;
2011-05-13 23:39:18 +00:00
import com.earth2me.essentials.register.payment.Methods ;
2011-07-09 11:52:46 +00:00
import com.earth2me.essentials.signs.SignBlockListener ;
import com.earth2me.essentials.signs.SignEntityListener ;
import com.earth2me.essentials.signs.SignPlayerListener ;
2013-06-16 00:07:16 +00:00
import com.earth2me.essentials.textreader.IText ;
import com.earth2me.essentials.textreader.KeywordReplacer ;
import com.earth2me.essentials.textreader.SimpleTextInput ;
2013-06-08 21:31:19 +00:00
import com.earth2me.essentials.utils.DateUtil ;
2014-07-12 06:03:36 +00:00
import com.google.common.base.Function ;
import com.google.common.base.Throwables ;
import com.google.common.collect.Iterables ;
2011-11-18 17:42:26 +00:00
import java.io.File ;
import java.io.FileReader ;
import java.io.IOException ;
2014-07-12 06:03:36 +00:00
import java.lang.reflect.InvocationTargetException ;
import java.lang.reflect.Method ;
2011-11-18 17:42:26 +00:00
import java.util.ArrayList ;
2014-07-12 06:03:36 +00:00
import java.util.Arrays ;
import java.util.Collection ;
2011-11-18 17:42:26 +00:00
import java.util.List ;
2014-04-13 05:53:11 +00:00
import java.util.UUID ;
2011-11-18 17:42:26 +00:00
import java.util.logging.Level ;
import java.util.logging.Logger ;
2011-03-30 04:03:21 +00:00
import java.util.regex.Matcher ;
import java.util.regex.Pattern ;
2013-10-11 02:44:41 +00:00
import net.ess3.api.Economy ;
import net.ess3.api.IEssentials ;
2013-07-13 17:52:53 +00:00
import net.ess3.api.IItemDb ;
2013-10-11 02:44:41 +00:00
import net.ess3.api.IJails ;
import net.ess3.api.ISettings ;
2012-04-20 21:31:25 +00:00
import org.bukkit.Bukkit ;
2012-02-11 02:45:15 +00:00
import org.bukkit.ChatColor ;
2011-11-18 17:42:26 +00:00
import org.bukkit.Server ;
import org.bukkit.World ;
2013-07-02 06:16:42 +00:00
import org.bukkit.block.Block ;
import org.bukkit.command.BlockCommandSender ;
2011-11-18 17:42:26 +00:00
import org.bukkit.command.Command ;
import org.bukkit.command.CommandSender ;
2011-07-09 11:52:46 +00:00
import org.bukkit.command.PluginCommand ;
2013-08-15 20:58:23 +00:00
import org.bukkit.command.TabCompleter ;
2011-03-30 04:03:21 +00:00
import org.bukkit.entity.Player ;
2012-01-20 04:20:37 +00:00
import org.bukkit.event.EventHandler ;
import org.bukkit.event.EventPriority ;
2012-12-31 05:44:20 +00:00
import org.bukkit.event.HandlerList ;
2012-01-20 04:20:37 +00:00
import org.bukkit.event.Listener ;
2011-11-30 19:48:42 +00:00
import org.bukkit.event.player.PlayerJoinEvent ;
2012-01-14 22:13:58 +00:00
import org.bukkit.event.world.WorldLoadEvent ;
import org.bukkit.event.world.WorldUnloadEvent ;
2011-11-18 17:42:26 +00:00
import org.bukkit.plugin.InvalidDescriptionException ;
import org.bukkit.plugin.Plugin ;
import org.bukkit.plugin.PluginDescriptionFile ;
import org.bukkit.plugin.PluginManager ;
import org.bukkit.plugin.java.JavaPlugin ;
2014-01-20 10:20:13 +00:00
import org.bukkit.plugin.java.JavaPluginLoader ;
2011-08-08 12:40:30 +00:00
import org.bukkit.scheduler.BukkitScheduler ;
2013-01-31 19:03:27 +00:00
import org.bukkit.scheduler.BukkitTask ;
2011-11-30 19:48:42 +00:00
import org.yaml.snakeyaml.error.YAMLException ;
2011-03-30 04:03:21 +00:00
2013-07-13 16:52:08 +00:00
public class Essentials extends JavaPlugin implements net . ess3 . api . IEssentials
2011-03-30 04:03:21 +00:00
{
2014-04-18 02:58:27 +00:00
public static final int BUKKIT_VERSION = 3050 ;
2013-12-07 20:03:05 +00:00
private static final Logger LOGGER = Logger . getLogger ( " Essentials " ) ;
2011-07-16 00:38:22 +00:00
private transient ISettings settings ;
2011-07-15 21:39:56 +00:00
private final transient TNTExplodeListener tntListener = new TNTExplodeListener ( this ) ;
2011-12-06 16:28:48 +00:00
private transient Jails jails ;
2011-07-15 21:39:56 +00:00
private transient Warps warps ;
private transient Worth worth ;
private transient List < IConf > confList ;
private transient Backup backup ;
2011-07-15 23:33:22 +00:00
private transient ItemDb itemDb ;
2011-07-15 21:39:56 +00:00
private transient final Methods paymentMethod = new Methods ( ) ;
2011-08-30 21:26:23 +00:00
private transient PermissionsHandler permissionsHandler ;
2011-11-18 00:43:58 +00:00
private transient AlternativeCommandsHandler alternativeCommandsHandler ;
2011-08-08 12:40:30 +00:00
private transient UserMap userMap ;
2011-10-30 05:38:17 +00:00
private transient ExecuteTimer execTimer ;
2011-11-21 01:55:26 +00:00
private transient I18n i18n ;
2012-03-15 03:49:17 +00:00
private transient Metrics metrics ;
2012-05-17 10:33:40 +00:00
private transient EssentialsTimer timer ;
2014-03-20 15:54:07 +00:00
private final transient List < String > vanishedPlayers = new ArrayList < String > ( ) ;
2014-07-12 06:03:36 +00:00
private transient Method oldGetOnlinePlayers ;
2011-03-30 04:03:21 +00:00
2014-01-20 10:20:13 +00:00
public Essentials ( )
{
}
public Essentials ( final Server server )
{
super ( new JavaPluginLoader ( server ) , new PluginDescriptionFile ( " Essentials " , " " , " com.earth2me.essentials.Essentials " ) , null , null ) ;
}
2011-08-08 12:40:30 +00:00
@Override
2011-07-16 00:38:22 +00:00
public ISettings getSettings ( )
2011-03-30 04:03:21 +00:00
{
return settings ;
}
2011-05-02 22:51:57 +00:00
2011-07-15 21:39:56 +00:00
public void setupForTesting ( final Server server ) throws IOException , InvalidDescriptionException
2011-03-30 04:03:21 +00:00
{
2011-07-15 21:39:56 +00:00
final File dataFolder = File . createTempFile ( " essentialstest " , " " ) ;
if ( ! dataFolder . delete ( ) )
{
throw new IOException ( ) ;
}
if ( ! dataFolder . mkdir ( ) )
{
throw new IOException ( ) ;
}
2011-11-21 01:55:26 +00:00
i18n = new I18n ( this ) ;
i18n . onEnable ( ) ;
2014-05-05 13:48:25 +00:00
i18n . updateLocale ( " en " ) ;
2014-03-20 15:54:07 +00:00
LOGGER . log ( Level . INFO , tl ( " usingTempFolderForTesting " ) ) ;
2011-07-15 21:39:56 +00:00
LOGGER . log ( Level . INFO , dataFolder . toString ( ) ) ;
2011-05-13 19:18:22 +00:00
this . initialize ( null , server , new PluginDescriptionFile ( new FileReader ( new File ( " src " + File . separator + " plugin.yml " ) ) ) , dataFolder , null , null ) ;
2011-07-15 23:33:22 +00:00
settings = new Settings ( this ) ;
2011-08-08 12:40:30 +00:00
userMap = new UserMap ( this ) ;
2011-08-30 21:26:23 +00:00
permissionsHandler = new PermissionsHandler ( this , false ) ;
2011-07-15 23:33:22 +00:00
Economy . setEss ( this ) ;
2014-05-27 19:31:13 +00:00
confList = new ArrayList < IConf > ( ) ;
jails = new Jails ( this ) ;
registerListeners ( server . getPluginManager ( ) ) ;
2011-03-30 04:03:21 +00:00
}
2011-08-08 12:40:30 +00:00
@Override
2011-03-30 04:03:21 +00:00
public void onEnable ( )
{
2013-08-13 22:37:33 +00:00
try
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
{
2013-12-07 20:03:05 +00:00
LOGGER . setParent ( this . getLogger ( ) ) ;
2013-08-13 22:37:33 +00:00
execTimer = new ExecuteTimer ( ) ;
execTimer . start ( ) ;
i18n = new I18n ( this ) ;
i18n . onEnable ( ) ;
execTimer . mark ( " I18n1 " ) ;
final PluginManager pm = getServer ( ) . getPluginManager ( ) ;
for ( Plugin plugin : pm . getPlugins ( ) )
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
{
2013-08-13 22:37:33 +00:00
if ( plugin . getDescription ( ) . getName ( ) . startsWith ( " Essentials " )
& & ! plugin . getDescription ( ) . getVersion ( ) . equals ( this . getDescription ( ) . getVersion ( ) )
& & ! plugin . getDescription ( ) . getName ( ) . equals ( " EssentialsAntiCheat " ) )
{
2014-03-20 15:54:07 +00:00
LOGGER . log ( Level . WARNING , tl ( " versionMismatch " , plugin . getDescription ( ) . getName ( ) ) ) ;
2013-08-13 22:37:33 +00:00
}
2011-03-30 04:03:21 +00:00
}
2013-08-13 22:37:33 +00:00
final Matcher versionMatch = Pattern . compile ( " git-Bukkit-(?:(?:[0-9]+) \\ .)+[0-9]+-R[ \\ .0-9]+-(?:[0-9]+-g[0-9a-f]+-)?b([0-9]+)jnks.* " ) . matcher ( getServer ( ) . getVersion ( ) ) ;
if ( versionMatch . matches ( ) )
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
{
2013-08-13 22:37:33 +00:00
final int versionNumber = Integer . parseInt ( versionMatch . group ( 1 ) ) ;
if ( versionNumber < BUKKIT_VERSION & & versionNumber > 100 )
{
2013-11-15 00:22:10 +00:00
wrongVersion ( ) ;
2013-08-13 22:37:33 +00:00
this . setEnabled ( false ) ;
return ;
}
2011-03-30 04:03:21 +00:00
}
2013-08-13 22:37:33 +00:00
else
2011-11-30 19:48:42 +00:00
{
2014-03-20 15:54:07 +00:00
LOGGER . log ( Level . INFO , tl ( " bukkitFormatChanged " ) ) ;
2013-08-13 22:37:33 +00:00
LOGGER . log ( Level . INFO , getServer ( ) . getVersion ( ) ) ;
LOGGER . log ( Level . INFO , getServer ( ) . getBukkitVersion ( ) ) ;
2011-11-30 19:48:42 +00:00
}
2013-08-13 22:37:33 +00:00
execTimer . mark ( " BukkitCheck " ) ;
2014-07-12 06:03:36 +00:00
for ( Method method : Server . class . getDeclaredMethods ( ) )
{
if ( method . getName ( ) . endsWith ( " getOnlinePlayers " ) & & method . getReturnType ( ) = = Player [ ] . class )
{
oldGetOnlinePlayers = method ;
break ;
}
}
2013-08-13 22:37:33 +00:00
try
2011-11-30 19:48:42 +00:00
{
2013-08-13 22:37:33 +00:00
final EssentialsUpgrade upgrade = new EssentialsUpgrade ( this ) ;
upgrade . beforeSettings ( ) ;
execTimer . mark ( " Upgrade " ) ;
confList = new ArrayList < IConf > ( ) ;
settings = new Settings ( this ) ;
confList . add ( settings ) ;
execTimer . mark ( " Settings " ) ;
userMap = new UserMap ( this ) ;
confList . add ( userMap ) ;
execTimer . mark ( " Init(Usermap) " ) ;
2014-04-13 05:53:11 +00:00
upgrade . afterSettings ( ) ;
execTimer . mark ( " Upgrade2 " ) ;
i18n . updateLocale ( settings . getLocale ( ) ) ;
2013-08-13 22:37:33 +00:00
warps = new Warps ( getServer ( ) , this . getDataFolder ( ) ) ;
confList . add ( warps ) ;
execTimer . mark ( " Init(Spawn/Warp) " ) ;
worth = new Worth ( this . getDataFolder ( ) ) ;
confList . add ( worth ) ;
itemDb = new ItemDb ( this ) ;
confList . add ( itemDb ) ;
execTimer . mark ( " Init(Worth/ItemDB) " ) ;
jails = new Jails ( this ) ;
confList . add ( jails ) ;
reload ( ) ;
2011-11-30 19:48:42 +00:00
}
2013-08-13 22:37:33 +00:00
catch ( YAMLException exception )
2011-11-30 20:25:11 +00:00
{
2013-08-13 22:37:33 +00:00
if ( pm . getPlugin ( " EssentialsUpdate " ) ! = null )
2011-11-30 19:48:42 +00:00
{
2014-03-20 15:54:07 +00:00
LOGGER . log ( Level . SEVERE , tl ( " essentialsHelp2 " ) ) ;
2011-11-30 19:48:42 +00:00
}
2013-08-13 22:37:33 +00:00
else
{
2014-03-20 15:54:07 +00:00
LOGGER . log ( Level . SEVERE , tl ( " essentialsHelp1 " ) ) ;
2013-08-13 22:37:33 +00:00
}
handleCrash ( exception ) ;
return ;
2011-11-30 19:48:42 +00:00
}
2013-08-13 22:37:33 +00:00
backup = new Backup ( this ) ;
permissionsHandler = new PermissionsHandler ( this , settings . useBukkitPermissions ( ) ) ;
alternativeCommandsHandler = new AlternativeCommandsHandler ( this ) ;
2013-01-25 03:06:21 +00:00
2013-08-13 22:37:33 +00:00
timer = new EssentialsTimer ( this ) ;
scheduleSyncRepeatingTask ( timer , 1000 , 50 ) ;
2012-12-31 05:44:20 +00:00
2013-08-13 22:37:33 +00:00
Economy . setEss ( this ) ;
execTimer . mark ( " RegHandler " ) ;
2012-12-31 05:44:20 +00:00
2013-08-13 22:37:33 +00:00
final MetricsStarter metricsStarter = new MetricsStarter ( this ) ;
if ( metricsStarter . getStart ( ) ! = null & & metricsStarter . getStart ( ) = = true )
{
runTaskLaterAsynchronously ( metricsStarter , 1 ) ;
}
else if ( metricsStarter . getStart ( ) ! = null & & metricsStarter . getStart ( ) = = false )
{
final MetricsListener metricsListener = new MetricsListener ( this , metricsStarter ) ;
pm . registerEvents ( metricsListener , this ) ;
}
final String timeroutput = execTimer . end ( ) ;
if ( getSettings ( ) . isDebug ( ) )
{
2014-03-20 15:54:07 +00:00
LOGGER . log ( Level . INFO , " Essentials load {0} " , timeroutput ) ;
2013-08-13 22:37:33 +00:00
}
2012-12-31 05:44:20 +00:00
}
2013-11-07 02:22:32 +00:00
catch ( NumberFormatException ex )
2012-12-31 05:44:20 +00:00
{
2013-08-13 22:37:33 +00:00
handleCrash ( ex ) ;
2012-12-31 05:44:20 +00:00
}
2013-08-13 22:37:33 +00:00
catch ( Error ex )
2012-12-31 05:44:20 +00:00
{
2013-08-13 22:37:33 +00:00
handleCrash ( ex ) ;
throw ex ;
2012-12-31 05:44:20 +00:00
}
}
2013-07-02 06:16:42 +00:00
2013-06-17 00:08:42 +00:00
@Override
2013-07-02 06:16:42 +00:00
public void saveConfig ( )
{
2013-06-17 00:08:42 +00:00
// We don't use any of the bukkit config writing, as this breaks our config file formatting.
}
2013-07-02 06:16:42 +00:00
2013-01-25 03:06:21 +00:00
private void registerListeners ( PluginManager pm )
{
2012-12-31 05:44:20 +00:00
HandlerList . unregisterAll ( this ) ;
2013-01-25 03:06:21 +00:00
2012-12-31 05:44:20 +00:00
if ( getSettings ( ) . isDebug ( ) )
{
LOGGER . log ( Level . INFO , " Registering Listeners " ) ;
}
2013-01-25 03:06:21 +00:00
2011-08-27 19:13:33 +00:00
final EssentialsPluginListener serverListener = new EssentialsPluginListener ( this ) ;
2012-01-20 04:20:37 +00:00
pm . registerEvents ( serverListener , this ) ;
2011-08-27 19:13:33 +00:00
confList . add ( serverListener ) ;
2011-05-14 10:14:58 +00:00
2011-07-09 11:52:46 +00:00
final EssentialsPlayerListener playerListener = new EssentialsPlayerListener ( this ) ;
2012-01-20 04:20:37 +00:00
pm . registerEvents ( playerListener , this ) ;
2011-03-30 04:03:21 +00:00
2011-07-09 11:52:46 +00:00
final EssentialsBlockListener blockListener = new EssentialsBlockListener ( this ) ;
2012-01-20 04:20:37 +00:00
pm . registerEvents ( blockListener , this ) ;
2011-07-15 14:43:39 +00:00
2011-07-09 11:52:46 +00:00
final SignBlockListener signBlockListener = new SignBlockListener ( this ) ;
2012-01-20 04:20:37 +00:00
pm . registerEvents ( signBlockListener , this ) ;
2011-07-15 14:43:39 +00:00
2011-07-09 11:52:46 +00:00
final SignPlayerListener signPlayerListener = new SignPlayerListener ( this ) ;
2012-01-20 04:20:37 +00:00
pm . registerEvents ( signPlayerListener , this ) ;
2011-07-15 14:43:39 +00:00
2011-07-09 11:52:46 +00:00
final SignEntityListener signEntityListener = new SignEntityListener ( this ) ;
2012-01-20 04:20:37 +00:00
pm . registerEvents ( signEntityListener , this ) ;
2011-07-09 11:52:46 +00:00
final EssentialsEntityListener entityListener = new EssentialsEntityListener ( this ) ;
2012-01-20 04:20:37 +00:00
pm . registerEvents ( entityListener , this ) ;
2012-03-15 00:49:22 +00:00
2012-01-14 22:13:58 +00:00
final EssentialsWorldListener worldListener = new EssentialsWorldListener ( this ) ;
2012-01-20 04:20:37 +00:00
pm . registerEvents ( worldListener , this ) ;
2013-01-25 03:06:21 +00:00
2012-01-20 04:20:37 +00:00
pm . registerEvents ( tntListener , this ) ;
2013-01-25 03:06:21 +00:00
jails . resetListener ( ) ;
2011-03-30 04:03:21 +00:00
}
2011-08-08 12:40:30 +00:00
@Override
2011-03-30 04:03:21 +00:00
public void onDisable ( )
{
2014-08-16 09:04:13 +00:00
for ( User user : getOnlineUsers ( ) )
2012-05-17 10:25:02 +00:00
{
2012-06-10 23:17:19 +00:00
if ( user . isVanished ( ) )
2012-05-17 10:25:02 +00:00
{
2013-06-02 16:45:56 +00:00
user . setVanished ( false ) ;
2014-03-20 15:54:07 +00:00
user . sendMessage ( tl ( " unvanishedReload " ) ) ;
2012-05-17 10:25:02 +00:00
}
2014-05-25 00:38:37 +00:00
user . stopTransaction ( ) ;
2012-05-17 10:25:02 +00:00
}
2013-03-19 21:05:12 +00:00
cleanupOpenInventories ( ) ;
2013-08-13 22:37:33 +00:00
if ( i18n ! = null )
{
i18n . onDisable ( ) ;
}
if ( backup ! = null )
{
backup . stopTask ( ) ;
}
2011-11-15 21:49:23 +00:00
Economy . setEss ( null ) ;
2011-07-09 11:52:46 +00:00
Trade . closeLog ( ) ;
2014-04-17 03:53:02 +00:00
getUserMap ( ) . getUUIDMap ( ) . forceWriteUUIDMap ( ) ;
2014-06-19 01:59:08 +00:00
HandlerList . unregisterAll ( this ) ;
2011-03-30 04:03:21 +00:00
}
2011-08-08 12:40:30 +00:00
@Override
2011-03-30 04:03:21 +00:00
public void reload ( )
{
2011-07-09 11:52:46 +00:00
Trade . closeLog ( ) ;
2011-03-30 04:03:21 +00:00
for ( IConf iConf : confList )
{
iConf . reloadConfig ( ) ;
2011-10-30 05:38:17 +00:00
execTimer . mark ( " Reload( " + iConf . getClass ( ) . getSimpleName ( ) + " ) " ) ;
2011-03-30 04:03:21 +00:00
}
2011-05-28 03:29:11 +00:00
2011-11-21 01:55:26 +00:00
i18n . updateLocale ( settings . getLocale ( ) ) ;
2013-01-25 03:06:21 +00:00
2012-12-31 05:44:20 +00:00
final PluginManager pm = getServer ( ) . getPluginManager ( ) ;
registerListeners ( pm ) ;
2011-03-30 04:03:21 +00:00
}
2013-08-15 20:58:23 +00:00
@Override
public List < String > onTabComplete ( CommandSender sender ,
Command command ,
String commandLabel ,
String [ ] args )
{
// Allow plugins to override the command via onCommand
if ( ! getSettings ( ) . isCommandOverridden ( command . getName ( ) ) & & ( ! commandLabel . startsWith ( " e " ) | | commandLabel . equalsIgnoreCase ( command . getName ( ) ) ) )
{
final PluginCommand pc = alternativeCommandsHandler . getAlternative ( commandLabel ) ;
if ( pc ! = null )
{
try
{
TabCompleter completer = pc . getTabCompleter ( ) ;
if ( completer ! = null )
{
return completer . onTabComplete ( sender , command , commandLabel , args ) ;
}
}
catch ( final Exception ex )
{
Bukkit . getLogger ( ) . log ( Level . SEVERE , ex . getMessage ( ) , ex ) ;
}
}
}
return null ;
}
2011-03-30 04:03:21 +00:00
@Override
2011-08-08 12:40:30 +00:00
public boolean onCommand ( final CommandSender sender , final Command command , final String commandLabel , final String [ ] args )
2011-03-30 04:03:21 +00:00
{
2011-12-06 12:41:29 +00:00
return onCommandEssentials ( sender , command , commandLabel , args , Essentials . class . getClassLoader ( ) , " com.earth2me.essentials.commands.Command " , " essentials. " , null ) ;
2011-05-10 19:57:59 +00:00
}
2011-05-13 20:36:41 +00:00
2011-08-08 12:40:30 +00:00
@Override
2013-10-16 19:59:39 +00:00
public boolean onCommandEssentials ( final CommandSender cSender , final Command command , final String commandLabel , final String [ ] args , final ClassLoader classLoader , final String commandPath , final String permissionPrefix , final IEssentialsModule module )
2011-07-15 14:43:39 +00:00
{
2011-03-30 04:03:21 +00:00
// Allow plugins to override the command via onCommand
2011-12-14 14:07:08 +00:00
if ( ! getSettings ( ) . isCommandOverridden ( command . getName ( ) ) & & ( ! commandLabel . startsWith ( " e " ) | | commandLabel . equalsIgnoreCase ( command . getName ( ) ) ) )
2011-03-30 04:03:21 +00:00
{
2011-11-18 00:43:58 +00:00
final PluginCommand pc = alternativeCommandsHandler . getAlternative ( commandLabel ) ;
if ( pc ! = null )
2011-04-15 01:41:42 +00:00
{
2012-12-21 06:38:51 +00:00
alternativeCommandsHandler . executed ( commandLabel , pc ) ;
2012-02-11 02:45:15 +00:00
try
{
2013-10-16 19:59:39 +00:00
return pc . execute ( cSender , commandLabel , args ) ;
2012-02-11 02:45:15 +00:00
}
catch ( final Exception ex )
{
2012-04-20 21:31:25 +00:00
Bukkit . getLogger ( ) . log ( Level . SEVERE , ex . getMessage ( ) , ex ) ;
2013-10-16 19:59:39 +00:00
cSender . sendMessage ( ChatColor . RED + " An internal error occurred while attempting to perform this command " ) ;
2012-02-11 02:45:15 +00:00
return true ;
}
2011-11-18 00:01:05 +00:00
}
2011-05-22 21:01:23 +00:00
}
2011-03-30 04:03:21 +00:00
try
{
2013-10-16 19:59:39 +00:00
2011-07-09 11:52:46 +00:00
User user = null ;
2013-07-02 06:16:42 +00:00
Block bSenderBlock = null ;
2013-10-16 19:59:39 +00:00
if ( cSender instanceof Player )
2011-07-09 11:52:46 +00:00
{
2013-10-16 19:59:39 +00:00
user = getUser ( ( Player ) cSender ) ;
2011-07-09 11:52:46 +00:00
}
2013-10-16 19:59:39 +00:00
else if ( cSender instanceof BlockCommandSender )
2013-07-02 06:16:42 +00:00
{
2013-10-16 19:59:39 +00:00
BlockCommandSender bsender = ( BlockCommandSender ) cSender ;
2013-07-02 06:16:42 +00:00
bSenderBlock = bsender . getBlock ( ) ;
}
2013-07-09 00:22:38 +00:00
2013-07-02 06:16:42 +00:00
if ( bSenderBlock ! = null )
{
Bukkit . getLogger ( ) . log ( Level . INFO , " CommandBlock at {0},{1},{2} issued server command: /{3} {4} " , new Object [ ]
{
bSenderBlock . getX ( ) , bSenderBlock . getY ( ) , bSenderBlock . getZ ( ) , commandLabel , EssentialsCommand . getFinalArg ( args , 0 )
} ) ;
}
else if ( user = = null )
{
Bukkit . getLogger ( ) . log ( Level . INFO , " {0} issued server command: /{1} {2} " , new Object [ ]
{
2013-10-16 19:59:39 +00:00
cSender . getName ( ) , commandLabel , EssentialsCommand . getFinalArg ( args , 0 )
2013-07-02 06:16:42 +00:00
} ) ;
}
2013-10-16 19:59:39 +00:00
CommandSource sender = new CommandSource ( cSender ) ;
2011-03-30 04:03:21 +00:00
// New mail notification
2013-03-11 02:01:00 +00:00
if ( user ! = null & & ! getSettings ( ) . isCommandDisabled ( " mail " ) & & ! command . getName ( ) . equals ( " mail " ) & & user . isAuthorized ( " essentials.mail " ) )
2011-03-30 04:03:21 +00:00
{
2011-06-01 10:40:12 +00:00
final List < String > mail = user . getMails ( ) ;
if ( mail ! = null & & ! mail . isEmpty ( ) )
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
{
2014-03-20 15:54:07 +00:00
user . sendMessage ( tl ( " youHaveNewMail " , mail . size ( ) ) ) ;
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
}
2011-03-30 04:03:21 +00:00
}
2013-07-17 17:29:46 +00:00
//Print version even if admin command is not available #easteregg
2013-03-21 21:12:58 +00:00
if ( commandLabel . equalsIgnoreCase ( " essversion " ) )
2013-03-11 02:01:00 +00:00
{
sender . sendMessage ( " This server is running Essentials " + getDescription ( ) . getVersion ( ) ) ;
2013-03-21 21:12:58 +00:00
return true ;
2013-03-11 02:01:00 +00:00
}
2011-03-30 04:03:21 +00:00
// Check for disabled commands
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
if ( getSettings ( ) . isCommandDisabled ( commandLabel ) )
{
return true ;
}
2011-03-30 04:03:21 +00:00
IEssentialsCommand cmd ;
try
{
2011-05-10 19:57:59 +00:00
cmd = ( IEssentialsCommand ) classLoader . loadClass ( commandPath + command . getName ( ) ) . newInstance ( ) ;
2011-06-01 10:40:12 +00:00
cmd . setEssentials ( this ) ;
2011-12-06 12:41:29 +00:00
cmd . setEssentialsModule ( module ) ;
2011-03-30 04:03:21 +00:00
}
catch ( Exception ex )
{
2014-03-20 15:54:07 +00:00
sender . sendMessage ( tl ( " commandNotLoaded " , commandLabel ) ) ;
LOGGER . log ( Level . SEVERE , tl ( " commandNotLoaded " , commandLabel ) , ex ) ;
2011-03-30 04:03:21 +00:00
return true ;
}
// Check authorization
2011-07-09 11:52:46 +00:00
if ( user ! = null & & ! user . isAuthorized ( cmd , permissionPrefix ) )
2011-03-30 04:03:21 +00:00
{
2014-03-20 15:54:07 +00:00
LOGGER . log ( Level . INFO , tl ( " deniedAccessCommand " , user . getName ( ) ) ) ;
user . sendMessage ( tl ( " noAccessCommand " ) ) ;
2011-03-30 04:03:21 +00:00
return true ;
}
2012-12-20 22:47:49 +00:00
if ( user ! = null & & user . isJailed ( ) & & ! user . isAuthorized ( cmd , " essentials.jail.allow. " ) )
{
if ( user . getJailTimeout ( ) > 0 )
{
2014-03-20 15:54:07 +00:00
user . sendMessage ( tl ( " playerJailedFor " , user . getName ( ) , DateUtil . formatDateDiff ( user . getJailTimeout ( ) ) ) ) ;
2012-12-20 22:47:49 +00:00
}
else
{
2014-03-20 15:54:07 +00:00
user . sendMessage ( tl ( " jailMessage " ) ) ;
2012-12-20 22:47:49 +00:00
}
return true ;
}
2011-03-30 04:03:21 +00:00
// Run the command
try
{
if ( user = = null )
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
{
cmd . run ( getServer ( ) , sender , commandLabel , command , args ) ;
}
2011-03-30 04:03:21 +00:00
else
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
{
cmd . run ( getServer ( ) , user , commandLabel , command , args ) ;
}
return true ;
}
2011-08-30 01:15:50 +00:00
catch ( NoChargeException ex )
{
return true ;
}
2013-09-28 16:21:16 +00:00
catch ( QuietAbortException ex )
{
return true ;
}
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
catch ( NotEnoughArgumentsException ex )
{
sender . sendMessage ( command . getDescription ( ) ) ;
2011-05-15 11:40:46 +00:00
sender . sendMessage ( command . getUsage ( ) . replaceAll ( " <command> " , commandLabel ) ) ;
2011-11-28 23:36:36 +00:00
if ( ! ex . getMessage ( ) . isEmpty ( ) )
{
2011-11-27 03:36:27 +00:00
sender . sendMessage ( ex . getMessage ( ) ) ;
}
2011-03-30 04:03:21 +00:00
return true ;
}
2013-11-07 02:22:32 +00:00
catch ( Exception ex )
2011-03-30 04:03:21 +00:00
{
2011-07-09 11:52:46 +00:00
showError ( sender , ex , commandLabel ) ;
2011-03-30 04:03:21 +00:00
return true ;
}
}
catch ( Throwable ex )
{
2014-03-20 15:54:07 +00:00
LOGGER . log ( Level . SEVERE , tl ( " commandFailed " , commandLabel ) , ex ) ;
2011-03-30 04:03:21 +00:00
return true ;
}
}
2013-04-13 22:50:17 +00:00
2013-03-19 21:05:12 +00:00
public void cleanupOpenInventories ( )
{
2014-08-16 09:04:13 +00:00
for ( User user : getOnlineUsers ( ) )
2013-03-19 21:05:12 +00:00
{
if ( user . isRecipeSee ( ) )
2013-04-13 22:50:17 +00:00
{
2013-07-07 11:11:57 +00:00
user . getBase ( ) . getOpenInventory ( ) . getTopInventory ( ) . clear ( ) ;
user . getBase ( ) . getOpenInventory ( ) . close ( ) ;
2013-03-19 21:05:12 +00:00
user . setRecipeSee ( false ) ;
}
if ( user . isInvSee ( ) | | user . isEnderSee ( ) )
{
2013-07-07 11:11:57 +00:00
user . getBase ( ) . getOpenInventory ( ) . close ( ) ;
2013-03-19 21:05:12 +00:00
user . setInvSee ( false ) ;
user . setEnderSee ( false ) ;
}
}
}
2011-03-30 04:03:21 +00:00
2011-08-08 12:40:30 +00:00
@Override
2013-10-16 19:59:39 +00:00
public void showError ( final CommandSource sender , final Throwable exception , final String commandLabel )
2011-07-09 11:52:46 +00:00
{
2014-03-20 15:54:07 +00:00
sender . sendMessage ( tl ( " errorWithMessage " , exception . getMessage ( ) ) ) ;
2011-07-09 11:52:46 +00:00
if ( getSettings ( ) . isDebug ( ) )
{
2014-04-18 03:48:34 +00:00
LOGGER . log ( Level . INFO , tl ( " errorCallingCommand " , commandLabel ) , exception ) ;
2011-07-09 11:52:46 +00:00
}
}
2014-02-04 16:11:43 +00:00
public static void wrongVersion ( )
2013-11-15 00:22:10 +00:00
{
LOGGER . log ( Level . SEVERE , " * ! * ! * ! * ! * ! * ! * ! * ! * ! * ! * ! * ! * " ) ;
2014-03-20 15:54:07 +00:00
LOGGER . log ( Level . SEVERE , tl ( " notRecommendedBukkit " ) ) ;
LOGGER . log ( Level . SEVERE , tl ( " requiredBukkit " , Integer . toString ( BUKKIT_VERSION ) ) ) ;
2013-11-15 00:22:10 +00:00
LOGGER . log ( Level . SEVERE , " * ! * ! * ! * ! * ! * ! * ! * ! * ! * ! * ! * ! * " ) ;
}
2011-08-08 12:40:30 +00:00
@Override
public BukkitScheduler getScheduler ( )
2011-03-30 04:03:21 +00:00
{
2011-08-08 12:40:30 +00:00
return this . getServer ( ) . getScheduler ( ) ;
2011-03-30 04:03:21 +00:00
}
2011-08-08 12:40:30 +00:00
@Override
2012-04-14 22:18:20 +00:00
public IJails getJails ( )
2011-03-30 04:03:21 +00:00
{
2012-04-14 22:18:20 +00:00
return jails ;
2011-03-30 04:03:21 +00:00
}
2011-08-08 12:40:30 +00:00
@Override
2011-06-01 10:40:12 +00:00
public Warps getWarps ( )
2011-03-30 04:03:21 +00:00
{
2011-06-01 10:40:12 +00:00
return warps ;
2011-03-30 04:03:21 +00:00
}
2011-04-16 00:42:43 +00:00
2011-08-08 12:40:30 +00:00
@Override
2011-06-01 10:40:12 +00:00
public Worth getWorth ( )
2011-04-16 00:42:43 +00:00
{
2011-06-01 10:40:12 +00:00
return worth ;
2011-04-16 00:42:43 +00:00
}
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
2011-08-08 12:40:30 +00:00
@Override
2011-06-01 10:40:12 +00:00
public Backup getBackup ( )
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
{
2011-06-01 10:40:12 +00:00
return backup ;
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
}
2013-11-07 02:22:32 +00:00
@Override
2012-03-15 03:49:17 +00:00
public Metrics getMetrics ( )
{
return metrics ;
}
2013-11-07 02:22:32 +00:00
@Override
2012-03-15 03:49:17 +00:00
public void setMetrics ( Metrics metrics )
{
this . metrics = metrics ;
}
2013-10-17 22:55:42 +00:00
@Deprecated
@Override
public User getUser ( final Object base )
{
if ( base instanceof Player )
{
return getUser ( ( Player ) base ) ;
}
2014-05-30 20:49:16 +00:00
if ( base instanceof org . bukkit . OfflinePlayer )
{
return getUser ( ( ( org . bukkit . OfflinePlayer ) base ) . getUniqueId ( ) ) ;
}
if ( base instanceof UUID )
{
return getUser ( ( UUID ) base ) ;
}
2013-10-17 22:55:42 +00:00
if ( base instanceof String )
{
return getOfflineUser ( ( String ) base ) ;
}
return null ;
}
2013-10-16 19:59:39 +00:00
2014-03-03 09:01:07 +00:00
//This will return null if there is not a match.
2011-08-08 12:40:30 +00:00
@Override
2013-10-16 19:59:39 +00:00
public User getUser ( final String base )
2013-10-17 22:55:42 +00:00
{
2014-04-13 05:53:11 +00:00
return getOfflineUser ( base ) ;
}
//This will return null if there is not a match.
@Override
public User getUser ( final UUID base )
{
return userMap . getUser ( base ) ;
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
}
2012-12-20 22:47:49 +00:00
2014-03-03 09:01:07 +00:00
//This will return null if there is not a match.
2012-10-26 20:34:36 +00:00
@Override
public User getOfflineUser ( final String name )
{
2014-05-05 13:48:25 +00:00
final User user = userMap . getUser ( name ) ;
2012-10-26 20:34:36 +00:00
if ( user ! = null & & user . getBase ( ) instanceof OfflinePlayer )
{
2014-04-18 03:48:34 +00:00
//This code should attempt to use the last known name of a user, if Bukkit returns name as null.
final String lastName = user . getLastAccountName ( ) ;
if ( lastName ! = null )
{
( ( OfflinePlayer ) user . getBase ( ) ) . setName ( lastName ) ;
}
else
{
( ( OfflinePlayer ) user . getBase ( ) ) . setName ( name ) ;
}
2012-10-26 20:34:36 +00:00
}
return user ;
}
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
2014-03-03 09:01:07 +00:00
//This will create a new user if there is not a match.
2013-10-16 19:59:39 +00:00
@Override
public User getUser ( final Player base )
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
{
if ( base = = null )
{
return null ;
}
2012-08-31 17:52:40 +00:00
if ( userMap = = null )
{
2012-08-06 01:44:01 +00:00
LOGGER . log ( Level . WARNING , " Essentials userMap not initialized " ) ;
return null ;
}
2012-08-31 17:52:40 +00:00
2014-04-13 05:53:11 +00:00
User user = userMap . getUser ( base . getUniqueId ( ) ) ;
2011-11-28 23:36:36 +00:00
if ( user = = null )
2011-08-11 11:43:04 +00:00
{
2014-02-27 01:55:04 +00:00
if ( getSettings ( ) . isDebug ( ) )
{
2014-03-20 15:54:07 +00:00
LOGGER . log ( Level . INFO , " Constructing new userfile from base player {0} " , base . getName ( ) ) ;
2014-02-27 01:55:04 +00:00
}
2011-11-28 23:36:36 +00:00
user = new User ( base , this ) ;
2011-11-30 19:48:42 +00:00
}
else
{
2011-11-29 16:39:13 +00:00
user . update ( base ) ;
2011-08-11 11:43:04 +00:00
}
2011-11-28 23:36:36 +00:00
return user ;
2011-07-15 14:43:39 +00:00
}
2013-08-13 22:37:33 +00:00
private void handleCrash ( Throwable exception )
{
final PluginManager pm = getServer ( ) . getPluginManager ( ) ;
LOGGER . log ( Level . SEVERE , exception . toString ( ) ) ;
pm . registerEvents ( new Listener ( )
{
@EventHandler ( priority = EventPriority . LOW )
public void onPlayerJoin ( final PlayerJoinEvent event )
{
event . getPlayer ( ) . sendMessage ( " Essentials failed to load, read the log file. " ) ;
}
} , this ) ;
2014-08-16 09:04:13 +00:00
for ( Player player : getOnlinePlayers ( ) )
2013-08-13 22:37:33 +00:00
{
player . sendMessage ( " Essentials failed to load, read the log file. " ) ;
}
this . setEnabled ( false ) ;
}
2011-08-08 12:40:30 +00:00
@Override
2011-07-15 21:39:56 +00:00
public World getWorld ( final String name )
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
{
if ( name . matches ( " [0-9]+ " ) )
{
2011-08-08 12:40:30 +00:00
final int worldId = Integer . parseInt ( name ) ;
if ( worldId < getServer ( ) . getWorlds ( ) . size ( ) )
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
{
2011-08-08 12:40:30 +00:00
return getServer ( ) . getWorlds ( ) . get ( worldId ) ;
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
}
}
2011-07-15 21:39:56 +00:00
return getServer ( ) . getWorld ( name ) ;
2011-05-02 18:22:17 +00:00
}
2011-05-02 22:51:57 +00:00
2011-08-08 12:40:30 +00:00
@Override
2011-07-15 21:39:56 +00:00
public void addReloadListener ( final IConf listener )
2011-05-10 21:14:38 +00:00
{
confList . add ( listener ) ;
}
2011-05-13 20:36:41 +00:00
2011-08-08 12:40:30 +00:00
@Override
2011-05-13 20:36:41 +00:00
public Methods getPaymentMethod ( )
{
return paymentMethod ;
}
2011-05-15 11:40:46 +00:00
2013-06-16 00:07:16 +00:00
@Override
public int broadcastMessage ( final String message )
{
2013-06-16 00:18:35 +00:00
return broadcastMessage ( null , null , message , true ) ;
2013-06-16 00:07:16 +00:00
}
2011-08-08 12:40:30 +00:00
@Override
2011-09-02 14:15:57 +00:00
public int broadcastMessage ( final IUser sender , final String message )
2011-05-28 03:29:11 +00:00
{
2013-06-16 00:18:35 +00:00
return broadcastMessage ( sender , null , message , false ) ;
2013-05-26 16:58:04 +00:00
}
@Override
2013-06-16 00:07:16 +00:00
public int broadcastMessage ( final String permission , final String message )
2013-05-26 16:58:04 +00:00
{
2013-06-16 00:18:35 +00:00
return broadcastMessage ( null , permission , message , false ) ;
2013-05-26 16:58:04 +00:00
}
2013-06-16 00:18:35 +00:00
private int broadcastMessage ( final IUser sender , final String permission , final String message , final boolean keywords )
2013-05-26 16:58:04 +00:00
{
if ( sender ! = null & & sender . isHidden ( ) )
2011-10-30 05:38:17 +00:00
{
2011-09-02 14:15:57 +00:00
return 0 ;
}
2013-06-16 00:07:16 +00:00
2013-06-16 00:18:35 +00:00
IText broadcast = new SimpleTextInput ( message ) ;
2013-06-16 00:07:16 +00:00
2014-07-12 06:03:36 +00:00
final Collection < Player > players = getOnlinePlayers ( ) ;
2011-05-28 03:29:11 +00:00
for ( Player player : players )
{
2011-08-08 12:40:30 +00:00
final User user = getUser ( player ) ;
2013-05-26 16:58:04 +00:00
if ( ( permission = = null & & ( sender = = null | | ! user . isIgnoredPlayer ( sender ) ) )
| | ( permission ! = null & & user . isAuthorized ( permission ) ) )
2011-05-15 11:40:46 +00:00
{
2013-06-16 00:18:35 +00:00
if ( keywords )
{
2013-10-16 19:59:39 +00:00
broadcast = new KeywordReplacer ( broadcast , new CommandSource ( player ) , this , false ) ;
2013-06-16 00:18:35 +00:00
}
for ( String messageText : broadcast . getLines ( ) )
2013-06-16 00:07:16 +00:00
{
2013-08-15 00:53:22 +00:00
user . sendMessage ( messageText ) ;
2013-06-16 00:07:16 +00:00
}
2011-05-15 11:40:46 +00:00
}
2011-05-28 03:29:11 +00:00
}
2011-05-15 11:40:46 +00:00
2014-07-12 06:03:36 +00:00
return players . size ( ) ;
2011-05-28 03:29:11 +00:00
}
2011-06-01 10:40:12 +00:00
2011-08-08 12:40:30 +00:00
@Override
2013-01-31 19:16:09 +00:00
public BukkitTask runTaskAsynchronously ( final Runnable run )
2011-06-01 10:40:12 +00:00
{
2013-01-31 19:03:27 +00:00
return this . getScheduler ( ) . runTaskAsynchronously ( this , run ) ;
}
2013-03-11 02:01:00 +00:00
2013-01-31 19:03:27 +00:00
@Override
public BukkitTask runTaskLaterAsynchronously ( final Runnable run , final long delay )
{
return this . getScheduler ( ) . runTaskLaterAsynchronously ( this , run , delay ) ;
2011-06-01 10:40:12 +00:00
}
2014-05-17 00:12:13 +00:00
@Override
public BukkitTask runTaskTimerAsynchronously ( final Runnable run , final long delay , final long period )
{
return this . getScheduler ( ) . runTaskTimerAsynchronously ( this , run , delay , period ) ;
}
2011-06-01 10:40:12 +00:00
2011-08-08 12:40:30 +00:00
@Override
2011-06-01 10:40:12 +00:00
public int scheduleSyncDelayedTask ( final Runnable run )
{
return this . getScheduler ( ) . scheduleSyncDelayedTask ( this , run ) ;
}
2011-08-08 12:40:30 +00:00
@Override
2011-07-09 11:52:46 +00:00
public int scheduleSyncDelayedTask ( final Runnable run , final long delay )
{
return this . getScheduler ( ) . scheduleSyncDelayedTask ( this , run , delay ) ;
}
2011-08-08 12:40:30 +00:00
@Override
2011-07-15 21:39:56 +00:00
public int scheduleSyncRepeatingTask ( final Runnable run , final long delay , final long period )
2011-06-01 10:40:12 +00:00
{
return this . getScheduler ( ) . scheduleSyncRepeatingTask ( this , run , delay , period ) ;
}
2011-08-08 12:40:30 +00:00
@Override
2011-07-09 11:52:46 +00:00
public TNTExplodeListener getTNTListener ( )
{
return tntListener ;
}
2011-08-08 12:40:30 +00:00
@Override
2011-08-30 21:26:23 +00:00
public PermissionsHandler getPermissionsHandler ( )
2011-07-09 11:52:46 +00:00
{
2011-07-15 21:39:56 +00:00
return permissionsHandler ;
2011-07-09 11:52:46 +00:00
}
2011-08-08 12:40:30 +00:00
2011-11-18 00:43:58 +00:00
@Override
public AlternativeCommandsHandler getAlternativeCommandsHandler ( )
{
return alternativeCommandsHandler ;
}
2011-08-08 12:40:30 +00:00
@Override
2013-07-13 17:52:53 +00:00
public IItemDb getItemDb ( )
2011-07-15 23:33:22 +00:00
{
return itemDb ;
}
2011-08-08 12:40:30 +00:00
@Override
public UserMap getUserMap ( )
{
return userMap ;
}
2011-12-02 00:37:12 +00:00
@Override
public I18n getI18n ( )
{
return i18n ;
}
2012-03-15 00:49:22 +00:00
2012-05-17 10:33:40 +00:00
@Override
public EssentialsTimer getTimer ( )
2012-05-17 10:25:02 +00:00
{
2012-05-17 10:33:40 +00:00
return timer ;
2012-05-17 10:25:02 +00:00
}
2012-03-15 00:49:22 +00:00
2012-05-21 05:13:01 +00:00
@Override
public List < String > getVanishedPlayers ( )
{
return vanishedPlayers ;
}
2014-07-12 06:03:36 +00:00
@Override
public Collection < Player > getOnlinePlayers ( )
{
try
{
return ( Collection < Player > ) getServer ( ) . getOnlinePlayers ( ) ; // Needed for sanity here, the Bukkit API is a bit broken in the sense it only allows subclasses of Player to this list
}
catch ( NoSuchMethodError ex )
{
try
{
return Arrays . asList ( ( Player [ ] ) oldGetOnlinePlayers . invoke ( getServer ( ) ) ) ;
}
catch ( InvocationTargetException ex1 )
{
throw Throwables . propagate ( ex . getCause ( ) ) ;
}
catch ( IllegalAccessException ex1 )
{
throw new RuntimeException ( " Error invoking oldGetOnlinePlayers " , ex1 ) ;
}
}
}
@Override
public Iterable < User > getOnlineUsers ( )
{
return Iterables . transform ( getOnlinePlayers ( ) , new Function < Player , User > ( )
{
@Override
public User apply ( Player player )
{
return getUser ( player ) ;
}
} ) ;
}
2012-08-31 17:52:40 +00:00
2012-03-15 00:49:22 +00:00
private static class EssentialsWorldListener implements Listener , Runnable
{
2012-01-14 22:13:58 +00:00
private transient final IEssentials ess ;
2012-01-20 04:20:37 +00:00
public EssentialsWorldListener ( final IEssentials ess )
2012-01-14 22:13:58 +00:00
{
this . ess = ess ;
}
2012-01-20 04:20:37 +00:00
@EventHandler ( priority = EventPriority . LOW )
public void onWorldLoad ( final WorldLoadEvent event )
2012-01-14 22:13:58 +00:00
{
2012-01-14 22:25:52 +00:00
ess . getJails ( ) . onReload ( ) ;
ess . getWarps ( ) . reloadConfig ( ) ;
for ( IConf iConf : ( ( Essentials ) ess ) . confList )
{
2012-03-15 00:49:22 +00:00
if ( iConf instanceof IEssentialsModule )
{
2012-01-14 22:25:52 +00:00
iConf . reloadConfig ( ) ;
}
}
2012-01-14 22:13:58 +00:00
}
2012-01-20 04:20:37 +00:00
@EventHandler ( priority = EventPriority . LOW )
public void onWorldUnload ( final WorldUnloadEvent event )
2012-01-14 22:13:58 +00:00
{
2012-01-14 22:25:52 +00:00
ess . getJails ( ) . onReload ( ) ;
ess . getWarps ( ) . reloadConfig ( ) ;
for ( IConf iConf : ( ( Essentials ) ess ) . confList )
{
2012-03-15 00:49:22 +00:00
if ( iConf instanceof IEssentialsModule )
{
2012-01-14 22:25:52 +00:00
iConf . reloadConfig ( ) ;
}
}
2012-01-14 22:13:58 +00:00
}
@Override
public void run ( )
{
ess . reload ( ) ;
}
}
2011-03-30 04:03:21 +00:00
}