2011-04-01 20:04:08 +02:00
package com.wimbli.WorldBorder ;
import org.bukkit.Location ;
import org.bukkit.plugin.java.JavaPlugin ;
2011-04-01 20:22:01 +02:00
2011-04-01 20:04:08 +02:00
public class WorldBorder extends JavaPlugin
{
2014-03-11 04:27:42 +01:00
public static volatile WorldBorder plugin = null ;
public static volatile WBCommand wbCommand = null ;
2014-11-25 21:33:51 +01:00
private BlockPlaceListener blockPlaceListener = null ;
2015-05-18 13:18:36 +02:00
private MobSpawnListener mobSpawnListener = null ;
2013-03-31 15:10:23 +02:00
2012-02-08 03:58:28 +01:00
@Override
2011-04-01 20:04:08 +02:00
public void onEnable ( )
{
2014-03-11 04:27:42 +01:00
if ( plugin = = null )
plugin = this ;
if ( wbCommand = = null )
wbCommand = new WBCommand ( ) ;
2012-01-31 17:34:00 +01:00
// Load (or create new) config file
2011-04-01 20:04:08 +02:00
Config . load ( this , false ) ;
// our one real command, though it does also have aliases "wb" and "worldborder"
2014-03-11 04:27:42 +01:00
getCommand ( " wborder " ) . setExecutor ( wbCommand ) ;
2011-05-02 11:14:30 +02:00
2011-12-14 14:18:18 +01:00
// keep an eye on teleports, to redirect them to a spot inside the border if necessary
2012-02-08 03:58:28 +01:00
getServer ( ) . getPluginManager ( ) . registerEvents ( new WBListener ( ) , this ) ;
2014-11-25 21:33:51 +01:00
2015-03-02 01:37:01 +01:00
if ( Config . preventBlockPlace ( ) )
2014-11-25 21:33:51 +01:00
enableBlockPlaceListener ( true ) ;
2012-03-16 06:26:13 +01:00
2015-05-18 13:18:36 +02:00
if ( Config . preventMobSpawn ( ) )
enableMobSpawnListener ( true ) ;
2012-03-16 06:26:13 +01:00
// integrate with DynMap if it's available
DynMapFeatures . setup ( ) ;
// Well I for one find this info useful, so...
Location spawn = getServer ( ) . getWorlds ( ) . get ( 0 ) . getSpawnLocation ( ) ;
2014-02-17 13:37:18 +01:00
Config . log ( " For reference, the main world's spawn location is at X: " + Config . coord . format ( spawn . getX ( ) ) + " Y: " + Config . coord . format ( spawn . getY ( ) ) + " Z: " + Config . coord . format ( spawn . getZ ( ) ) ) ;
2011-04-01 20:04:08 +02:00
}
2012-02-08 03:58:28 +01:00
@Override
2011-04-01 20:04:08 +02:00
public void onDisable ( )
{
2012-03-16 06:26:13 +01:00
DynMapFeatures . removeAllBorders ( ) ;
2011-04-09 16:55:57 +02:00
Config . StopBorderTimer ( ) ;
2011-07-19 07:12:14 +02:00
Config . StoreFillTask ( ) ;
Config . StopFillTask ( ) ;
2011-04-01 20:04:08 +02:00
}
2011-06-07 13:08:21 +02:00
// for other plugins to hook into
2014-03-11 04:27:42 +01:00
public BorderData getWorldBorder ( String worldName )
2011-06-07 13:08:21 +02:00
{
return Config . Border ( worldName ) ;
}
2014-03-11 04:27:42 +01:00
/ * *
* @deprecated Replaced by { @link # getWorldBorder ( String worldName ) } ;
* this method name starts with an uppercase letter , which it shouldn ' t
* /
public BorderData GetWorldBorder ( String worldName )
{
return getWorldBorder ( worldName ) ;
}
2014-11-25 21:33:51 +01:00
2015-05-19 16:17:24 +02:00
public void enableBlockPlaceListener ( boolean enable )
{
2015-03-02 01:37:01 +01:00
if ( enable )
2014-11-25 21:33:51 +01:00
getServer ( ) . getPluginManager ( ) . registerEvents ( this . blockPlaceListener = new BlockPlaceListener ( ) , this ) ;
2015-05-18 13:18:36 +02:00
else if ( blockPlaceListener ! = null )
2014-11-25 21:33:51 +01:00
blockPlaceListener . unregister ( ) ;
}
2015-05-18 13:18:36 +02:00
2015-05-19 16:17:24 +02:00
public void enableMobSpawnListener ( boolean enable )
{
2015-05-18 13:18:36 +02:00
if ( enable )
getServer ( ) . getPluginManager ( ) . registerEvents ( this . mobSpawnListener = new MobSpawnListener ( ) , this ) ;
else if ( mobSpawnListener ! = null )
mobSpawnListener . unregister ( ) ;
}
2011-04-01 20:04:08 +02:00
}