2011-09-17 20:59:37 +02:00
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Multiverse 2 Copyright ( c ) the Multiverse Team 2011 . *
* Multiverse 2 is licensed under the BSD License . *
* For more information please check the README . md file included *
* with this project . *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
2011-07-20 16:48:46 +02:00
package com.onarandombox.MultiverseCore ;
2011-09-22 03:26:02 +02:00
import com.fernferret.allpay.AllPay ;
import com.fernferret.allpay.GenericBank ;
2011-10-08 19:42:35 +02:00
import com.onarandombox.MultiverseCore.api.Core ;
2011-09-27 04:21:39 +02:00
import com.onarandombox.MultiverseCore.api.MVPlugin ;
2011-09-22 03:26:02 +02:00
import com.onarandombox.MultiverseCore.commands.* ;
import com.onarandombox.MultiverseCore.configuration.MVConfigMigrator ;
import com.onarandombox.MultiverseCore.configuration.MVCoreConfigMigrator ;
2011-09-25 18:46:07 +02:00
import com.onarandombox.MultiverseCore.destination.* ;
2011-09-22 03:26:02 +02:00
import com.onarandombox.MultiverseCore.listeners.MVEntityListener ;
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener ;
import com.onarandombox.MultiverseCore.listeners.MVPluginListener ;
import com.onarandombox.MultiverseCore.listeners.MVWeatherListener ;
2011-10-08 02:26:40 +02:00
import com.onarandombox.MultiverseCore.utils.* ;
2011-10-08 18:14:52 +02:00
import com.onarandombox.MultiverseCore.utils.MVPermissions ;
2011-09-22 03:26:02 +02:00
import com.pneumaticraft.commandhandler.CommandHandler ;
2011-07-20 16:48:46 +02:00
import org.bukkit.ChatColor ;
2011-07-30 17:17:23 +02:00
import org.bukkit.Location ;
2011-07-20 16:48:46 +02:00
import org.bukkit.World.Environment ;
import org.bukkit.command.Command ;
import org.bukkit.command.CommandSender ;
2011-10-11 03:37:58 +02:00
import org.bukkit.configuration.Configuration ;
2011-10-11 02:12:22 +02:00
import org.bukkit.configuration.file.FileConfiguration ;
2011-10-11 02:40:31 +02:00
import org.bukkit.configuration.file.YamlConfiguration ;
2011-07-20 16:48:46 +02:00
import org.bukkit.entity.Player ;
import org.bukkit.event.Event ;
import org.bukkit.event.Event.Priority ;
2011-10-15 15:47:07 +02:00
import org.bukkit.plugin.PluginDescriptionFile ;
2011-07-20 16:48:46 +02:00
import org.bukkit.plugin.PluginManager ;
import org.bukkit.plugin.java.JavaPlugin ;
2011-09-22 03:26:02 +02:00
import java.io.* ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.HashMap ;
import java.util.logging.Level ;
import java.util.logging.Logger ;
2011-07-20 16:48:46 +02:00
2011-10-08 19:42:35 +02:00
public class MultiverseCore extends JavaPlugin implements MVPlugin , Core {
2011-10-14 03:39:17 +02:00
private final static int Protocol = 6 ;
2011-10-10 19:49:53 +02:00
// Global Multiverse config variable, states whether or not
// Multiverse should stop other plugins from teleporting players
// to worlds.
public static boolean EnforceAccess ;
public static boolean EnforceGameModes ;
2011-10-11 03:37:58 +02:00
public static boolean PrefixChat ;
public static boolean BedRespawn ;
2011-10-15 15:47:07 +02:00
private File testConfigDirectory ;
private PluginDescriptionFile testDescriptionFile ;
2011-10-08 18:57:48 +02:00
2011-10-11 02:40:31 +02:00
2011-09-27 04:21:39 +02:00
@Override
public String dumpVersionInfo ( String buffer ) {
// I'm kinda cheating on this one, since we call the init event.
return buffer ;
}
@Override
public MultiverseCore getCore ( ) {
return this ;
}
@Override
public void setCore ( MultiverseCore core ) {
}
2011-10-08 19:42:35 +02:00
@Override
2011-09-27 04:21:39 +02:00
public int getProtocolVersion ( ) {
return MultiverseCore . Protocol ;
}
2011-07-20 16:48:46 +02:00
// Useless stuff to keep us going.
private static final Logger log = Logger . getLogger ( " Minecraft " ) ;
private static DebugLog debugLog ;
2011-08-01 01:11:59 +02:00
public static boolean MobsDisabledInDefaultWorld = false ;
2011-07-20 16:48:46 +02:00
// Setup our Map for our Commands using the CommandHandler.
private CommandHandler commandHandler ;
2011-08-23 03:53:00 +02:00
private final static String tag = " [Multiverse-Core] " ;
2011-07-20 16:48:46 +02:00
// Multiverse Permissions Handler
2011-08-01 03:18:59 +02:00
private MVPermissions ph ;
2011-07-20 16:48:46 +02:00
// Configurations
2011-10-11 02:40:31 +02:00
private FileConfiguration multiverseConfig = null ;
2011-07-20 16:48:46 +02:00
2011-08-25 04:01:50 +02:00
private WorldManager worldManager = new WorldManager ( this ) ;
2011-09-14 03:54:06 +02:00
2011-07-20 16:48:46 +02:00
// Setup the block/player/entity listener.
2011-08-06 06:35:55 +02:00
private MVPlayerListener playerListener = new MVPlayerListener ( this ) ;
2011-07-20 16:48:46 +02:00
private MVEntityListener entityListener = new MVEntityListener ( this ) ;
private MVPluginListener pluginListener = new MVPluginListener ( this ) ;
2011-08-08 05:03:36 +02:00
private MVWeatherListener weatherListener = new MVWeatherListener ( this ) ;
2011-07-20 16:48:46 +02:00
public UpdateChecker updateCheck ;
2011-08-20 17:07:40 +02:00
public static int GlobalDebug = 0 ;
2011-07-20 16:48:46 +02:00
// HashMap to contain information relating to the Players.
private HashMap < String , MVPlayerSession > playerSessions ;
private GenericBank bank = null ;
2011-09-14 03:54:06 +02:00
private AllPay banker ;
2011-07-30 00:35:27 +02:00
protected MVConfigMigrator migrator = new MVCoreConfigMigrator ( this ) ;
2011-07-20 16:48:46 +02:00
protected int pluginCount ;
2011-07-23 04:57:56 +02:00
private DestinationFactory destFactory ;
2011-08-23 03:53:00 +02:00
private SpoutInterface spoutInterface = null ;
2011-09-14 04:13:27 +02:00
private double allpayversion = 3 ;
private double chversion = 1 ;
2011-09-18 17:48:46 +02:00
private MVMessaging messaging ;
2011-07-20 16:48:46 +02:00
@Override
public void onLoad ( ) {
// Create our DataFolder
getDataFolder ( ) . mkdirs ( ) ;
// Setup our Debug Log
debugLog = new DebugLog ( " Multiverse-Core " , getDataFolder ( ) + File . separator + " debug.log " ) ;
}
2011-07-21 05:44:43 +02:00
2011-10-15 15:47:07 +02:00
@Override
public File getDataFolder ( ) {
if ( this . testConfigDirectory ! = null ) {
return this . testConfigDirectory ;
}
return super . getDataFolder ( ) ;
}
@Override
public PluginDescriptionFile getDescription ( ) {
if ( this . testDescriptionFile ! = null ) {
return this . testDescriptionFile ;
}
return super . getDescription ( ) ; //To change body of overridden methods use File | Settings | File Templates.
}
public void setTestMode ( File configDir , PluginDescriptionFile descriptionFile ) {
this . testConfigDirectory = configDir ;
this . testDescriptionFile = descriptionFile ;
}
2011-10-11 02:40:31 +02:00
public FileConfiguration getMVConfiguration ( ) {
return this . multiverseConfig ;
}
2011-07-20 16:48:46 +02:00
public GenericBank getBank ( ) {
return this . bank ;
}
public void onEnable ( ) {
2011-09-14 03:54:06 +02:00
// Perform initial checks for AllPay
2011-09-14 04:13:27 +02:00
if ( ! this . validateAllpay ( ) | | ! this . validateCH ( ) ) {
2011-09-14 03:54:06 +02:00
this . getServer ( ) . getPluginManager ( ) . disablePlugin ( this ) ;
return ;
}
this . banker = new AllPay ( this , tag + " " ) ;
2011-07-20 16:48:46 +02:00
// Output a little snippet to show it's enabled.
2011-10-08 22:59:47 +02:00
this . log ( Level . INFO , " - Version " + this . getDescription ( ) . getVersion ( ) + " (API v " + Protocol + " ) Enabled - By " + getAuthors ( ) ) ;
2011-07-31 15:41:09 +02:00
this . checkServerProps ( ) ;
2011-09-18 19:45:06 +02:00
2011-07-20 16:48:46 +02:00
this . registerEvents ( ) ;
// Setup Permissions, we'll do an initial check for the Permissions plugin then fall back on isOP().
this . ph = new MVPermissions ( this ) ;
this . bank = this . banker . loadEconPlugin ( ) ;
2011-07-21 05:44:43 +02:00
2011-07-20 16:48:46 +02:00
// Setup the command manager
this . commandHandler = new CommandHandler ( this , this . ph ) ;
// Call the Function to assign all the Commands to their Class.
this . registerCommands ( ) ;
2011-09-18 19:45:06 +02:00
// Initialize the Destination factor AFTER the commands
this . initializeDestinationFactory ( ) ;
2011-07-20 16:48:46 +02:00
this . playerSessions = new HashMap < String , MVPlayerSession > ( ) ;
// Start the Update Checker
// updateCheck = new UpdateChecker(this.getDescription().getName(), this.getDescription().getVersion());
// Call the Function to load all the Worlds and setup the HashMap
// When called with null, it tries to load ALL
// this function will be called every time a plugin registers a new envtype with MV
// Setup & Load our Configuration files.
loadConfigs ( ) ;
2011-10-11 02:40:31 +02:00
if ( this . multiverseConfig ! = null ) {
2011-08-25 01:25:30 +02:00
this . worldManager . loadWorlds ( true ) ;
2011-07-20 16:48:46 +02:00
} else {
2011-07-30 17:17:23 +02:00
this . log ( Level . SEVERE , " Your configs were not loaded. Very little will function in Multiverse. " ) ;
2011-07-20 16:48:46 +02:00
}
}
2011-09-14 03:54:06 +02:00
private boolean validateAllpay ( ) {
try {
this . banker = new AllPay ( this , " Verify " ) ;
if ( this . banker . getVersion ( ) > = allpayversion ) {
return true ;
} else {
log . info ( tag + " - Version " + this . getDescription ( ) . getVersion ( ) + " was NOT ENABLED!!! " ) ;
2011-09-18 20:31:41 +02:00
log . info ( tag + " A plugin that has loaded before " + this . getDescription ( ) . getName ( ) + " has an incompatible version of AllPay! " ) ;
2011-09-14 03:54:06 +02:00
log . info ( tag + " The Following Plugins MAY out of date! " ) ;
log . info ( tag + " This plugin needs AllPay v " + allpayversion + " or higher and another plugin has loaded v " + this . banker . getVersion ( ) + " ! " ) ;
log . info ( tag + AllPay . pluginsThatUseUs . toString ( ) ) ;
return false ;
}
} catch ( Throwable t ) {
}
log . info ( tag + " - Version " + this . getDescription ( ) . getVersion ( ) + " was NOT ENABLED!!! " ) ;
2011-09-18 20:31:41 +02:00
log . info ( tag + " A plugin that has loaded before " + this . getDescription ( ) . getName ( ) + " has an incompatible version of AllPay! " ) ;
2011-09-14 03:54:06 +02:00
log . info ( tag + " Check the logs for [AllPay] - Version ... for PLUGIN NAME to find the culprit! Then Yell at that dev! " ) ;
log . info ( tag + " Or update that plugin :P " ) ;
log . info ( tag + " This plugin needs AllPay v " + allpayversion + " or higher! " ) ;
return false ;
}
2011-09-17 19:12:02 +02:00
2011-09-14 04:13:27 +02:00
private boolean validateCH ( ) {
try {
this . commandHandler = new CommandHandler ( this , null ) ;
if ( this . commandHandler . getVersion ( ) > = chversion ) {
return true ;
} else {
log . info ( tag + " - Version " + this . getDescription ( ) . getVersion ( ) + " was NOT ENABLED!!! " ) ;
2011-09-18 20:31:41 +02:00
log . info ( tag + " A plugin that has loaded before " + this . getDescription ( ) . getName ( ) + " has an incompatible version of CommandHandler (an internal library)! " ) ;
2011-09-14 04:13:27 +02:00
log . info ( tag + " Please contact this plugin author!!!!!!! " ) ;
log . info ( tag + " This plugin needs CommandHandler v " + chversion + " or higher and another plugin has loaded v " + this . commandHandler . getVersion ( ) + " ! " ) ;
return false ;
}
} catch ( Throwable t ) {
}
log . info ( tag + " - Version " + this . getDescription ( ) . getVersion ( ) + " was NOT ENABLED!!! " ) ;
2011-09-18 20:31:41 +02:00
log . info ( tag + " A plugin that has loaded before " + this . getDescription ( ) . getName ( ) + " has an incompatible version of CommandHandler (an internal library)! " ) ;
2011-09-14 04:13:27 +02:00
log . info ( tag + " Please contact this plugin author!!!!!!! " ) ;
2011-09-22 03:26:02 +02:00
log . info ( tag + " This plugin needs CommandHandler v " + chversion + " or higher! " ) ;
2011-09-14 04:13:27 +02:00
return false ;
}
2011-09-14 03:54:06 +02:00
2011-07-23 04:57:56 +02:00
private void initializeDestinationFactory ( ) {
this . destFactory = new DestinationFactory ( this ) ;
this . destFactory . registerDestinationType ( WorldDestination . class , " " ) ;
this . destFactory . registerDestinationType ( WorldDestination . class , " w " ) ;
2011-07-23 07:19:31 +02:00
this . destFactory . registerDestinationType ( ExactDestination . class , " e " ) ;
2011-08-07 16:29:23 +02:00
this . destFactory . registerDestinationType ( PlayerDestination . class , " pl " ) ;
2011-08-09 06:02:56 +02:00
this . destFactory . registerDestinationType ( CannonDestination . class , " ca " ) ;
2011-09-22 01:45:10 +02:00
this . destFactory . registerDestinationType ( BedDestination . class , " b " ) ;
2011-07-23 04:57:56 +02:00
}
2011-09-22 03:26:02 +02:00
/** Function to Register all the Events needed. */
2011-07-20 16:48:46 +02:00
private void registerEvents ( ) {
2011-10-15 15:47:07 +02:00
System . out . print ( getServer ( ) . getName ( ) ) ;
2011-07-20 16:48:46 +02:00
PluginManager pm = getServer ( ) . getPluginManager ( ) ;
// pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Highest, this); // Low so it acts above any other.
pm . registerEvent ( Event . Type . PLAYER_TELEPORT , this . playerListener , Priority . Highest , this ) ; // Cancel Teleports if needed.
pm . registerEvent ( Event . Type . PLAYER_JOIN , this . playerListener , Priority . Normal , this ) ; // To create the Player Session
pm . registerEvent ( Event . Type . PLAYER_QUIT , this . playerListener , Priority . Normal , this ) ; // To remove Player Sessions
pm . registerEvent ( Event . Type . PLAYER_RESPAWN , this . playerListener , Priority . Low , this ) ; // Let plugins which specialize in (re)spawning carry more weight.
pm . registerEvent ( Event . Type . PLAYER_CHAT , this . playerListener , Priority . Normal , this ) ; // To prepend the world name
2011-09-18 21:22:48 +02:00
pm . registerEvent ( Event . Type . PLAYER_PORTAL , this . playerListener , Priority . Monitor , this ) ; // To switch gamemode
2011-10-04 01:43:57 +02:00
pm . registerEvent ( Event . Type . PLAYER_CHANGED_WORLD , this . playerListener , Priority . Monitor , this ) ; // To switch gamemode
2011-07-20 16:48:46 +02:00
pm . registerEvent ( Event . Type . ENTITY_REGAIN_HEALTH , this . entityListener , Priority . Normal , this ) ;
pm . registerEvent ( Event . Type . ENTITY_DAMAGE , this . entityListener , Priority . Normal , this ) ; // To Allow/Disallow fake PVP
pm . registerEvent ( Event . Type . CREATURE_SPAWN , this . entityListener , Priority . Normal , this ) ; // To prevent all or certain animals/monsters from spawning.
2011-09-29 03:56:41 +02:00
pm . registerEvent ( Event . Type . FOOD_LEVEL_CHANGE , this . entityListener , Priority . Normal , this ) ;
2011-07-20 16:48:46 +02:00
pm . registerEvent ( Event . Type . PLUGIN_ENABLE , this . pluginListener , Priority . Monitor , this ) ;
pm . registerEvent ( Event . Type . PLUGIN_DISABLE , this . pluginListener , Priority . Monitor , this ) ;
2011-08-09 02:17:55 +02:00
2011-08-08 05:03:36 +02:00
pm . registerEvent ( Event . Type . WEATHER_CHANGE , this . weatherListener , Priority . Normal , this ) ;
pm . registerEvent ( Event . Type . THUNDER_CHANGE , this . weatherListener , Priority . Normal , this ) ;
2011-07-20 16:48:46 +02:00
}
2011-09-22 03:26:02 +02:00
/** Load the Configuration files OR create the default config files. */
2011-07-20 16:48:46 +02:00
public void loadConfigs ( ) {
// Now grab the Configuration Files.
2011-10-11 02:40:31 +02:00
this . multiverseConfig = YamlConfiguration . loadConfiguration ( new File ( getDataFolder ( ) , " config.yml " ) ) ;
2011-10-11 03:37:58 +02:00
Configuration coreDefaults = YamlConfiguration . loadConfiguration ( this . getClass ( ) . getResourceAsStream ( " /defaults/config.yml " ) ) ;
this . multiverseConfig . setDefaults ( coreDefaults ) ;
2011-10-13 03:50:03 +02:00
this . multiverseConfig . options ( ) . copyDefaults ( true ) ;
2011-08-25 03:05:20 +02:00
this . worldManager . loadWorldConfig ( new File ( getDataFolder ( ) , " worlds.yml " ) ) ;
2011-07-20 16:48:46 +02:00
// Setup the Debug option, we'll default to false because this option will not be in the default config.
2011-10-11 03:37:58 +02:00
GlobalDebug = this . multiverseConfig . getInt ( " debug " , 0 ) ;
2011-10-13 03:50:03 +02:00
// Lets cache these values due to the fact that they will be accessed many times.
2011-10-11 03:37:58 +02:00
EnforceAccess = this . multiverseConfig . getBoolean ( " enforceaccess " , false ) ;
EnforceGameModes = this . multiverseConfig . getBoolean ( " enforcegamemodes " , true ) ;
PrefixChat = this . multiverseConfig . getBoolean ( " worldnameprefix " , true ) ;
BedRespawn = this . multiverseConfig . getBoolean ( " bedrespawn " , true ) ;
2011-09-18 17:48:46 +02:00
this . messaging = new MVMessaging ( this ) ;
2011-10-11 03:37:58 +02:00
this . messaging . setCooldown ( this . multiverseConfig . getInt ( " messagecooldown " , 5000 ) ) ;
2011-10-12 22:50:04 +02:00
this . saveMVConfigs ( ) ;
2011-09-18 17:48:46 +02:00
}
2011-09-22 03:26:02 +02:00
public MVMessaging getMessaging ( ) {
2011-09-18 17:48:46 +02:00
return this . messaging ;
2011-07-20 16:48:46 +02:00
}
2011-09-22 03:26:02 +02:00
/** Register Multiverse-Core commands to Command Manager. */
2011-07-20 16:48:46 +02:00
private void registerCommands ( ) {
// Intro Commands
2011-08-01 01:11:59 +02:00
this . commandHandler . registerCommand ( new HelpCommand ( this ) ) ;
2011-07-20 16:48:46 +02:00
this . commandHandler . registerCommand ( new VersionCommand ( this ) ) ;
this . commandHandler . registerCommand ( new ListCommand ( this ) ) ;
this . commandHandler . registerCommand ( new InfoCommand ( this ) ) ;
this . commandHandler . registerCommand ( new CreateCommand ( this ) ) ;
this . commandHandler . registerCommand ( new ImportCommand ( this ) ) ;
this . commandHandler . registerCommand ( new ReloadCommand ( this ) ) ;
this . commandHandler . registerCommand ( new SetSpawnCommand ( this ) ) ;
this . commandHandler . registerCommand ( new CoordCommand ( this ) ) ;
this . commandHandler . registerCommand ( new TeleportCommand ( this ) ) ;
this . commandHandler . registerCommand ( new WhoCommand ( this ) ) ;
this . commandHandler . registerCommand ( new SpawnCommand ( this ) ) ;
// Dangerous Commands
this . commandHandler . registerCommand ( new UnloadCommand ( this ) ) ;
2011-10-08 20:18:08 +02:00
this . commandHandler . registerCommand ( new LoadCommand ( this ) ) ;
2011-07-20 16:48:46 +02:00
this . commandHandler . registerCommand ( new RemoveCommand ( this ) ) ;
this . commandHandler . registerCommand ( new DeleteCommand ( this ) ) ;
this . commandHandler . registerCommand ( new ConfirmCommand ( this ) ) ;
// Modification commands
2011-08-01 01:11:59 +02:00
this . commandHandler . registerCommand ( new ModifyCommand ( this ) ) ;
2011-07-20 16:48:46 +02:00
this . commandHandler . registerCommand ( new PurgeCommand ( this ) ) ;
this . commandHandler . registerCommand ( new ModifyAddCommand ( this ) ) ;
this . commandHandler . registerCommand ( new ModifySetCommand ( this ) ) ;
this . commandHandler . registerCommand ( new ModifyRemoveCommand ( this ) ) ;
this . commandHandler . registerCommand ( new ModifyClearCommand ( this ) ) ;
2011-10-10 19:31:22 +02:00
this . commandHandler . registerCommand ( new ConfigCommand ( this ) ) ;
2011-07-20 16:48:46 +02:00
// Misc Commands
this . commandHandler . registerCommand ( new EnvironmentCommand ( this ) ) ;
2011-08-20 17:07:40 +02:00
this . commandHandler . registerCommand ( new DebugCommand ( this ) ) ;
2011-08-22 00:57:17 +02:00
this . commandHandler . registerCommand ( new GeneratorCommand ( this ) ) ;
2011-10-10 20:28:02 +02:00
this . commandHandler . registerCommand ( new CheckCommand ( this ) ) ;
2011-07-20 16:48:46 +02:00
}
2011-09-22 03:26:02 +02:00
/** Deprecated, please use WorldManager.loadWorlds(Boolean forceLoad) now. */
2011-08-25 01:25:30 +02:00
@Deprecated
2011-07-20 16:48:46 +02:00
public void loadWorlds ( boolean forceLoad ) {
2011-08-25 01:25:30 +02:00
this . worldManager . loadWorlds ( true ) ;
2011-07-20 16:48:46 +02:00
}
/ * *
2011-09-22 03:26:02 +02:00
* Deprecated , please use WorldManager . addWorld ( String name , Environment env , String seedString , String generator )
* now .
2011-07-20 16:48:46 +02:00
* /
2011-08-25 01:25:30 +02:00
@Deprecated
2011-07-20 16:48:46 +02:00
public boolean addWorld ( String name , Environment env , String seedString , String generator ) {
2011-08-25 01:25:30 +02:00
return this . worldManager . addWorld ( name , env , seedString , generator ) ;
2011-07-20 16:48:46 +02:00
}
2011-10-08 20:36:57 +02:00
/** Deprecated, please use WorldManager.unloadWorld(String name) now. */
2011-08-25 01:25:30 +02:00
@Deprecated
2011-07-21 22:07:57 +02:00
public boolean removeWorldFromList ( String name ) {
2011-10-08 20:36:57 +02:00
return this . worldManager . unloadWorld ( name ) ;
2011-07-20 16:48:46 +02:00
}
2011-09-22 03:26:02 +02:00
/** Deprecated, please use WorldManager.removeWorldFromConfig(String name) now. */
2011-08-25 01:25:30 +02:00
@Deprecated
2011-07-21 22:07:57 +02:00
public boolean removeWorldFromConfig ( String name ) {
2011-09-14 03:54:06 +02:00
return this . worldManager . removeWorldFromConfig ( name ) ;
2011-07-20 16:48:46 +02:00
}
2011-09-22 03:26:02 +02:00
/** Deprecated please use WorldManager.deleteWorld(String name) now. */
2011-08-25 01:25:30 +02:00
@Deprecated
2011-08-09 02:17:55 +02:00
public Boolean deleteWorld ( String name ) {
2011-08-25 01:25:30 +02:00
return this . worldManager . deleteWorld ( name ) ;
2011-07-20 16:48:46 +02:00
}
2011-09-22 03:26:02 +02:00
/** What happens when the plugin gets disabled... */
2011-07-20 16:48:46 +02:00
public void onDisable ( ) {
debugLog . close ( ) ;
this . banker = null ;
this . bank = null ;
log ( Level . INFO , " - Disabled " ) ;
}
2011-10-08 19:42:35 +02:00
@Override
2011-07-20 16:48:46 +02:00
public MVPlayerSession getPlayerSession ( Player player ) {
if ( this . playerSessions . containsKey ( player . getName ( ) ) ) {
return this . playerSessions . get ( player . getName ( ) ) ;
} else {
2011-10-11 03:37:58 +02:00
this . playerSessions . put ( player . getName ( ) , new MVPlayerSession ( player , this . multiverseConfig , this ) ) ;
2011-07-20 16:48:46 +02:00
return this . playerSessions . get ( player . getName ( ) ) ;
}
}
/ * *
* Grab and return the Teleport class .
2011-09-17 19:12:02 +02:00
*
2011-07-20 16:48:46 +02:00
* @return
* /
2011-10-08 02:47:39 +02:00
public SafeTTeleporter getTeleporter ( ) {
return new SafeTTeleporter ( this ) ;
2011-07-20 16:48:46 +02:00
}
2011-09-22 06:15:16 +02:00
/ * *
* Grab the Permissions Handler for Multiverse
*
* @return A valid { @link MVPermissions } .
* /
2011-10-08 18:14:52 +02:00
public MVPermissions getMVPerms ( ) {
2011-07-20 16:48:46 +02:00
return this . ph ;
}
2011-10-08 18:14:52 +02:00
@Deprecated
public com . onarandombox . MultiverseCore . MVPermissions getPermissions ( ) {
2011-10-08 18:57:48 +02:00
return new com . onarandombox . MultiverseCore . MVPermissions ( this ) ;
2011-10-08 18:14:52 +02:00
}
2011-10-08 18:57:48 +02:00
2011-08-25 01:25:30 +02:00
@Deprecated
2011-07-20 16:48:46 +02:00
public PurgeWorlds getWorldPurger ( ) {
2011-08-25 03:05:20 +02:00
return this . worldManager . getWorldPurger ( ) ;
2011-07-20 16:48:46 +02:00
}
2011-09-22 03:26:02 +02:00
/** onCommand */
2011-07-20 16:48:46 +02:00
@Override
public boolean onCommand ( CommandSender sender , Command command , String commandLabel , String [ ] args ) {
2011-09-18 17:48:46 +02:00
if ( ! this . isEnabled ( ) ) {
2011-07-20 16:48:46 +02:00
sender . sendMessage ( " This plugin is Disabled! " ) ;
return true ;
}
ArrayList < String > allArgs = new ArrayList < String > ( Arrays . asList ( args ) ) ;
allArgs . add ( 0 , command . getName ( ) ) ;
return this . commandHandler . locateAndRunCommand ( sender , allArgs ) ;
}
/ * *
2011-09-22 03:26:02 +02:00
* Print messages to the server Log as well as to our DebugLog . ' debugLog ' is used to seperate Heroes information
* from the Servers Log Output .
2011-09-17 19:12:02 +02:00
*
2011-07-20 16:48:46 +02:00
* @param level
* @param msg
* /
public void log ( Level level , String msg ) {
2011-08-23 03:53:00 +02:00
staticLog ( level , msg ) ;
}
public static void staticLog ( Level level , String msg ) {
2011-08-20 17:07:40 +02:00
if ( level = = Level . FINE & & GlobalDebug > = 1 ) {
2011-08-23 03:53:00 +02:00
staticDebugLog ( Level . INFO , msg ) ;
2011-08-20 17:07:40 +02:00
return ;
} else if ( level = = Level . FINER & & GlobalDebug > = 2 ) {
2011-08-23 03:53:00 +02:00
staticDebugLog ( Level . INFO , msg ) ;
2011-08-20 17:07:40 +02:00
return ;
} else if ( level = = Level . FINEST & & GlobalDebug > = 3 ) {
2011-08-23 03:53:00 +02:00
staticDebugLog ( Level . INFO , msg ) ;
2011-08-20 17:07:40 +02:00
return ;
} else if ( level ! = Level . FINE & & level ! = Level . FINER & & level ! = Level . FINEST ) {
2011-08-23 03:53:00 +02:00
log . log ( level , tag + " " + msg ) ;
debugLog . log ( level , tag + " " + msg ) ;
2011-08-20 17:07:40 +02:00
}
2011-07-20 16:48:46 +02:00
}
/ * *
2011-09-22 03:26:02 +02:00
* Print messages to the Debug Log , if the servers in Debug Mode then we also wan ' t to print the messages to the
* standard Server Console .
2011-09-17 19:12:02 +02:00
*
2011-07-20 16:48:46 +02:00
* @param level
* @param msg
* /
2011-08-23 03:53:00 +02:00
public static void staticDebugLog ( Level level , String msg ) {
2011-08-20 17:07:40 +02:00
log . log ( level , " [MVCore-Debug] " + msg ) ;
debugLog . log ( level , " [MVCore-Debug] " + msg ) ;
2011-07-20 16:48:46 +02:00
}
/ * *
* Parse the Authors Array into a readable String with ',' and ' and ' .
2011-09-17 19:12:02 +02:00
*
2011-07-20 16:48:46 +02:00
* @return
* /
private String getAuthors ( ) {
String authors = " " ;
ArrayList < String > auths = this . getDescription ( ) . getAuthors ( ) ;
2011-10-15 15:47:07 +02:00
if ( auths . size ( ) = = 0 ) {
return " " ;
}
2011-07-20 16:48:46 +02:00
if ( auths . size ( ) = = 1 ) {
return auths . get ( 0 ) ;
}
for ( int i = 0 ; i < auths . size ( ) ; i + + ) {
if ( i = = this . getDescription ( ) . getAuthors ( ) . size ( ) - 1 ) {
authors + = " and " + this . getDescription ( ) . getAuthors ( ) . get ( i ) ;
} else {
authors + = " , " + this . getDescription ( ) . getAuthors ( ) . get ( i ) ;
}
}
return authors . substring ( 2 ) ;
}
public CommandHandler getCommandHandler ( ) {
return this . commandHandler ;
}
public String getTag ( ) {
2011-08-25 01:25:30 +02:00
return MultiverseCore . tag ;
2011-07-20 16:48:46 +02:00
}
/ * *
* This code should get moved somewhere more appropriate , but for now , it ' s here .
2011-09-17 19:12:02 +02:00
*
2011-07-20 16:48:46 +02:00
* @param env
2011-09-22 03:26:02 +02:00
*
2011-07-20 16:48:46 +02:00
* @return
* /
public Environment getEnvFromString ( String env ) {
// Don't reference the enum directly as there aren't that many, and we can be more forgiving to users this way
if ( env . equalsIgnoreCase ( " HELL " ) | | env . equalsIgnoreCase ( " NETHER " ) )
env = " NETHER " ;
if ( env . equalsIgnoreCase ( " SKYLANDS " ) | | env . equalsIgnoreCase ( " SKYLAND " ) | | env . equalsIgnoreCase ( " STARWARS " ) )
env = " SKYLANDS " ;
if ( env . equalsIgnoreCase ( " NORMAL " ) | | env . equalsIgnoreCase ( " WORLD " ) )
env = " NORMAL " ;
try {
2011-09-22 03:26:02 +02:00
// If the value wasn't found, maybe it's new, try checking the enum directly.
2011-07-20 16:48:46 +02:00
return Environment . valueOf ( env ) ;
} catch ( IllegalArgumentException e ) {
return null ;
}
}
public void showNotMVWorldMessage ( CommandSender sender , String worldName ) {
sender . sendMessage ( " Multiverse doesn't know about " + ChatColor . DARK_AQUA + worldName + ChatColor . WHITE + " yet. " ) ;
sender . sendMessage ( " Type " + ChatColor . DARK_AQUA + " /mv import ? " + ChatColor . WHITE + " for help! " ) ;
}
public void removePlayerSession ( Player player ) {
if ( this . playerSessions . containsKey ( player . getName ( ) ) ) {
this . playerSessions . remove ( player . getName ( ) ) ;
}
}
/ * *
* Returns the number of plugins that have specifically hooked into core .
2011-09-17 19:12:02 +02:00
*
2011-07-20 16:48:46 +02:00
* @return
* /
public int getPluginCount ( ) {
return this . pluginCount ;
}
2011-09-22 03:26:02 +02:00
/** Increments the number of plugins that have specifically hooked into core. */
2011-07-20 16:48:46 +02:00
public void incrementPluginCount ( ) {
this . pluginCount + = 1 ;
}
2011-09-22 03:26:02 +02:00
/** Decrements the number of plugins that have specifically hooked into core. */
2011-07-20 16:48:46 +02:00
public void decrementPluginCount ( ) {
this . pluginCount - = 1 ;
}
public AllPay getBanker ( ) {
return this . banker ;
}
public void setBank ( GenericBank bank ) {
this . bank = bank ;
}
2011-07-23 04:57:56 +02:00
2011-10-08 18:57:48 +02:00
public DestinationFactory getDestFactory ( ) {
2011-07-23 04:57:56 +02:00
return this . destFactory ;
}
2011-07-30 17:17:23 +02:00
2011-10-08 18:57:48 +02:00
@Deprecated
public com . onarandombox . utils . DestinationFactory getDestinationFactory ( ) {
2011-10-08 19:57:50 +02:00
return new com . onarandombox . utils . DestinationFactory ( this ) ;
2011-10-08 18:57:48 +02:00
}
2011-07-30 17:17:23 +02:00
/ * *
* This is a convenience method to allow the QueuedCommand system to call it . You should NEVER call this directly .
2011-09-17 19:12:02 +02:00
*
2011-07-30 17:17:23 +02:00
* @param p Player
* @param l The potentially unsafe location .
* /
2011-10-14 03:38:44 +02:00
public void teleportPlayer ( CommandSender teleporter , Player p , Location l ) {
// This command is the override, and MUST NOT TELEPORT SAFELY
this . getTeleporter ( ) . safelyTeleport ( teleporter , p , l , false ) ;
2011-07-30 17:17:23 +02:00
}
2011-08-04 02:15:21 +02:00
2011-07-31 15:41:09 +02:00
private void checkServerProps ( ) {
File serverFolder = new File ( this . getDataFolder ( ) . getAbsolutePath ( ) ) . getParentFile ( ) . getParentFile ( ) ;
File serverProperties = new File ( serverFolder . getAbsolutePath ( ) + File . separator + " server.properties " ) ;
try {
FileInputStream fileStream = new FileInputStream ( serverProperties ) ;
DataInputStream in = new DataInputStream ( fileStream ) ;
BufferedReader br = new BufferedReader ( new InputStreamReader ( in ) ) ;
String propLine ;
while ( ( propLine = br . readLine ( ) ) ! = null ) {
// Print the content on the console
if ( propLine . matches ( " .*spawn-monsters.* " ) & & ! propLine . matches ( " .*spawn-monsters \\ s*= \\ s*true.* " ) ) {
this . log ( Level . SEVERE , " Monster spawning has been DISABLED. " ) ;
this . log ( Level . SEVERE , " In order to let Multiverse fully control your worlds: " ) ;
this . log ( Level . SEVERE , " Please set 'spawn-monsters=true' in your server.properties file! " ) ;
2011-08-01 01:11:59 +02:00
MultiverseCore . MobsDisabledInDefaultWorld = true ;
2011-07-31 15:41:09 +02:00
}
}
} catch ( IOException e ) {
// This should never happen...
this . log ( Level . SEVERE , e . getMessage ( ) ) ;
}
2011-07-31 03:09:30 +02:00
}
2011-08-13 22:58:43 +02:00
2011-08-23 03:53:00 +02:00
public void setSpout ( ) {
this . spoutInterface = new SpoutInterface ( ) ;
2011-08-21 20:10:18 +02:00
this . commandHandler . registerCommand ( new SpoutCommand ( this ) ) ;
2011-08-13 22:58:43 +02:00
}
2011-08-23 03:53:00 +02:00
public SpoutInterface getSpout ( ) {
return this . spoutInterface ;
2011-08-13 22:58:43 +02:00
}
2011-08-23 03:53:00 +02:00
2011-10-08 18:57:48 +02:00
public WorldManager getMVWorldManager ( ) {
2011-08-25 01:25:30 +02:00
return this . worldManager ;
}
2011-10-08 18:57:48 +02:00
@Deprecated
public com . onarandombox . utils . WorldManager getWorldManager ( ) {
return new com . onarandombox . utils . WorldManager ( this ) ;
}
2011-09-15 04:06:03 +02:00
public MVPlayerListener getPlayerListener ( ) {
return this . playerListener ;
}
2011-10-12 22:50:04 +02:00
public boolean loadMVConfigs ( ) {
return false ;
}
public boolean saveMVConfigs ( ) {
boolean retVal = true ;
try {
this . multiverseConfig . save ( new File ( getDataFolder ( ) , " config.yml " ) ) ;
} catch ( IOException e ) {
retVal = false ;
this . log ( Level . SEVERE , " Could not save Multiverse config.yml config. Please check your file permissions. " ) ;
}
2011-10-13 22:37:53 +02:00
this . worldManager . saveWorldsConfig ( ) ;
2011-10-12 22:50:04 +02:00
return retVal ;
}
2011-07-20 16:48:46 +02:00
}