2012-01-26 18:10:49 -05:00
---- Some settings -----
SHOW_PLUGIN_NAMES = true -- If true, plugin name will be shown before commands
-- This is overwritten in the Initialize() function
------------------------
-- Global variables
PLUGIN = { } -- Reference to own plugin object
BannedPlayersIni = { }
WhiteListIni = { }
2013-03-02 09:43:46 -05:00
X = { }
Y = { }
Z = { }
2013-06-30 15:14:22 -04:00
LimitWorldsCuboid = { }
2013-02-01 14:55:42 -05:00
function Initialize ( Plugin )
2012-01-26 15:39:46 -05:00
PLUGIN = Plugin
2013-02-01 14:55:42 -05:00
Plugin : SetName ( " Core " )
2013-06-30 15:14:22 -04:00
Plugin : SetVersion ( 13 )
2012-01-26 15:39:46 -05:00
PluginManager = cRoot : Get ( ) : GetPluginManager ( )
2013-01-13 06:10:26 -05:00
PluginManager : AddHook ( Plugin , cPluginManager.HOOK_PLAYER_JOINED )
PluginManager : AddHook ( Plugin , cPluginManager.HOOK_PLAYER_BREAKING_BLOCK )
PluginManager : AddHook ( Plugin , cPluginManager.HOOK_PLAYER_PLACING_BLOCK )
2012-06-19 17:58:22 -04:00
PluginManager : AddHook ( Plugin , cPluginManager.HOOK_LOGIN )
2013-01-28 11:54:11 -05:00
PluginManager : AddHook ( Plugin , cPluginManager.HOOK_KILLING )
2012-06-19 17:58:22 -04:00
PluginManager : AddHook ( Plugin , cPluginManager.HOOK_CRAFTING_NO_RECIPE )
2012-08-22 19:05:12 -04:00
PluginManager : AddHook ( Plugin , cPluginManager.HOOK_CHAT ) -- used in web_chat.lua
2013-03-24 11:44:44 -04:00
PluginManager : AddHook ( Plugin , cPluginManager.HOOK_CHUNK_GENERATING )
PluginManager : AddHook ( Plugin , cPluginManager.HOOK_PLAYER_MOVING )
2013-06-28 06:18:55 -04:00
PluginManager : BindCommand ( " /listworlds " , " core.listworlds " , HandleListWorldsCommand , " - Shows a list of all the worlds " ) ;
2013-04-03 11:25:25 -04:00
PluginManager : BindCommand ( " /listgroups " , " core.listgroups " , HandleListGroupsCommand , " - Shows a list of all the groups " ) ;
2013-03-24 14:41:19 -04:00
PluginManager : BindCommand ( " /toggledownfall " , " core.toggledownfall " , HandleToggleDownfallCommand , " - Toggles the weather " ) ;
2013-03-02 09:43:46 -05:00
PluginManager : BindCommand ( " /back " , " core.back " , HandleBackCommand , " - Return to your last position " ) ;
PluginManager : BindCommand ( " /save-all " , " core.save-all " , HandleSaveAllCommand , " - Saves all your worlds " ) ;
2013-02-01 14:55:42 -05:00
PluginManager : BindCommand ( " /help " , " core.help " , HandleHelpCommand , " [Page] - Show available commands " ) ;
2013-03-24 11:44:44 -04:00
PluginManager : BindCommand ( " /rank " , " core.rank " , HandleRankCommand , " [Player] [Rank] - to add someone to a group " ) ;
2013-02-01 14:55:42 -05:00
PluginManager : BindCommand ( " /pluginlist " , " core.pluginlist " , HandlePluginListCommand , " - Show list of plugins " ) ;
PluginManager : BindCommand ( " /tp " , " core.teleport " , HandleTPCommand , " [Player] - Teleport yourself to a player " ) ;
PluginManager : BindCommand ( " /item " , " core.item " , HandleItemCommand , " [ItemType/Name] <Amount> - Give yourself an item " ) ;
2013-03-24 11:44:44 -04:00
PluginManager : BindCommand ( " /i " , " core.item " , HandleItemCommand , " " ) ;
2013-02-01 14:55:42 -05:00
PluginManager : BindCommand ( " /list " , " core.playerlist " , HandlePlayerListCommand , " - Shows list of connected players " ) ;
PluginManager : BindCommand ( " /who " , " core.playerlist " , HandlePlayerListCommand , " - Shows list of connected players " ) ;
PluginManager : BindCommand ( " /playerlist " , " core.playerlist " , HandlePlayerListCommand , " - Shows list of connected players " ) ;
PluginManager : BindCommand ( " /motd " , " core.motd " , HandleMOTDCommand , " - Show message of the day " ) ;
PluginManager : BindCommand ( " /reload " , " core.reload " , HandleReloadCommand , " - Reload all plugins " ) ;
PluginManager : BindCommand ( " /stop " , " core.stop " , HandleStopCommand , " - Stops the server " ) ;
PluginManager : BindCommand ( " /time " , " core.time " , HandleTimeCommand , " [Day/Night] - Sets the time of day " ) ;
PluginManager : BindCommand ( " /spawn " , " core.spawn " , HandleSpawnCommand , " - Return to the spawn " ) ;
PluginManager : BindCommand ( " /kick " , " core.kick " , HandleKickCommand , " [Player] - Kick a player " ) ;
PluginManager : BindCommand ( " /ban " , " core.ban " , HandleBanCommand , " [Player] - Ban a player " ) ;
PluginManager : BindCommand ( " /unban " , " core.unban " , HandleUnbanCommand , " [Player] - Unban a player " ) ;
PluginManager : BindCommand ( " /top " , " core.top " , HandleTopCommand , " - Teleport yourself to the top most block " ) ;
PluginManager : BindCommand ( " /gm " , " core.changegm " , HandleChangeGMCommand , " [0|1] - Change your gamemode " ) ;
PluginManager : BindCommand ( " /gotoworld " , " core.gotoworld " , HandleGotoWorldCommand , " [WorldName] - Move to a different world! " ) ;
PluginManager : BindCommand ( " /coords " , " core.coords " , HandleCoordsCommand , " - Show your current server coordinates " ) ;
PluginManager : BindCommand ( " /regeneratechunk " , " core.regeneratechunk " , HandleRegenerateChunkCommand , " <[X] [Z]> - Regenerates a chunk, current or specified " ) ;
PluginManager : BindCommand ( " /viewdistance " , " core.viewdistance " , HandleViewDistanceCommand , " [ " .. cClientHandle.MIN_VIEW_DISTANCE .. " - " .. cClientHandle.MAX_VIEW_DISTANCE .. " ] - Change your view distance " )
2013-02-15 08:00:59 -05:00
InitConsoleCommands ( ) ;
2013-03-24 11:44:44 -04:00
-- Load the settings
IniFile = cIniFile ( " Settings.ini " )
2012-01-26 18:10:49 -05:00
if ( IniFile : ReadFile ( ) == true ) then
2013-03-24 11:44:44 -04:00
HardCore = IniFile : GetValueSet ( " GameMode " , " Hardcore " , " false " )
LimitWorld = IniFile : GetValueSetB ( " Worlds " , " LimitWorld " , true )
2013-06-30 15:14:22 -04:00
LimitWorldWidth = IniFile : GetValueSetI ( " Worlds " , " LimitWorldWidth " , 10 )
2013-03-24 11:44:44 -04:00
SHOW_PLUGIN_NAMES = IniFile : GetValueSetB ( " HelpPlugin " , " ShowPluginNames " , true )
2013-06-30 15:14:22 -04:00
IniFile : WriteFile ( )
2012-01-26 18:10:49 -05:00
end
2013-06-30 15:14:22 -04:00
cRoot : Get ( ) : ForEachWorld (
function ( World )
LimitWorldsCuboid [ World : GetName ( ) ] = cCuboid ( )
LimitWorldsCuboid [ World : GetName ( ) ] . p1 = Vector3i ( math.floor ( World : GetSpawnX ( ) / 16 ) + LimitWorldWidth , 0 , math.floor ( World : GetSpawnZ ( ) / 16 ) + LimitWorldWidth )
LimitWorldsCuboid [ World : GetName ( ) ] . p2 = Vector3i ( math.floor ( World : GetSpawnX ( ) / 16 ) - LimitWorldWidth , 256 , math.floor ( World : GetSpawnZ ( ) / 16 ) - LimitWorldWidth )
LimitWorldsCuboid [ World : GetName ( ) ] : Sort ( )
end
)
2012-01-26 18:10:49 -05:00
-- Load whitelist, and add default values and stuff
2012-09-08 16:49:29 -04:00
WhiteListIni = cIniFile ( Plugin : GetLocalDirectory ( ) .. " /whitelist.ini " )
2012-01-26 18:10:49 -05:00
if ( WhiteListIni : ReadFile ( ) == true ) then
if ( WhiteListIni : GetValueB ( " WhiteListSettings " , " WhiteListOn " , false ) == true ) then
if ( WhiteListIni : GetNumValues ( " WhiteList " ) > 0 ) then
LOGINFO ( " Core: loaded " .. WhiteListIni : GetNumValues ( ' WhiteList ' ) .. " whitelisted players. " )
else
LOGWARN ( " WARNING: WhiteList is on, but there are no people in the whitelist! " )
end
end
else
WhiteListIni : SetValueB ( " WhiteListSettings " , " WhiteListOn " , false )
WhiteListIni : SetValue ( " WhiteList " , " " , " " ) -- So it adds an empty header
WhiteListIni : DeleteValue ( " WhiteList " , " " ) -- And remove the value
WhiteListIni : KeyComment ( " WhiteList " , " PlayerName=1 " )
if ( WhiteListIni : WriteFile ( ) == false ) then
LOGWARN ( " WARNING: Could not write to whitelist.ini " )
end
end
-- Load banned players, and add default values and stuff
2012-09-08 16:49:29 -04:00
BannedPlayersIni = cIniFile ( Plugin : GetLocalDirectory ( ) .. " /banned.ini " )
2012-01-26 18:10:49 -05:00
if ( BannedPlayersIni : ReadFile ( ) == true ) then
if ( BannedPlayersIni : GetNumValues ( " Banned " ) > 0 ) then
LOGINFO ( " Core: loaded " .. BannedPlayersIni : GetNumValues ( " Banned " ) .. " banned players. " )
end
else
BannedPlayersIni : SetValue ( " Banned " , " " , " " ) -- So it adds an empty header
BannedPlayersIni : DeleteValue ( " Banned " , " " ) -- And remove the value
BannedPlayersIni : KeyComment ( " Banned " , " PlayerName=1 " )
if ( BannedPlayersIni : WriteFile ( ) == false ) then
LOGWARN ( " WARNING: Could not write to banned.ini " )
end
end
2012-01-26 15:39:46 -05:00
2013-03-24 11:44:44 -04:00
Plugin : AddWebTab ( " Manage Server " , HandleRequest_ManageServer ) ;
2013-02-15 08:00:59 -05:00
Plugin : AddWebTab ( " Server Settings " , HandleRequest_ServerSettings ) ;
Plugin : AddWebTab ( " Chat " , HandleRequest_Chat ) ;
Plugin : AddWebTab ( " Playerlist " , HandleRequest_PlayerList ) ;
Plugin : AddWebTab ( " Whitelist " , HandleRequest_WhiteList ) ;
Plugin : AddWebTab ( " Permissions " , HandleRequest_Permissions ) ;
Plugin : AddWebTab ( " Manage Plugins " , HandleRequest_ManagePlugins ) ;
2012-01-27 18:47:32 -05:00
2012-01-26 18:10:49 -05:00
LOG ( " Initialized " .. Plugin : GetName ( ) .. " v. " .. Plugin : GetVersion ( ) )
2012-01-26 15:39:46 -05:00
return true
end