1
0

Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Tiger Wang 2013-08-13 15:44:29 +01:00
commit 0ac24a98e4
52 changed files with 31477 additions and 31022 deletions

View File

@ -37,8 +37,6 @@ all: MCServer/MCServer
# -- according to http://stackoverflow.com/questions/6183899/undefined-reference-to-dlopen, libs must come after all sources # -- according to http://stackoverflow.com/questions/6183899/undefined-reference-to-dlopen, libs must come after all sources
# BUILDDIR ... folder where the intermediate object files are built # BUILDDIR ... folder where the intermediate object files are built
LNK_LIBS = -lstdc++ -ldl
ifeq ($(release),1) ifeq ($(release),1)
################ ################
# release build - fastest run-time, no gdb support # release build - fastest run-time, no gdb support
@ -83,6 +81,23 @@ endif
###################################################
# Set the link libraries based on the OS
# Linux uses libdl
# FreeBSD uses libltdl
# TODO: other OSs?
UNAME := $(shell uname -s)
ifeq ($(UNAME),Linux)
LNK_LIBS = -lstdc++ -ldl
else
LNK_LIBS = -lstdc++ -lltdl
endif
################ ################
# 32-bit build override in 64-bit build environments # 32-bit build override in 64-bit build environments
# - so that BearBin doesn't need to modify his makefile after each makefile change :) # - so that BearBin doesn't need to modify his makefile after each makefile change :)

View File

@ -8,6 +8,7 @@ Commands
* /back * /back
* /ban * /ban
* /clear
* /downfall * /downfall
* /give * /give
* /gm * /gm
@ -15,6 +16,7 @@ Commands
* /help * /help
* /i * /i
* /item * /item
* /kill
* /kick * /kick
* /locate * /locate
* /me * /me

View File

@ -1,9 +1,10 @@
function HandleBackCommand( Split, Player ) function HandleBackCommand( Split, Player )
if BackCoords[Player:GetName()] == nil then if BackCoords[Player:GetName()] == nil then
Player:SendMessage(cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "No known last position") SendMessageFailure(Player, "No known last position")
return true
else else
Player:TeleportToCoords(BackCoords[Player:GetName()].x, BackCoords[Player:GetName()].y, BackCoords[Player:GetName()].z) Player:TeleportToCoords(BackCoords[Player:GetName()].x, BackCoords[Player:GetName()].y, BackCoords[Player:GetName()].z)
Player:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Teleported back to your last known position") SendMessageSuccess(Player, "Teleported back to your last known position")
end end
return true return true
end end

View File

@ -1,45 +1,49 @@
function HandleBanCommand( Split, Player ) function HandleBanCommand( Split, Player )
if( #Split < 2 ) then if( #Split < 2 ) then
Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Usage: /ban [Player] <Reason>" ) SendMessage( Player, "Usage: /ban [Player] <Reason>" )
return true return true
end end
local Reason = cChatColor.Red .. "You have been banned." .. cChatColor.White .. " Did you do something illegal?" local Reason = cChatColor.Red .. "You have been banned." .. cChatColor.White .. " Did you do something illegal?"
if( #Split > 2 ) then if( #Split > 2 ) then
Reason = table.concat(Split, " ", 3) Reason = table.concat( Split, " ", 3 )
end end
if KickPlayer(Split[2], Reason) == false then if KickPlayer(Split[2], Reason) == false then
BannedPlayersIni:DeleteValue("Banned", Split[2]) BannedPlayersIni:DeleteValue( "Banned", Split[2] )
BannedPlayersIni:SetValueB("Banned", Split[2], true) BannedPlayersIni:SetValueB( "Banned", Split[2], true )
BannedPlayersIni:WriteFile() BannedPlayersIni:WriteFile()
Player:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Could not find player, but banned anyway" ) SendMessageFailure( Player, "Could not find player, but banned anyway" )
else else
BannedPlayersIni:DeleteValue("Banned", Split[2]) BannedPlayersIni:DeleteValue( "Banned", Split[2] )
BannedPlayersIni:SetValueB("Banned", Split[2], true) BannedPlayersIni:SetValueB( "Banned", Split[2], true )
BannedPlayersIni:WriteFile() BannedPlayersIni:WriteFile()
Player:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Successfully kicked and banned player" ) SendMessageSuccess( Player, "Successfully kicked and banned player" )
end end
return true return true
end end
function HandleUnbanCommand( Split, Player ) function HandleUnbanCommand( Split, Player )
if( #Split < 2 ) then if( #Split < 2 ) then
Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Usage: /unban [Player]" ) SendMessage( Player, "Usage: /unban [Player]" )
return true return true
end end
if( BannedPlayersIni:GetValueB("Banned", Split[2], false) == false ) then if( BannedPlayersIni:GetValueB("Banned", Split[2], false) == false ) then
Player:SendMessage(cChatColor.Rose .. "[INFO] " .. cChatColor.White .. Split[2] .. " is not banned!" ) SendMessageFailure( Player, "Player is not banned!" )
return true return true
end end
BannedPlayersIni:DeleteValue("Banned", Split[2]) BannedPlayersIni:DeleteValue("Banned", Split[2])
BannedPlayersIni:SetValueB("Banned", Split[2], false) BannedPlayersIni:SetValueB("Banned", Split[2], false)
BannedPlayersIni:WriteFile() BannedPlayersIni:WriteFile()
LOGINFO( Player:GetName() .. " is unbanning " .. Split[2] ) LOGINFO( Player:GetName() .. " is unbanning " .. Split[2] )
Player:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Unbanning " .. Split[2] ) SendMessageSuccess( Player, "Unbanning " .. Split[2] )
return true return true
end
end

View File

@ -0,0 +1,25 @@
function HandleClearCommand( Split, Player )
if (Split[2] == nil) then
SendMessage( Player, "Usage: /clear <player>" )
return true
end
local InventoryCleared = false;
local ClearInventory = function(OtherPlayer)
if (OtherPlayer:GetName() == Split[2]) then
OtherPlayer:GetInventory():Clear()
InventoryCleared = true
end
end
cRoot:Get():FindAndDoWithPlayer(Split[2], ClearInventory);
if (InventoryCleared) then
SendMessageSuccess( Player, "You cleared the inventory of " .. Split[2] )
return true
else
SendMessageFailure( Player, "Player not found" )
return true
end
end

View File

@ -2,7 +2,7 @@
function InitConsoleCommands() function InitConsoleCommands()
local PluginMgr = cPluginManager:Get(); local PluginMgr = cPluginManager:Get();
-- Please keep the list alpha-sorted -- Please keep the list alpha-sorted
PluginMgr:BindConsoleCommand("ban", HandleConsoleBan, " ~ Bans a player by name"); PluginMgr:BindConsoleCommand("ban", HandleConsoleBan, " ~ Bans a player by name");
PluginMgr:BindConsoleCommand("banlist ips", HandleConsoleBanList, " - Lists all players banned by IP"); PluginMgr:BindConsoleCommand("banlist ips", HandleConsoleBanList, " - Lists all players banned by IP");
@ -21,7 +21,7 @@ function InitConsoleCommands()
PluginMgr:BindConsoleCommand("setversion", HandleConsoleVersion, " ~ Sets server version reported to 1.4+ clients"); PluginMgr:BindConsoleCommand("setversion", HandleConsoleVersion, " ~ Sets server version reported to 1.4+ clients");
PluginMgr:BindConsoleCommand("unban", HandleConsoleUnban, " ~ Unbans a player by name"); PluginMgr:BindConsoleCommand("unban", HandleConsoleUnban, " ~ Unbans a player by name");
PluginMgr:BindConsoleCommand("unload", HandleConsoleUnload, " - Unloads all unused chunks"); PluginMgr:BindConsoleCommand("unload", HandleConsoleUnload, " - Unloads all unused chunks");
end end
function HandleConsoleGive(Split) function HandleConsoleGive(Split)
@ -37,7 +37,7 @@ function HandleConsoleGive(Split)
local FoundItem = StringToItem(Split[3] .. ":" .. Split[5], Item) local FoundItem = StringToItem(Split[3] .. ":" .. Split[5], Item)
else else
local FoundItem = StringToItem(Split[3], Item) local FoundItem = StringToItem(Split[3], Item)
end end
if not IsValidItem(Item.m_ItemType) then -- StringToItem does not check if item is valid if not IsValidItem(Item.m_ItemType) then -- StringToItem does not check if item is valid
FoundItem = false FoundItem = false
end end
@ -63,10 +63,10 @@ function HandleConsoleGive(Split)
local function giveItems(newPlayer) local function giveItems(newPlayer)
local ItemsGiven = newPlayer:GetInventory():AddItem(Item) local ItemsGiven = newPlayer:GetInventory():AddItem(Item)
if ItemsGiven == ItemAmount then if ItemsGiven == ItemAmount then
newPlayer:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "There you go!" ) SendMessageSuccess( newPlayer, "There you go!" )
LOG("Gave " .. newPlayer:GetName() .. " " .. Item.m_ItemCount .. " times " .. Item.m_ItemType .. ":" .. Item.m_ItemDamage) LOG("Gave " .. newPlayer:GetName() .. " " .. Item.m_ItemCount .. " times " .. Item.m_ItemType .. ":" .. Item.m_ItemDamage)
else else
Player:SendMessage( cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "Not enough space in inventory, only gave " .. ItemsGiven) SendMessageFailure( Player, "Not enough space in inventory, only gave " .. ItemsGiven)
return true, "Only " .. Item.m_ItemCount .. " out of " .. ItemsGiven .. "items could be delivered." return true, "Only " .. Item.m_ItemCount .. " out of " .. ItemsGiven .. "items could be delivered."
end end
end end
@ -86,13 +86,13 @@ end
function HandleConsoleBan(Split) function HandleConsoleBan(Split)
if (#Split < 2) then if (#Split < 2) then
return true, "Usage: ban [Player] <Reason>"; return true, "Usage: ban [Player] <Reason>";
end end
local Reason = cChatColor.Red .. "You have been banned." .. cChatColor.White .. " Did you do something illegal?" local Reason = cChatColor.Red .. "You have been banned." .. cChatColor.White .. " Did you do something illegal?"
if( #Split > 2 ) then if( #Split > 2 ) then
Reason = table.concat(Split, " ", 3) Reason = table.concat(Split, " ", 3)
end end
if KickPlayer(Split[2], Reason) == false then if KickPlayer(Split[2], Reason) == false then
BannedPlayersIni:DeleteValue("Banned", Split[2]) BannedPlayersIni:DeleteValue("Banned", Split[2])
BannedPlayersIni:SetValueB("Banned", Split[2], true) BannedPlayersIni:SetValueB("Banned", Split[2], true)
@ -109,30 +109,32 @@ function HandleConsoleBan(Split)
end end
function HandleConsoleUnban(Split) function HandleConsoleUnban(Split)
if( #Split < 2 ) then
return true, "Usage: unban [Player]" if #Split < 2 then
return true, "Usage: /unban [Player]"
end end
if( BannedPlayersIni:GetValueB("Banned", Split[2], false) == false ) then if( BannedPlayersIni:GetValueB("Banned", Split[2], false) == false ) then
return true, Split[2] .. " is not banned!" return true, Split[2] .. " is not banned!"
end end
BannedPlayersIni:SetValueB("Banned", Split[2], false, false) BannedPlayersIni:SetValueB("Banned", Split[2], false, false)
BannedPlayersIni:WriteFile() BannedPlayersIni:WriteFile()
local Server = cRoot:Get():GetServer() local Server = cRoot:Get():GetServer()
return true, "Unbanned " .. Split[2] return true, "Unbanned " .. Split[2]
end end
function HandleConsoleBanList(Split) function HandleConsoleBanList(Split)
if (#Split == 1) then if (#Split == 1) then
return true, BanListByName(); return true, BanListByName();
end end
if (string.lower(Split[2]) == "ips") then if (string.lower(Split[2]) == "ips") then
return true, BanListByIPs(); return true, BanListByIPs();
end end
return true, "Unknown banlist subcommand"; return true, "Unknown banlist subcommand";
end end
@ -146,15 +148,15 @@ function HandleConsoleHelp(Split)
MaxLength = CmdLen; MaxLength = CmdLen;
end end
end end
cPluginManager:Get():ForEachConsoleCommand(AddToTable); cPluginManager:Get():ForEachConsoleCommand(AddToTable);
-- Sort the table: -- Sort the table:
local CompareCommands = function(a, b) local CompareCommands = function(a, b)
return a[1] < b[1]; -- compare command strings return a[1] < b[1]; -- compare command strings
end end
table.sort(Commands, CompareCommands); table.sort(Commands, CompareCommands);
local Out = ""; local Out = "";
Out = "'-' denotes no prefix, '~' denotes that a value is required.\n" Out = "'-' denotes no prefix, '~' denotes that a value is required.\n"
for i, Command in ipairs(Commands) do for i, Command in ipairs(Commands) do
@ -185,14 +187,14 @@ function HandleConsoleListGroups(Split)
if (not(GroupsIni:ReadFile())) then if (not(GroupsIni:ReadFile())) then
return true, "No groups found"; return true, "No groups found";
end end
-- Read the groups: -- Read the groups:
Number = GroupsIni:NumKeys(); Number = GroupsIni:NumKeys();
Groups = {}; Groups = {};
for i = 0, Number do for i = 0, Number do
table.insert(Groups, GroupsIni:KeyName(i)) table.insert(Groups, GroupsIni:KeyName(i))
end end
-- Output the groups, concatenated to a string: -- Output the groups, concatenated to a string:
local Out = "Groups:\n" local Out = "Groups:\n"
Out = Out .. table.concat(Groups, ", "); Out = Out .. table.concat(Groups, ", ");
@ -204,9 +206,9 @@ function HandleConsoleNumChunks(Split)
local AddNumChunks = function(World) local AddNumChunks = function(World)
Output[World:GetName()] = World:GetNumChunks(); Output[World:GetName()] = World:GetNumChunks();
end; end;
cRoot:Get():ForEachWorld(AddNumChunks); cRoot:Get():ForEachWorld(AddNumChunks);
local Total = 0; local Total = 0;
local Out = ""; local Out = "";
for name, num in pairs(Output) do for name, num in pairs(Output) do
@ -214,7 +216,7 @@ function HandleConsoleNumChunks(Split)
Total = Total + num; Total = Total + num;
end end
Out = Out .. "Total: " .. Total .. " chunks\n"; Out = Out .. "Total: " .. Total .. " chunks\n";
return true, Out; return true, Out;
end end
@ -227,9 +229,9 @@ function HandleConsolePlayers(Split)
end end
table.insert(PlayersInWorlds[WorldName], Player:GetName() .. " @ " .. Player:GetIP()); table.insert(PlayersInWorlds[WorldName], Player:GetName() .. " @ " .. Player:GetIP());
end end
cRoot:Get():ForEachPlayer(AddToTable); cRoot:Get():ForEachPlayer(AddToTable);
local Out = ""; local Out = "";
for WorldName, Players in pairs(PlayersInWorlds) do for WorldName, Players in pairs(PlayersInWorlds) do
Out = Out .. "World " .. WorldName .. ":\n"; Out = Out .. "World " .. WorldName .. ":\n";
@ -237,7 +239,7 @@ function HandleConsolePlayers(Split)
Out = Out .. " " .. PlayerName .. "\n"; Out = Out .. " " .. PlayerName .. "\n";
end end
end end
return true, Out; return true, Out;
end end
@ -247,7 +249,7 @@ function HandleConsoleVersion(Split)
local Version = cRoot:Get():GetPrimaryServerVersion(); local Version = cRoot:Get():GetPrimaryServerVersion();
return true, "Primary server version: #" .. Version .. ", " .. cRoot:GetProtocolVersionTextFromInt(Version); return true, "Primary server version: #" .. Version .. ", " .. cRoot:GetProtocolVersionTextFromInt(Version);
end end
-- Set new value as the version: -- Set new value as the version:
cRoot:Get():SetPrimaryServerVersion(tonumber(Split[2])); cRoot:Get():SetPrimaryServerVersion(tonumber(Split[2]));
local Version = cRoot:Get():GetPrimaryServerVersion(); local Version = cRoot:Get():GetPrimaryServerVersion();
@ -259,36 +261,36 @@ function HandleConsoleRank(Split)
return true, "Usage: /rank [Player] [Group]"; return true, "Usage: /rank [Player] [Group]";
end end
local Out = ""; local Out = "";
-- Read the groups.ini file: -- Read the groups.ini file:
local GroupsIni = cIniFile("groups.ini") local GroupsIni = cIniFile("groups.ini")
if (not(GroupsIni:ReadFile())) then if (not(GroupsIni:ReadFile())) then
Out = "Could not read groups.ini, creating anew!\n" Out = "Could not read groups.ini, creating anew!\n"
end end
-- Find the group: -- Find the group:
if (GroupsIni:FindKey(Split[3]) == -1) then if (GroupsIni:FindKey(Split[3]) == -1) then
return true, Out .. "Group does not exist"; return true, Out .. "Group does not exist";
end end
-- Read the users.ini file: -- Read the users.ini file:
local UsersIni = cIniFile("users.ini"); local UsersIni = cIniFile("users.ini");
if (not(UsersIni:ReadFile())) then if (not(UsersIni:ReadFile())) then
Out = Out .. "Could not read users.ini, creating anew!\n"; Out = Out .. "Could not read users.ini, creating anew!\n";
end end
-- Write the new group value to users.ini: -- Write the new group value to users.ini:
UsersIni:DeleteKey(Split[2]); UsersIni:DeleteKey(Split[2]);
UsersIni:GetValueSet(Split[2], "Groups", Split[3]); UsersIni:GetValueSet(Split[2], "Groups", Split[3]);
UsersIni:WriteFile(); UsersIni:WriteFile();
-- Reload the player's permissions: -- Reload the player's permissions:
cRoot:Get():ForEachWorld( cRoot:Get():ForEachWorld(
function (World) function (World)
World:ForEachPlayer( World:ForEachPlayer(
function (Player) function (Player)
if (Player:GetName() == Split[2]) then if (Player:GetName() == Split[2]) then
Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "You were moved to group " .. Split[3]); SendMessage( Player, "You were moved to group " .. Split[3] )
Player:LoadPermissionsFromDisk(); Player:LoadPermissionsFromDisk();
end end
end end
@ -328,7 +330,7 @@ function HandleConsoleUnload(Split)
local UnloadChunks = function(World) local UnloadChunks = function(World)
World:UnloadUnusedChunks(); World:UnloadUnusedChunks();
end end
local Out = "Num loaded chunks before: " .. cRoot:Get():GetTotalChunkCount() .. "\n"; local Out = "Num loaded chunks before: " .. cRoot:Get():GetTotalChunkCount() .. "\n";
cRoot:Get():ForEachWorld(UnloadChunks); cRoot:Get():ForEachWorld(UnloadChunks);
Out = Out .. "Num loaded chunks after: " .. cRoot:Get():GetTotalChunkCount(); Out = Out .. "Num loaded chunks after: " .. cRoot:Get():GetTotalChunkCount();
@ -357,4 +359,4 @@ end
function BanListByIPs() function BanListByIPs()
-- TODO: No IP ban implemented yet -- TODO: No IP ban implemented yet
return ""; return "";
end end

View File

@ -2,32 +2,33 @@ function HandleGiveCommand(Split, Player)
-- Make sure there are a correct number of arguments. -- Make sure there are a correct number of arguments.
if #Split ~= 3 and #Split ~= 4 and #Split ~= 5 then if #Split ~= 3 and #Split ~= 4 and #Split ~= 5 then
Player:SendMessage( cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Usage: /give <player> <item> [amount] [meta]" ) SendMessage( Player, "Usage: /give <player> <item> [amount] [meta]" )
return true return true
end end
-- Get the item from the arguments and check it's valid. -- Get the item from the arguments and check it's valid.
local Item = cItem() local Item = cItem()
if #Split == 5 then if #Split == 5 then
local FoundItem = StringToItem(Split[3] .. ":" .. Split[5], Item) local FoundItem = StringToItem( Split[3] .. ":" .. Split[5], Item )
else else
local FoundItem = StringToItem(Split[3], Item) local FoundItem = StringToItem( Split[3], Item )
end end
if not IsValidItem(Item.m_ItemType) then -- StringToItem does not check if item is valid
if not IsValidItem( Item.m_ItemType ) then -- StringToItem does not check if item is valid
FoundItem = false FoundItem = false
end end
if not FoundItem then if not FoundItem then
Player:SendMessage(cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "Invalid item id or name!" ) SendMessageFailure( Player, "Invalid item id or name!" )
return true return true
end end
-- Work out how many items the user wants. -- Work out how many items the user wants.
local ItemAmount = 1 local ItemAmount = 1
if #Split > 3 then if #Split > 3 then
ItemAmount = tonumber(Split[4]) ItemAmount = tonumber( Split[4] )
if ItemAmount == nil or ItemAmount < 1 or ItemAmount > 512 then if ItemAmount == nil or ItemAmount < 1 or ItemAmount > 512 then
Player:SendMessage(cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "Invalid amount!" ) SendMessageFailure( Player, "Invalid amount!" )
return true return true
end end
end end
@ -37,27 +38,27 @@ function HandleGiveCommand(Split, Player)
-- Get the playername from the split. -- Get the playername from the split.
local playerName = Split[2] local playerName = Split[2]
local function giveItems(newPlayer) local function giveItems( newPlayer )
local ItemsGiven = newPlayer:GetInventory():AddItem(Item) local ItemsGiven = newPlayer:GetInventory():AddItem( Item )
if ItemsGiven == ItemAmount then if ItemsGiven == ItemAmount then
newPlayer:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "You were given " .. Item.m_ItemCount .. " of " .. Item.m_ItemType .. "." ) SendMessageSuccess( newPlayer, "You were given " .. Item.m_ItemCount .. " of " .. Item.m_ItemType .. "." )
if not newPlayer == Player then if not newPlayer == Player then
Player:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Items given!" ) SendMessageSuccess( Player, "Items given!" )
end end
LOG("Gave " .. newPlayer:GetName() .. " " .. Item.m_ItemCount .. " times " .. Item.m_ItemType .. ":" .. Item.m_ItemDamage) LOG("Gave " .. newPlayer:GetName() .. " " .. Item.m_ItemCount .. " times " .. Item.m_ItemType .. ":" .. Item.m_ItemDamage )
else else
Player:SendMessage( cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "Not enough space in inventory, only gave " .. ItemsGiven) SendMessageFailure( Player, "Not enough space in inventory, only gave " .. ItemsGiven )
LOG( "Player " .. Player:GetName() .. " asked for " .. Item.m_ItemCount .. " times " .. Item.m_ItemType .. ":" .. Item.m_ItemDamage ..", but only could fit " .. ItemsGiven ) LOG( "Player " .. Player:GetName() .. " asked for " .. Item.m_ItemCount .. " times " .. Item.m_ItemType .. ":" .. Item.m_ItemDamage ..", but only could fit " .. ItemsGiven )
end end
return true return true
end end
-- Finally give the items to the player. -- Finally give the items to the player.
itemStatus = cRoot:Get():FindAndDoWithPlayer(playerName, giveItems) itemStatus = cRoot:Get():FindAndDoWithPlayer( playerName, giveItems )
-- Check to make sure that giving items was successful. -- Check to make sure that giving items was successful.
if not itemStatus then if not itemStatus then
Player:SendMessage( cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "There was no player that matched your query.") SendMessageFailure( Player, "There was no player that matched your query." )
end end
return true return true

View File

@ -1,8 +1,11 @@
function HandleChangeGMCommand( Split, Player ) function HandleChangeGMCommand( Split, Player )
if( #Split ~= 2 ) then if( #Split ~= 2 ) then
Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Usage: /gm [GameMode (0|1)]" ) SendMessage( Player, "Usage: /gm [0|1]" )
return true return true
end end
Player:SetGameMode(Split[2])
Player:SetGameMode( Split[2] )
return true return true
end
end

View File

@ -1,41 +1,43 @@
function HandleHelpCommand(Split, Player) function HandleHelpCommand( Split, Player )
local PluginManager = cRoot:Get():GetPluginManager() local PluginManager = cRoot:Get():GetPluginManager()
local LinesPerPage = 8; local LinesPerPage = 8
local CurrentPage = 1; local CurrentPage = 1
local CurrentLine = 0; local CurrentLine = 0
local PageRequested = 1; local PageRequested = 1
local Output = {}; local Output = {}
if (#Split == 2) then if (#Split == 2) then
PageRequested = tonumber(Split[2]); PageRequested = tonumber( Split[2] )
end end
local Process = function(Command, Permission, HelpString) local Process = function( Command, Permission, HelpString )
if not(Player:HasPermission(Permission)) then if not (Player:HasPermission(Permission)) then
return false; return false
end; end
if (HelpString == "") then if (HelpString == "") then
return false; return false
end; end
CurrentLine = CurrentLine + 1; CurrentLine = CurrentLine + 1
CurrentPage = math.floor(CurrentLine / LinesPerPage) + 1; CurrentPage = math.floor( CurrentLine / LinesPerPage ) + 1
if (CurrentPage ~= PageRequested) then if (CurrentPage ~= PageRequested) then
return false; return false
end; end
table.insert(Output, cChatColor.Blue .. Command .. HelpString); table.insert( Output, Command .. HelpString )
end end
PluginManager:ForEachCommand(Process); PluginManager:ForEachCommand( Process )
-- CurrentPage now contains the total number of pages, and Output has the individual help lines to be sent -- CurrentPage now contains the total number of pages, and Output has the individual help lines to be sent
Player:SendMessage(cChatColor.Purple .. "---------- [COMMANDS HELP " .. cChatColor.Gold .. "(Page " .. PageRequested .. " / " .. CurrentPage .. ")" .. cChatColor.Purple .. "] -----------"); SendMessage( Player, "Page " .. PageRequested .. " out of " .. CurrentPage .. "." )
Player:SendMessage(cChatColor.Purple .. "'-' means no prefix, '~' means a value is required."); SendMessage( Player, "'-' means no prefix, '~' means a value is required." )
for idx, msg in ipairs(Output) do for idx, msg in ipairs( Output ) do
Player:SendMessage(msg); SendMessage( Player, msg )
end; end
return true return true
end
end

View File

@ -1,7 +1,7 @@
function HandleItemCommand(Split, Player) function HandleItemCommand( Split, Player )
if ((#Split ~= 2) and (#Split ~=3)) then if ((#Split ~= 2) and (#Split ~=3)) then
Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Usage: /i <item>[:meta] [amount]" ) SendMessage( Player, "Usage: /i <item>[:meta] [amount]" )
return true return true
end end
@ -20,7 +20,7 @@ function HandleItemCommand(Split, Player)
newSplit[5] = itemSplit[2] newSplit[5] = itemSplit[2]
end end
HandleGiveCommand(newSplit, Player) HandleGiveCommand( newSplit, Player )
return true return true
end end

View File

@ -1,42 +1,46 @@
function HandleKickCommand( Split, Player ) function HandleKickCommand( Split, Player )
if( #Split < 2 ) then if( #Split < 2 ) then
Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Usage: /kick [Player] <Reason>" ) SendMessage( Player, "Usage: /kick [Player] <Reason>" )
return true return true
end end
local Reason = "You have been kicked" local Reason = "You have been kicked"
if( #Split > 2 ) then if ( #Split > 2 ) then
Reason = table.concat(Split, " ", 3) Reason = table.concat( Split, " ", 3 )
end end
if( KickPlayer( Split[2], Reason ) == false ) then if( KickPlayer( Split[2], Reason ) == false ) then
Player:SendMessage(cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "Could not find player " .. Split[2] ) SendMessageFailure( Player, "Could not find player " .. Split[2] )
end end
return true return true
end end
--- Kicks a player by name, with the specified reason; returns bool whether found and player's real name --- Kicks a player by name, with the specified reason; returns bool whether found and player's real name
function KickPlayer(PlayerName, Reason) function KickPlayer( PlayerName, Reason )
local RealName = "";
local RealName = ""
if (Reason == nil) then if (Reason == nil) then
Reason = "You have been kicked"; Reason = "You have been kicked"
end end
local FoundPlayerCallback = function(a_Player) local FoundPlayerCallback = function( a_Player )
RealName = a_Player:GetName() RealName = a_Player:GetName()
local Server = cRoot:Get():GetServer() local Server = cRoot:Get():GetServer()
LOGINFO( "'" .. RealName .. "' is being kicked for ( "..Reason..") " ) LOGINFO( "'" .. RealName .. "' is being kicked for ( "..Reason..") " )
Server:SendMessage("Kicking " .. RealName) Server:SendMessage("Kicking " .. RealName)
a_Player:GetClientHandle():Kick(Reason); a_Player:GetClientHandle():Kick(Reason)
end end
if (not(cRoot:Get():FindAndDoWithPlayer( PlayerName, FoundPlayerCallback))) then if not cRoot:Get():FindAndDoWithPlayer( PlayerName, FoundPlayerCallback ) then
-- Could not find player -- Could not find player
return false; return false
end end
return true, RealName; -- Player has been kicked return true, RealName -- Player has been kicked
end
end

View File

@ -0,0 +1,34 @@
function HandleKillCommand( Split, Player )
if (Split[2] == nil) then
Player:TakeDamage(dtInVoid, nil, 1000, 1000, 0)
return true
end
local HasKilled = false;
local KillPlayer = function(OtherPlayer)
if (OtherPlayer:GetName() == Split[2]) then
if (OtherPlayer:GetGameMode() == 1) then
HasKilled = creative
end
if (OtherPlayer:GetGameMode() == 0) then
OtherPlayer:TakeDamage(dtInVoid, nil, 1000, 1000, 0)
HasKilled = true
end
end
end
cRoot:Get():FindAndDoWithPlayer(Split[2], KillPlayer);
if (HasKilled == creative) then
SendMessageFailure( Player, "Player " .. Split[2] .. " is in creative mode" )
return true
end
if (HasKilled) then
SendMessageSuccess( Player, "Player " .. Split[2] .. " is killed" )
return true
else
SendMessageFailure( Player, "Player not found" )
return true
end
end

View File

@ -1,4 +1,4 @@
function HandleLocateCommand( Split, Player ) function HandleLocateCommand( Split, Player )
Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. string.format("You are at [X:%0.2f Y:%0.2f Z:%0.2f] in world %s", Player:GetPosX(), Player:GetPosY(), Player:GetPosZ(), Player:GetWorld():GetName()) ) SendMessage( Player, string.format("You are at [X:%0.2f Y:%0.2f Z:%0.2f] in world %s", Player:GetPosX(), Player:GetPosY(), Player:GetPosZ(), Player:GetWorld():GetName()) )
return true return true
end end

View File

@ -4,180 +4,188 @@ BannedPlayersIni = {}
WhiteListIni = {} WhiteListIni = {}
BackCoords = {} BackCoords = {}
Messages = {} Messages = {}
Destination = {}
--END VARIABLES --END VARIABLES
--COMMENCE AWESOMENESS! --COMMENCE AWESOMENESS!
function Initialize(Plugin) function Initialize( Plugin )
PLUGIN = Plugin PLUGIN = Plugin
Plugin:SetName("Core") Plugin:SetName( "Core" )
Plugin:SetVersion(13) Plugin:SetVersion( 13 )
--ADD HOOKS --ADD HOOKS
PluginManager = cRoot:Get():GetPluginManager() PluginManager = cRoot:Get():GetPluginManager()
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_JOINED) PluginManager:AddHook( Plugin, cPluginManager.HOOK_PLAYER_JOINED )
PluginManager:AddHook(Plugin, cPluginManager.HOOK_DISCONNECT) PluginManager:AddHook( Plugin, cPluginManager.HOOK_DISCONNECT )
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_BREAKING_BLOCK) PluginManager:AddHook( Plugin, cPluginManager.HOOK_PLAYER_BREAKING_BLOCK )
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_PLACING_BLOCK) PluginManager:AddHook( Plugin, cPluginManager.HOOK_PLAYER_PLACING_BLOCK )
PluginManager:AddHook(Plugin, cPluginManager.HOOK_LOGIN) PluginManager:AddHook( Plugin, cPluginManager.HOOK_LOGIN )
PluginManager:AddHook(Plugin, cPluginManager.HOOK_KILLING) PluginManager:AddHook( Plugin, cPluginManager.HOOK_KILLING )
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CRAFTING_NO_RECIPE) PluginManager:AddHook( Plugin, cPluginManager.HOOK_CRAFTING_NO_RECIPE )
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHAT) -- used in web_chat.lua PluginManager:AddHook( Plugin, cPluginManager.HOOK_CHAT ) -- used in web_chat.lua
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_MOVING) PluginManager:AddHook( Plugin, cPluginManager.HOOK_PLAYER_MOVING )
--PLEASE ALPHA SORT http://elmosaukko.com/sort-alphabetically/ THIS LIST --PLEASE ALPHA SORT http://elmosaukko.com/sort-alphabetically/ THIS LIST
--BIND COMMANDS --BIND COMMANDS
PluginManager:BindCommand("/back", "core.back", HandleBackCommand, " - Return to your last position"); PluginManager:BindCommand("/back", "core.back", HandleBackCommand, " - Return to your last position")
PluginManager:BindCommand("/ban", "core.ban", HandleBanCommand, " ~ Ban a player"); PluginManager:BindCommand("/ban", "core.ban", HandleBanCommand, " ~ Ban a player")
PluginManager:BindCommand("/downfall", "core.downfall", HandleDownfallCommand, " - Toggles the weather"); PluginManager:BindCommand("/clear", "core.clear", HandleClearCommand, " - Clear the inventory of some player")
PluginManager:BindCommand("/give", "core.give", HandleGiveCommand, " ~ Give someone an item"); PluginManager:BindCommand("/give", "core.give", HandleGiveCommand, " ~ Give someone an item")
PluginManager:BindCommand("/gm", "core.changegm", HandleChangeGMCommand, " ~ Change your gamemode"); PluginManager:BindCommand("/gm", "core.changegm", HandleChangeGMCommand, " ~ Change your gamemode")
PluginManager:BindCommand("/groups", "core.groups", HandleGroupsCommand, " - Shows a list of all the groups"); PluginManager:BindCommand("/groups", "core.groups", HandleGroupsCommand, " - Shows a list of all the groups")
PluginManager:BindCommand("/help", "core.help", HandleHelpCommand, " ~ Show available commands"); PluginManager:BindCommand("/help", "core.help", HandleHelpCommand, " ~ Show available commands")
PluginManager:BindCommand("/i", "core.give", HandleItemCommand, "") PluginManager:BindCommand("/i", "core.give", HandleItemCommand, "")
PluginManager:BindCommand("/item", "core.give", HandleItemCommand, " - Give yourself an item.") PluginManager:BindCommand("/item", "core.give", HandleItemCommand, " - Give yourself an item.")
PluginManager:BindCommand("/kick", "core.kick", HandleKickCommand, " ~ Kick a player"); PluginManager:BindCommand("/kick", "core.kick", HandleKickCommand, " ~ Kick a player")
PluginManager:BindCommand("/locate", "core.locate", HandleLocateCommand, " - Show your current server coordinates"); PluginManager:BindCommand("/kill", "core.kill", HandleKillCommand, " - Kill some player")
PluginManager:BindCommand("/me", "core.me", HandleMeCommand, " ~ Tell what you are doing"); PluginManager:BindCommand("/locate", "core.locate", HandleLocateCommand, " - Show your current server coordinates")
PluginManager:BindCommand("/motd", "core.motd", HandleMOTDCommand, " - Show message of the day"); PluginManager:BindCommand("/me", "core.me", HandleMeCommand, " ~ Tell what you are doing")
PluginManager:BindCommand("/plugins", "core.plugins", HandlePluginsCommand, " - Show list of plugins"); PluginManager:BindCommand("/motd", "core.motd", HandleMOTDCommand, " - Show message of the day")
PluginManager:BindCommand("/portal", "core.portal", HandlePortalCommand, " ~ Move to a different world"); PluginManager:BindCommand("/msg", "core.tell", HandleTellCommand, "")
PluginManager:BindCommand("/rank", "core.rank", HandleRankCommand, " ~ Add someone to a group"); PluginManager:BindCommand("/plugins", "core.plugins", HandlePluginsCommand, " - Show list of plugins")
PluginManager:BindCommand("/regen", "core.regen", HandleRegenCommand, " ~ Regenerates a chunk, current or specified"); PluginManager:BindCommand("/portal", "core.portal", HandlePortalCommand, " ~ Move to a different world")
PluginManager:BindCommand("/reload", "core.reload", HandleReloadCommand, " - Reload all plugins"); PluginManager:BindCommand("/rank", "core.rank", HandleRankCommand, " ~ Add someone to a group")
PluginManager:BindCommand("/save-all", "core.save-all", HandleSaveAllCommand, " - Saves all your worlds"); PluginManager:BindCommand("/regen", "core.regen", HandleRegenCommand, " ~ Regenerates a chunk, current or specified")
PluginManager:BindCommand("/spawn", "core.spawn", HandleSpawnCommand, " - Return to the spawn"); PluginManager:BindCommand("/reload", "core.reload", HandleReloadCommand, " - Reload all plugins")
PluginManager:BindCommand("/stop", "core.stop", HandleStopCommand, " - Stops the server"); PluginManager:BindCommand("/save-all", "core.save-all", HandleSaveAllCommand, " - Saves all your worlds")
PluginManager:BindCommand("/time", "core.time", HandleTimeCommand, " ~ Sets the time of day"); PluginManager:BindCommand("/spawn", "core.spawn", HandleSpawnCommand, " - Return to the spawn")
PluginManager:BindCommand("/top", "core.top", HandleTopCommand, " - Teleport yourself to the top most block"); PluginManager:BindCommand("/stop", "core.stop", HandleStopCommand, " - Stops the server")
PluginManager:BindCommand("/tp", "core.teleport", HandleTPCommand, " ~ Teleport yourself to a player"); PluginManager:BindCommand("/tell", "core.tell", HandleTellCommand, " ~ Send a private message")
PluginManager:BindCommand("/tpa", "core.teleport", HandleTPACommand, " ~ Ask to teleport yourself to a player"); PluginManager:BindCommand("/time", "core.time", HandleTimeCommand, " ~ Sets the time of day")
PluginManager:BindCommand("/tpaccept", "core.teleport", HandleTPAcceptCommand, " ~ Accept a teleportation request"); PluginManager:BindCommand("/toggledownfall", "core.toggledownfall", HandleDownfallCommand, " - Toggles the weather")
PluginManager:BindCommand("/unban", "core.unban", HandleUnbanCommand, " ~ Unban a player"); PluginManager:BindCommand("/top", "core.top", HandleTopCommand, " - Teleport yourself to the top most block")
PluginManager:BindCommand("/tp", "core.teleport", HandleTPCommand, " ~ Teleport yourself to a player")
PluginManager:BindCommand("/tpa", "core.teleport", HandleTPACommand, " ~ Ask to teleport yourself to a player")
PluginManager:BindCommand("/tpaccept", "core.teleport", HandleTPAcceptCommand, " ~ Accept a teleportation request")
PluginManager:BindCommand("/unban", "core.unban", HandleUnbanCommand, " ~ Unban a player")
PluginManager:BindCommand("/viewdistance", "core.viewdistance", HandleViewDistanceCommand, " [".. cClientHandle.MIN_VIEW_DISTANCE .."-".. cClientHandle.MAX_VIEW_DISTANCE .."] - Change your view distance") PluginManager:BindCommand("/viewdistance", "core.viewdistance", HandleViewDistanceCommand, " [".. cClientHandle.MIN_VIEW_DISTANCE .."-".. cClientHandle.MAX_VIEW_DISTANCE .."] - Change your view distance")
PluginManager:BindCommand("/worlds", "core.worlds", HandleWorldsCommand, " - Shows a list of all the worlds"); PluginManager:BindCommand("/weather", "core.weather", HandleWeatherCommand, " ~ Change world weather")
PluginManager:BindCommand("/worlds", "core.worlds", HandleWorldsCommand, " - Shows a list of all the worlds")
InitConsoleCommands(); InitConsoleCommands()
--LOAD SETTINGS --LOAD SETTINGS
IniFile = cIniFile("settings.ini") IniFile = cIniFile( "settings.ini" )
if ( IniFile:ReadFile() == true ) then if IniFile:ReadFile() == true then
HardCore = IniFile:GetValueSet("GameMode", "Hardcore", "false") HardCore = IniFile:GetValueSet( "GameMode", "Hardcore", "false" )
IniFile:WriteFile() IniFile:WriteFile()
end end
WorldsSpawnProtect = {} WorldsSpawnProtect = {}
local KeyIdx = IniFile:FindKey("Worlds") --(FIND WHERE 'WORLDS' KEY IS LOCATED) local KeyIdx = IniFile:FindKey( "Worlds" ) --(FIND WHERE 'WORLDS' KEY IS LOCATED)
local NumValues = (IniFile:GetNumValues( KeyIdx )) --(HOW MANY VALUES ARE THERE?) local NumValues = IniFile:GetNumValues( KeyIdx ) --(HOW MANY VALUES ARE THERE?)
for i = 0, NumValues - 1 do --(FOR EVERY WORLD KEY, TAKING ACCOUNT OF OFF BY ONE ERRORS) for i = 0, NumValues - 1 do --(FOR EVERY WORLD KEY, TAKING ACCOUNT OF OFF BY ONE ERRORS)
WorldIni = cIniFile(IniFile:GetValue(KeyIdx, i) .. "/world.ini") WorldIni = cIniFile( IniFile:GetValue(KeyIdx, i) .. "/world.ini" )
if WorldIni:ReadFile() == true then if WorldIni:ReadFile() == true then
WorldsSpawnProtect[IniFile:GetValue(KeyIdx, i)] = WorldIni:GetValueSetI("SpawnProtect", "ProtectRadius", 10) WorldsSpawnProtect[IniFile:GetValue(KeyIdx, i)] = WorldIni:GetValueSetI( "SpawnProtect", "ProtectRadius", 10 )
WorldIni:WriteFile() WorldIni:WriteFile()
end end
end end
WorldsWorldLimit = {} WorldsWorldLimit = {}
local KeyIdx = IniFile:FindKey("Worlds") --(FIND WHERE 'WORLDS' KEY IS LOCATED) local KeyIdx = IniFile:FindKey( "Worlds" ) --(FIND WHERE 'WORLDS' KEY IS LOCATED)
local NumValues = (IniFile:GetNumValues( KeyIdx )) --(HOW MANY VALUES ARE THERE?) local NumValues = IniFile:GetNumValues( KeyIdx ) --(HOW MANY VALUES ARE THERE?)
for i = 0, NumValues - 1 do --(FOR EVERY WORLD KEY, TAKING ACCOUNT OF OFF BY ONE ERRORS) for i = 0, NumValues - 1 do --(FOR EVERY WORLD KEY, TAKING ACCOUNT OF OFF BY ONE ERRORS)
WorldIni = cIniFile(IniFile:GetValue(KeyIdx, i) .. "/world.ini") WorldIni = cIniFile( IniFile:GetValue(KeyIdx, i) .. "/world.ini" )
if WorldIni:ReadFile() == true then if WorldIni:ReadFile() == true then
WorldsWorldLimit[IniFile:GetValue(KeyIdx, i)] = WorldIni:GetValueSetI("WorldLimit", "LimitRadius", 0) WorldsWorldLimit[IniFile:GetValue(KeyIdx, i)] = WorldIni:GetValueSetI( "WorldLimit", "LimitRadius", 0 )
WorldIni:WriteFile() WorldIni:WriteFile()
end end
end end
--LOAD WHITELIST --LOAD WHITELIST
WhiteListIni = cIniFile( Plugin:GetLocalDirectory() .. "/whitelist.ini" ) WhiteListIni = cIniFile( Plugin:GetLocalDirectory() .. "/whitelist.ini" )
if ( WhiteListIni:ReadFile() == true ) then if WhiteListIni:ReadFile() == true then
if( WhiteListIni:GetValueB("WhiteListSettings", "WhiteListOn", false) == true ) then if WhiteListIni:GetValueB( "WhiteListSettings", "WhiteListOn", false ) == true then
if( WhiteListIni:GetNumValues("WhiteList") > 0 ) then if WhiteListIni:GetNumValues( "WhiteList" ) > 0 then
LOGINFO("Core: loaded " .. WhiteListIni:GetNumValues('WhiteList') .. " whitelisted players.") LOGINFO( "Core: loaded " .. WhiteListIni:GetNumValues('WhiteList') .. " whitelisted players." )
else else
LOGWARN("WARNING: WhiteList is on, but there are no people in the whitelist!") LOGWARN( "WARNING: WhiteList is on, but there are no people in the whitelist!" )
end end
end end
else else
WhiteListIni:SetValueB("WhiteListSettings", "WhiteListOn", false ) WhiteListIni:SetValueB( "WhiteListSettings", "WhiteListOn", false )
WhiteListIni:SetValue("WhiteList", "", "") -- So it adds an empty header WhiteListIni:SetValue( "WhiteList", "", "" ) -- So it adds an empty header
WhiteListIni:DeleteValue("WhiteList", "") -- And remove the value WhiteListIni:DeleteValue( "WhiteList", "" ) -- And remove the value
WhiteListIni:KeyComment("WhiteList", "PlayerName=1") WhiteListIni:KeyComment( "WhiteList", "PlayerName=1" )
if( WhiteListIni:WriteFile() == false ) then if WhiteListIni:WriteFile() == false then
LOGWARN("WARNING: Could not write to whitelist.ini") LOGWARN( "WARNING: Could not write to whitelist.ini" )
end end
end end
--LOAD BANNED (BAD LUCK, BRO) --LOAD BANNED (BAD LUCK, BRO)
BannedPlayersIni = cIniFile( Plugin:GetLocalDirectory() .. "/banned.ini" ) BannedPlayersIni = cIniFile( Plugin:GetLocalDirectory() .. "/banned.ini" )
if ( BannedPlayersIni:ReadFile() == true ) then if BannedPlayersIni:ReadFile() == true then
if( BannedPlayersIni:GetNumValues("Banned") > 0 ) then if BannedPlayersIni:GetNumValues( "Banned" ) > 0 then
LOGINFO("Core: loaded " .. BannedPlayersIni:GetNumValues("Banned") .. " banned players.") LOGINFO( "Core: loaded " .. BannedPlayersIni:GetNumValues("Banned") .. " banned players." )
end end
else else
BannedPlayersIni:SetValue("Banned", "", "") -- So it adds an empty header BannedPlayersIni:SetValue( "Banned", "", "" ) -- So it adds an empty header
BannedPlayersIni:DeleteValue("Banned", "") -- And remove the value BannedPlayersIni:DeleteValue( "Banned", "" ) -- And remove the value
BannedPlayersIni:KeyComment("Banned", "PlayerName=1") BannedPlayersIni:KeyComment( "Banned", "PlayerName=1" )
if( BannedPlayersIni:WriteFile() == false ) then if BannedPlayersIni:WriteFile() == false then
LOGWARN("WARNING: Could not write to banned.ini") LOGWARN( "WARNING: Could not write to banned.ini" )
end end
end end
--ADD WEB INTERFACE TABULATES --ADD WEB INTERFACE TABULATES
Plugin:AddWebTab("Manage Server", HandleRequest_ManageServer); Plugin:AddWebTab( "Manage Server", HandleRequest_ManageServer )
Plugin:AddWebTab("Server Settings", HandleRequest_ServerSettings); Plugin:AddWebTab( "Server Settings", HandleRequest_ServerSettings )
Plugin:AddWebTab("Chat", HandleRequest_Chat); Plugin:AddWebTab( "Chat", HandleRequest_Chat )
Plugin:AddWebTab("Playerlist", HandleRequest_PlayerList); Plugin:AddWebTab( "Playerlist", HandleRequest_PlayerList )
Plugin:AddWebTab("Whitelist", HandleRequest_WhiteList); Plugin:AddWebTab( "Whitelist", HandleRequest_WhiteList )
Plugin:AddWebTab("Permissions", HandleRequest_Permissions); Plugin:AddWebTab( "Permissions", HandleRequest_Permissions )
Plugin:AddWebTab("Manage Plugins", HandleRequest_ManagePlugins); Plugin:AddWebTab( "Manage Plugins", HandleRequest_ManagePlugins )
LoadMotd() LoadMotd()
LOG( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() ) LOG( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() )
return true return true
end end
--AWESOMENESS STILL GOING! --AWESOMENESS STILL GOING!
--BEGIN SPAWNPROTECT LOGFILE CODE (COURTSEY OF BEARBIN) --BEGIN SPAWNPROTECT LOGFILE CODE (COURTSEY OF BEARBIN)
function WriteLog(breakPlace, X, Y, Z, player, id, meta) function WriteLog( breakPlace, X, Y, Z, player, id, meta )
local logText = {} local logText = {}
table.insert(logText, player) table.insert( logText, player )
table.insert(logText, " tried to ") table.insert( logText, " tried to " )
if breakPlace == 0 then if breakPlace == 0 then
table.insert(logText, "break ") table.insert( logText, "break " )
else else
table.insert(logText, "place ") table.insert( logText, "place " )
end end
table.insert(logText, ItemToString(cItem(id, 1, meta))) table.insert( logText, ItemToString(cItem(id, 1, meta)) )
table.insert(logText, " at ") table.insert( logText, " at ")
table.insert(logText, tostring(X)) table.insert( logText, tostring(X) )
table.insert(logText, ", ") table.insert( logText, ", ")
table.insert(logText, tostring(Y)) table.insert( logText, tostring(Y) )
table.insert(logText, ", ") table.insert( logText, ", ")
table.insert(logText, tostring(Z)) table.insert( logText, tostring(Z) )
table.insert(logText, ".") table.insert( logText, "." )
LOGINFO(table.concat(logText,'')) LOGINFO( table.concat( logText, '') )
if LOGTOFILE then if LOGTOFILE then
local logFile = io.open( Plugin:GetLocalDirectory() .. '/blocks.log', 'a') local logFile = io.open( Plugin:GetLocalDirectory() .. '/blocks.log', 'a' )
logFile:write(table.concat(logText,'').."\n") logFile:write( table.concat( logText, '' ) .. "\n" )
logFile:close() logFile:close()
end end
return return
end end
function WarnPlayer(Player) function WarnPlayer( Player )
Player:SendMessage(cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "Go further from spawn to build") SendMessageFailure( Player, "Go further from spawn to build" )
return return true
end end
function OnDisable() function OnDisable()
LOG( "Disabled Core!") LOG( "Disabled Core!" )
end end
--END AWESOMENESS :'( --END AWESOMENESS :'(

View File

@ -1,15 +1,20 @@
function HandleMeCommand( Split, Player ) function HandleMeCommand( Split, Player )
table.remove(Split, 1);
local Message = ""; table.remove( Split, 1 )
for i, Text in ipairs(Split) do local Message = ""
Message = Message .. " " .. Text;
for i, Text in ipairs( Split ) do
Message = Message .. " " .. Text
end end
if (Split[1] == nil) then
Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Usage: /me <action>") if Split[1] == nil then
SendMessage( Player, "Usage: /me <action>" )
return true return true
end end
if (Split[1] ~= nil) then
cRoot:Get():GetServer():BroadcastChat(Player:GetName() .. "" .. Message); if Split[1] ~= nil then
cRoot:Get():GetServer():BroadcastChat( Player:GetName() .. "" .. Message )
return true return true
end end
end end

View File

@ -0,0 +1,27 @@
-- Use prefixes or not.
-- If set to true, messages are prefixed, e. g. "[FATAL]". If false, messages are colored.
g_UsePrefixes = true
function SendMessage(a_Player, a_Message)
if (g_UsePrefixes) then
a_Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. a_Message)
else
a_Player:SendMessage(cChatColor.Yellow .. a_Message)
end
end
function SendMessageSuccess(a_Player, a_Message)
if (g_UsePrefixes) then
a_Player:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. a_Message)
else
a_Player:SendMessage(cChatColor.Green .. a_Message)
end
end
function SendMessageFailure(a_Player, a_Message)
if (g_UsePrefixes) then
a_Player:SendMessage(cChatColor.Red .. "[INFO] " .. cChatColor.White .. a_Message)
else
a_Player:SendMessage(cChatColor.Red .. a_Message)
end
end

View File

@ -4,32 +4,36 @@ function HandleMOTDCommand( Split, Player )
end end
function LoadMotd() function LoadMotd()
local File = io.open("motd.txt", "r")
local File = io.open( "motd.txt", "r" )
-- Check if the file 'motd.txt' exists, else create it. -- Check if the file 'motd.txt' exists, else create it.
if not File then if not File then
CreateFile = io.open("motd.txt", "w") CreateFile = io.open( "motd.txt", "w" )
CreateFile:write("@6Welcome to the MCServer test server!\n@6http://www.mc-server.org/\n@6Type /help for all commands") CreateFile:write("@6Welcome to the MCServer test server!\n@6http://www.mc-server.org/\n@6Type /help for all commands")
CreateFile:close() CreateFile:close()
else else
File:close() File:close()
end end
for line in io.lines("motd.txt") do
for line in io.lines( "motd.txt" ) do
local TempMessage = line local TempMessage = line
-- Do a for loop that goes to each char in the line. -- Do a for loop that goes to each char in the line.
for I=1, string.len(TempMessage) do for I=1, string.len( TempMessage ) do
-- If the char is a '@' then check if the next char represents a color. -- If the char is a '@' then check if the next char represents a color.
if string.sub(TempMessage, I, I) == "@" then if string.sub( TempMessage, I, I ) == "@" then
local Char = string.sub(TempMessage, I + 1, I + 1) local Char = string.sub( TempMessage, I + 1, I + 1 )
local Color = ReturnColorFromChar(TempMessage, Char) local Color = ReturnColorFromChar( TempMessage, Char )
-- If the next char represented a color then put the color in the string. -- If the next char represented a color then put the color in the string.
if (Color ~= nil) then if Color ~= nil then
TempMessage = string.gsub(TempMessage, "@" .. Char, Color) TempMessage = string.gsub( TempMessage, "@" .. Char, Color )
end end
end end
end end
-- Add the message to the list of messages. -- Add the message to the list of messages.
Messages[#Messages + 1] = TempMessage Messages[#Messages + 1] = TempMessage
end end
end end
function ShowMOTDTo( Player ) function ShowMOTDTo( Player )
@ -39,6 +43,7 @@ function ShowMOTDTo( Player )
end end
function ReturnColorFromChar( Split, char ) function ReturnColorFromChar( Split, char )
-- Check if the char represents a color. Else return nil. -- Check if the char represents a color. Else return nil.
if char == "0" then if char == "0" then
return cChatColor.Black return cChatColor.Black
@ -85,4 +90,5 @@ function ReturnColorFromChar( Split, char )
elseif char == "r" then elseif char == "r" then
return cChatColor.Plain return cChatColor.Plain
end end
end
end

View File

@ -1,15 +1,17 @@
function HandlePluginsCommand( Split, Player ) function HandlePluginsCommand( Split, Player )
local PluginManager = cRoot:Get():GetPluginManager() local PluginManager = cRoot:Get():GetPluginManager()
local PluginList = PluginManager:GetAllPlugins() local PluginList = PluginManager:GetAllPlugins()
local PluginTable = {} local PluginTable = {}
for k, Plugin in pairs( PluginList ) do for k, Plugin in pairs( PluginList ) do
if ( Plugin ) then if Plugin then
table.insert(PluginTable, Plugin:GetName() ) table.insert( PluginTable, Plugin:GetName() )
end end
end end
Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "There are " .. #PluginTable .. " loaded plugins") SendMessage( Player, "There are " .. #PluginTable .. " loaded plugins" )
Player:SendMessage(cChatColor.Gold .. table.concat(PluginTable, cChatColor.Gold.." ") ) SendMessage( Player, table.concat( PluginTable , " " ) )
return true return true
end
end

View File

@ -1,24 +1,27 @@
function HandlePortalCommand( Split, Player ) function HandlePortalCommand( Split, Player )
if( #Split ~= 2 ) then if( #Split ~= 2 ) then
Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Usage: /portal [WorldName]" ) SendMessage( Player, "Usage: /portal [WorldName]" )
return true
end
if( Player:MoveToWorld(Split[2]) == false ) then
Player:SendMessage(cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "Could not move to world " .. Split[2] .. "!" )
return true return true
end end
if( Player:MoveToWorld(Split[2]) == false ) then
Player:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Moved successfully to '" .. Split[2] .. "'! :D" ) SendMessageFailure( Player, "Could not move to world " .. Split[2] .. "!" )
return true
end
SendMessageSuccess( Player, "Moved successfully to '" .. Split[2] .. "'! :D" )
return true return true
end end
function HandleWorldsCommand( Split, Player ) function HandleWorldsCommand( Split, Player )
local SettingsIni = cIniFile("settings.ini") local SettingsIni = cIniFile("settings.ini")
if SettingsIni:ReadFile() == false then if SettingsIni:ReadFile() == false then
Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "No worlds found" ) SendMessageFailure( Player, "No worlds found" )
end end
Number = SettingsIni:NumValues("Worlds") - 1 Number = SettingsIni:NumValues("Worlds") - 1
Worlds = {} Worlds = {}
for i=0, SettingsIni:GetNumKeys() - 1 do for i=0, SettingsIni:GetNumKeys() - 1 do
@ -27,10 +30,12 @@ function HandleWorldsCommand( Split, Player )
break break
end end
end end
for i=0, Number do for i=0, Number do
table.insert( Worlds, SettingsIni:GetValue( Key, i) ) table.insert( Worlds, SettingsIni:GetValue( Key, i ) )
end end
Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Found " .. #Worlds .. " worlds" ) SendMessage( Player, "Found " .. #Worlds .. " worlds" )
Player:SendMessage(cChatColor.Gold .. table.concat( Worlds, ", " ) ) SendMessage( Player, table.concat( Worlds, ", " ) )
return true return true
end
end

View File

@ -1,48 +1,63 @@
function HandleRankCommand( Split, Player ) function HandleRankCommand( Split, Player )
if Split[2] == nil or Split[3] == nil then if Split[2] == nil or Split[3] == nil then
Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Usage: /rank [Player] [Group]") SendMessage( Player, "Usage: /rank [Player] [Group]" )
return true return true
end end
local GroupsIni = cIniFile("groups.ini")
if( GroupsIni:ReadFile() == false ) then local GroupsIni = cIniFile( "groups.ini" )
LOG("Could not read groups.ini!") if GroupsIni:ReadFile() == false then
LOG( "Could not read groups.ini!" )
end end
if GroupsIni:FindKey(Split[3]) == -1 then if GroupsIni:FindKey(Split[3]) == -1 then
Player:SendMessage(cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "Group does not exist") SendMessageFailure( Player, "Group does not exist" )
return true return true
end end
local UsersIni = cIniFile("users.ini") local UsersIni = cIniFile("users.ini")
if( UsersIni:ReadFile() == false ) then if UsersIni:ReadFile() == false then
LOG("Could not read users.ini!") LOG( "Could not read users.ini!" )
end end
UsersIni:DeleteKey(Split[2])
UsersIni:GetValueSet(Split[2], "Groups", Split[3]) UsersIni:DeleteKey( Split[2] )
UsersIni:GetValueSet( Split[2], "Groups", Split[3] )
UsersIni:WriteFile() UsersIni:WriteFile()
local loopPlayers = function( Player ) local loopPlayers = function( Player )
if Player:GetName() == Split[2] then if Player:GetName() == Split[2] then
Player:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "You were moved to group " .. Split[3] ) SendMessageSuccess( Player, "You were moved to group " .. Split[3] )
Player:LoadPermissionsFromDisk() Player:LoadPermissionsFromDisk()
end end
end end
local loopWorlds = function ( World ) local loopWorlds = function ( World )
World:ForEachPlayer( loopPlayers ) World:ForEachPlayer( loopPlayers )
end end
cRoot:Get():ForEachWorld( loopWorlds ) cRoot:Get():ForEachWorld( loopWorlds )
Player:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Player " .. Split[2] .. " Was moved to " .. Split[3]) SendMessageSuccess( Player, "Player " .. Split[2] .. " Was moved to " .. Split[3] )
return true return true
end end
function HandleGroupsCommand( Split, Player ) function HandleGroupsCommand( Split, Player )
local GroupsIni = cIniFile("groups.ini")
local GroupsIni = cIniFile( "groups.ini" )
if GroupsIni:ReadFile() == false then if GroupsIni:ReadFile() == false then
Player:SendMessage(cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "No groups found" ) SendMessageFailure( Player, "No groups found" )
end end
Number = GroupsIni:NumKeys() - 1 Number = GroupsIni:NumKeys() - 1
Groups = {} Groups = {}
for i=0, Number do for i=0, Number do
table.insert( Groups, GroupsIni:KeyName(i) ) table.insert( Groups, GroupsIni:KeyName( i ) )
end end
Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Found " .. #Groups .. " groups" )
Player:SendMessage(cChatColor.Gold .. table.concat( Groups, " " ) ) SendMessage( Player, "Found " .. #Groups .. " groups" )
SendMessage( Player, table.concat( Groups, " " ) )
return true return true
end
end

View File

@ -1,18 +1,20 @@
function HandleRegenCommand(Split, Player) function HandleRegenCommand(Split, Player)
if ((#Split == 2) or (#Split > 3)) then
Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Usage: '/regeneratechunk' or '/regeneratechunk [X] [Z]'"); if #Split == 2 or #Split > 3 then
return true; SendMessage( Player, "Usage: '/regeneratechunk' or '/regeneratechunk [X] [Z]'" )
return true
end end
local X = Player:GetChunkX(); local X = Player:GetChunkX()
local Z = Player:GetChunkZ(); local Z = Player:GetChunkZ()
if (#Split == 3) then if #Split == 3 then
X = Split[2]; X = Split[2]
Z = Split[3]; Z = Split[3]
end end
Player:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Regenerating chunk ["..X..", "..Z.."]"); SendMessageSuccess( Player, "Regenerating chunk ["..X..", "..Z.."]")
Player:GetWorld():RegenerateChunk(X, Z); Player:GetWorld():RegenerateChunk(X, Z)
return true; return true
end
end

View File

@ -1,22 +1,28 @@
function HandleSaveAllCommand( Split, Player ) function HandleSaveAllCommand( Split, Player )
cRoot:Get():SaveAllChunks();
cRoot:Get():SaveAllChunks()
local Server = cRoot:Get():GetServer() local Server = cRoot:Get():GetServer()
Server:SendMessage(cChatColor.Rose .. "[WARNING] " .. cChatColor.White .. "Saving all worlds!") Server:SendMessage(cChatColor.Rose .. "[WARNING] " .. cChatColor.White .. "Saving all worlds!")
return true; return true
end end
function HandleStopCommand( Split, Player ) function HandleStopCommand( Split, Player )
Server = cRoot:Get():GetServer() Server = cRoot:Get():GetServer()
local Server = cRoot:Get():GetServer() local Server = cRoot:Get():GetServer()
Server:SendMessage(cChatColor.Red .. "[WARNING] " .. cChatColor.White .. "Server is terminating!" ) Server:SendMessage(cChatColor.Red .. "[WARNING] " .. cChatColor.White .. "Server is terminating!" )
cRoot:Get():QueueExecuteConsoleCommand("stop") cRoot:Get():QueueExecuteConsoleCommand("stop")
return true return true
end end
function HandleReloadCommand( Split, Player ) function HandleReloadCommand( Split, Player )
Server = cRoot:Get():GetServer() Server = cRoot:Get():GetServer()
local Server = cRoot:Get():GetServer() local Server = cRoot:Get():GetServer()
Server:SendMessage(cChatColor.Rose .. "[WARNING] " .. cChatColor.White .. "Reloading all plugins!" ) Server:SendMessage(cChatColor.Rose .. "[WARNING] " .. cChatColor.White .. "Reloading all plugins!" )
cRoot:Get():GetPluginManager():ReloadPlugins() cRoot:Get():GetPluginManager():ReloadPlugins()
return true return true
end
end

View File

@ -1,7 +1,9 @@
function HandleSpawnCommand(Split, Player) function HandleSpawnCommand(Split, Player)
World = Player:GetWorld() World = Player:GetWorld()
SetBackCoordinates(Player) SetBackCoordinates(Player)
Player:TeleportToCoords(World:GetSpawnX(), World:GetSpawnY(), World:GetSpawnZ()) Player:TeleportToCoords(World:GetSpawnX(), World:GetSpawnY(), World:GetSpawnZ())
Player:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Returned to world spawn" ) SendMessageSuccess( Player, "Returned to world spawn" )
return true return true
end
end

View File

@ -1,80 +1,100 @@
function HandleTPCommand(a_Split, a_Player) function HandleTPCommand(a_Split, a_Player)
if ((#a_Split == 2) or (#a_Split == 3)) then
if #a_Split == 2 or #a_Split == 3 then
-- Teleport to player specified in a_Split[2], tell them unless a_Split[3] equals "-h": -- Teleport to player specified in a_Split[2], tell them unless a_Split[3] equals "-h":
TeleportToPlayer(a_Player, a_Split[2], (a_Split[3] ~= "-h")); TeleportToPlayer( a_Player, a_Split[2], (a_Split[3] ~= "-h") )
return true; return true
elseif (#a_Split == 4) then
elseif #a_Split == 4 then
-- Teleport to XYZ coords specified in a_Split[2, 3, 4]: -- Teleport to XYZ coords specified in a_Split[2, 3, 4]:
SetBackCoordinates(a_Player); SetBackCoordinates(a_Player)
a_Player:TeleportToCoords(a_Split[2], a_Split[3], a_Split[4]); a_Player:TeleportToCoords( a_Split[2], a_Split[3], a_Split[4] )
a_Player:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "You teleported to [X:" .. a_Split[2] .. " Y:" .. a_Split[3] .. " Z:" .. a_Split[4] .. "]"); SendMessageSuccess( a_Player, "You teleported to [X:" .. a_Split[2] .. " Y:" .. a_Split[3] .. " Z:" .. a_Split[4] .. "]" )
return true; return true
else else
a_Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Usage: /tp [PlayerName] (-h) or /tp [X Y Z]" ) SendMessage( a_Player, "Usage: /tp [PlayerName] (-h) or /tp [X Y Z]" )
return true return true
end end
end end
function HandleTPACommand( Split, Player ) function HandleTPACommand( Split, Player )
if Split[2] == nil then if Split[2] == nil then
Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Usage: /tpa [Player]" ) SendMessage( Player, "Usage: /tpa [Player]" )
return true return true
end end
local loopPlayer = function( OtherPlayer ) local loopPlayer = function( OtherPlayer )
if OtherPlayer:GetName() == Split[2] then if OtherPlayer:GetName() == Split[2] then
OtherPlayer:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. Player:GetName() .. " send a teleport request" ) SendMessage( OtherPlayer, Player:GetName() .. " send a teleport request" )
Player:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "You send a teleport request to " .. OtherPlayer:GetName() ) SendMessageSuccess( Player, "You send a teleport request to " .. OtherPlayer:GetName() )
Destination[OtherPlayer:GetName()] = Player:GetName() Destination[OtherPlayer:GetName()] = Player:GetName()
end end
end end
local loopWorlds = function( World ) local loopWorlds = function( World )
World:ForEachPlayer( loopPlayer ) World:ForEachPlayer( loopPlayer )
end end
cRoot:Get():ForEachWorld( loopWorlds ) cRoot:Get():ForEachWorld( loopWorlds )
return true return true
end end
function HandleTPAcceptCommand( Split, Player ) function HandleTPAcceptCommand( Split, Player )
if Destination[Player:GetName()] == nil then if Destination[Player:GetName()] == nil then
Player:SendMessage(cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "Nobody has send you a teleport request" ) SendMessageFailure( Player, "Nobody has send you a teleport request" )
return true return true
end end
local loopPlayer = function( OtherPlayer ) local loopPlayer = function( OtherPlayer )
if Destination[Player:GetName()] == OtherPlayer:GetName() then if Destination[Player:GetName()] == OtherPlayer:GetName() then
if OtherPlayer:GetWorld():GetName() ~= Player:GetWorld():GetName() then if OtherPlayer:GetWorld():GetName() ~= Player:GetWorld():GetName() then
OtherPlayer:MoveToWorld( Player:GetWorld():GetName() ) OtherPlayer:MoveToWorld( Player:GetWorld():GetName() )
end end
OtherPlayer:TeleportToEntity( Player ) OtherPlayer:TeleportToEntity( Player )
Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. OtherPlayer:GetName() .. " teleported to you" ) SendMessage( Player, OtherPlayer:GetName() .. " teleported to you" )
OtherPlayer:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "You teleported to " .. Player:GetName() ) SendMessageSuccess( OtherPlayer, "You teleported to " .. Player:GetName() )
Destination[Player:GetName()] = nil Destination[Player:GetName()] = nil
end end
end end
local loopWorlds = function( World ) local loopWorlds = function( World )
World:ForEachPlayer( loopPlayer ) World:ForEachPlayer( loopPlayer )
end end
cRoot:Get():ForEachWorld( loopWorlds ) cRoot:Get():ForEachWorld( loopWorlds )
return true return true
end end
-- Teleports a_SrcPlayer to a player named a_DstPlayerName; if a_TellDst is true, will send a notice to the destination player -- Teleports a_SrcPlayer to a player named a_DstPlayerName; if a_TellDst is true, will send a notice to the destination player
function TeleportToPlayer(a_SrcPlayer, a_DstPlayerName, a_TellDst) function TeleportToPlayer( a_SrcPlayer, a_DstPlayerName, a_TellDst )
local teleport = function(OtherPlayer) local teleport = function(OtherPlayer)
if (OtherPlayer == a_SrcPlayer) then
if OtherPlayer == a_SrcPlayer then
-- Asked to teleport to self? -- Asked to teleport to self?
a_SrcPlayer:SendMessage(cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "Y' can't teleport to yerself!"); SendMessageFailure( a_SrcPlayer, "Y' can't teleport to yerself!" )
else else
SetBackCoordinates(a_SrcPlayer); SetBackCoordinates( a_SrcPlayer )
a_SrcPlayer:TeleportToEntity(OtherPlayer); a_SrcPlayer:TeleportToEntity( OtherPlayer )
a_SrcPlayer:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "You teleported to " .. OtherPlayer:GetName() .. "!"); SendMessageSuccess( a_SrcPlayer, "You teleported to " .. OtherPlayer:GetName() .. "!" )
if (a_TellDst) then if (a_TellDst) then
OtherPlayer:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. Player:GetName().." teleported to you!"); SendMessage( OtherPlayer, Player:GetName().." teleported to you!" )
end end
end end
end end
local World = a_SrcPlayer:GetWorld(); local World = a_SrcPlayer:GetWorld()
if (not(World:DoWithPlayer(a_DstPlayerName, teleport))) then if not World:DoWithPlayer(a_DstPlayerName, teleport) then
a_SrcPlayer:SendMessage(cChatColor.Rose .. "[INFO] " .. cChatColor.White .. "Can't find player " .. a_DstPlayerName); SendMessageFailure( a_SrcPlayer, "Can't find player " .. a_DstPlayerName)
end end
end
end

View File

@ -0,0 +1,37 @@
function HandleTellCommand(Split, Player, OtherPlayer)
if (Split[2] == nil) or (Split[3] == nil) then
Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. "Usage: /tell [playername] [message]")
return true
end
local SendMessage = function(OtherPlayer)
Sender = Player:GetName()
Reciever = Split[2]
if (OtherPlayer:GetName() == Split[2]) then
Server = cRoot:Get():GetServer()
FullMsg = ""
for i,v in ipairs(Split) do
if(i>2) then
if(FullMsg == "") then
FullMsg = v
else
FullMsg = FullMsg .. " " .. v
end
end
end
Player:SendMessage(cChatColor.Green .. "[INFO] " .. "Message to player " .. Reciever .. " sent!" )
OtherPlayer:SendMessage(cChatColor.Orange .. "[MSG: " .. Sender .. " ] " .. FullMsg )
else
Player:SendMessage(cChatColor.Red .. 'Player "' ..Split[2].. '" not found')
end
end
cRoot:Get():ForEachPlayer(SendMessage)
return true;
end

View File

@ -1,23 +1,26 @@
function HandleTimeCommand( Split, Player ) function HandleTimeCommand( Split, Player )
if Split[2] == nil then
Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Usage: /time [Day/Night/Set/Add]" ) if Split[2] == nil then
SendMessage( Player, "Usage: /time [Day/Night/Set/Add]" )
return true return true
end end
local Server = cRoot:Get():GetServer() local Server = cRoot:Get():GetServer()
if( string.upper( Split[2] ) == "DAY") then if string.upper( Split[2] ) == "DAY" then
Player:GetWorld():SetTimeOfDay( 0 ) Player:GetWorld():SetTimeOfDay( 0 )
Server:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Time was set to daytime" ) Server:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Time was set to daytime" )
elseif( string.upper( Split[2] ) == "NIGHT") then elseif string.upper( Split[2] ) == "NIGHT" then
Player:GetWorld():SetTimeOfDay( 12000 + 1000 ) Player:GetWorld():SetTimeOfDay( 12000 + 1000 )
Server:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Time was set to night time" ) Server:SendMessage( cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Time was set to night time" )
elseif( string.upper(Split[2]) == "SET" ) and ( tonumber(Split[3]) ~= nil) then elseif string.upper( Split[2] ) == "SET" and tonumber( Split[3] ) ~= nil then
Player:GetWorld():SetTimeOfDay( tonumber(Split[3]) ) Player:GetWorld():SetTimeOfDay( tonumber(Split[3]) )
Server:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Time was set to " .. Split[3] ) Server:SendMessage( cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Time was set to " .. Split[3] )
elseif( string.upper(Split[2]) == "ADD" ) and ( tonumber(Split[3]) ~= nil) then elseif string.upper( Split[2] ) == "ADD" and tonumber( Split[3] ) ~= nil then
Player:GetWorld():SetTimeOfDay( Player:GetWorld():GetTimeOfDay() + Split[3] ) Player:GetWorld():SetTimeOfDay( Player:GetWorld():GetTimeOfDay() + Split[3] )
Server:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. Split[3] .. "Was added to the time" ) Server:SendMessage( cChatColor.Green .. "[INFO] " .. cChatColor.White .. Split[3] .. "Was added to the time" )
else else
Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Usage: /time [Day/Night/Set/Add]" ) SendMessage( Player, "Usage: /time [Day/Night/Set/Add]" )
end end
return true return true
end end

View File

@ -1,11 +1,13 @@
function HandleTopCommand( Split, Player ) function HandleTopCommand( Split, Player )
local World = Player:GetWorld() local World = Player:GetWorld()
local PlayerPos = Player:GetPosition() local PlayerPos = Player:GetPosition()
local Height = World:GetHeight( math.floor(PlayerPos.x), math.floor(PlayerPos.z) ) local Height = World:GetHeight( math.floor( PlayerPos.x ), math.floor( PlayerPos.z ) )
SetBackCoordinates( Player ) SetBackCoordinates( Player )
Player:TeleportToCoords( PlayerPos.x, Height+1, PlayerPos.z ) Player:TeleportToCoords( PlayerPos.x, Height+1, PlayerPos.z )
Player:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Teleported to the topmost block") SendMessageSuccess( Player, "Teleported to the topmost block" )
return true return true
end
end

View File

@ -1,10 +1,12 @@
function HandleViewDistanceCommand( Split, Player ) function HandleViewDistanceCommand( Split, Player )
if( #Split ~= 2 ) then if( #Split ~= 2 ) then
Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Usage: /viewdistance [".. cClientHandle.MIN_VIEW_DISTANCE .."-".. cClientHandle.MAX_VIEW_DISTANCE .."]" ) SendMessage( Player, "Usage: /viewdistance [".. cClientHandle.MIN_VIEW_DISTANCE .."-".. cClientHandle.MAX_VIEW_DISTANCE .."]" )
return true return true
end end
Player:GetClientHandle():SetViewDistance( Split[2] ) Player:GetClientHandle():SetViewDistance( Split[2] )
Player:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Your view distance has been set to " .. Player:GetClientHandle():GetViewDistance() ) SendMessageSuccess( Player, "Your view distance has been set to " .. Player:GetClientHandle():GetViewDistance() )
return true return true
end
end

View File

@ -1,3 +1,25 @@
function HandleWeatherCommand(Split, Player)
if #Split ~= 2 then
SendMessage( Player, "Usage: /weather [clear/rain/thunder]" )
return true
end
if (Split[2] == "clear") then
Player:GetWorld():SetWeather(0)
SendMessageSuccess( Player, "Downfall stopped" )
elseif (Split[2] == "rain") then
Player:GetWorld():SetWeather(1)
SendMessageSuccess( Player, "Let it rain!" )
elseif (Split[2] == "thunder") then
Player:GetWorld():SetWeather(2)
SendMessageSuccess( Player, "Thundery showers activate!")
end
return true
end
function HandleDownfallCommand( Split, Player ) function HandleDownfallCommand( Split, Player )
World = Player:GetWorld() World = Player:GetWorld()
if World:GetWeather() == 0 then if World:GetWeather() == 0 then
@ -5,6 +27,7 @@ function HandleDownfallCommand( Split, Player )
else else
World:SetWeather(0) World:SetWeather(0)
end end
Player:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "Downfall toggled")
return true SendMessageSuccess( Player, "Downfall Toggled")
end
end

View File

@ -10,15 +10,15 @@ local function ShowUsersTable()
local Content = "<h4>Users</h4>" local Content = "<h4>Users</h4>"
local NumUsers = UsersIni:GetNumKeys() local NumUsers = UsersIni:GetNumKeys()
Content = Content .. "<table>" Content = Content .. "<table>"
if( NumUsers > 0 ) then if( NumUsers > 0 ) then
Content = Content .. "<tr><th></th><th>User</th><th>Groups</th></tr>" Content = Content .. "<tr><th></th><th>User</th><th>Groups</th></tr>"
for i=0, NumUsers-1 do for i=0, NumUsers-1 do
local UserName = UsersIni:GetKeyName( i ) local UserName = UsersIni:GetKeyName( i )
Content = Content .. "<tr>" Content = Content .. "<tr>"
Content = Content .. "<td style='width: 10px;'>" .. i .. ".</td>" Content = Content .. "<td style='width: 10px;'>" .. i .. ".</td>"
Content = Content .. "<td>" .. UserName .. "</td>" Content = Content .. "<td>" .. UserName .. "</td>"
@ -31,23 +31,23 @@ local function ShowUsersTable()
Content = Content .. "<tr><td>None</td></tr>" Content = Content .. "<tr><td>None</td></tr>"
end end
Content = Content .. "</table>" Content = Content .. "</table>"
return Content return Content
end end
local function ShowGroupsTable() local function ShowGroupsTable()
local Content = "<h4>Groups</h4>" local Content = "<h4>Groups</h4>"
local NumGroups = GroupsIni:GetNumKeys() local NumGroups = GroupsIni:GetNumKeys()
Content = Content .. "<table>" Content = Content .. "<table>"
if( NumGroups > 0 ) then if( NumGroups > 0 ) then
Content = Content .. "<tr><th></th><th>Name</th><th>Permissions</th><th>Color</th></tr>" Content = Content .. "<tr><th></th><th>Name</th><th>Permissions</th><th>Color</th></tr>"
for i=0, NumGroups-1 do for i=0, NumGroups-1 do
local GroupName = GroupsIni:GetKeyName( i ) local GroupName = GroupsIni:GetKeyName( i )
Content = Content .. "<tr>" Content = Content .. "<tr>"
Content = Content .. "<td style='width: 10px;'>" .. i .. ".</td>" Content = Content .. "<td style='width: 10px;'>" .. i .. ".</td>"
Content = Content .. "<td>" .. GroupName .. "</td>" Content = Content .. "<td>" .. GroupName .. "</td>"
@ -63,14 +63,14 @@ local function ShowGroupsTable()
Content = Content .. "<tr><td>None</td></tr>" Content = Content .. "<tr><td>None</td></tr>"
end end
Content = Content .. "</table>" Content = Content .. "</table>"
return Content return Content
end end
local function HTML_Select_Group( name, defaultValue ) local function HTML_Select_Group( name, defaultValue )
Groups = "" Groups = ""
for I=0, GroupsIni:GetNumKeys() - 1 do for I=0, GroupsIni:GetNumKeys() - 1 do
Groups = Groups .. Groups = Groups ..
HTML_Option(GroupsIni:KeyName(I), GroupsIni:KeyName(I), defaultValue == GroupsIni:KeyName(I) ) HTML_Option(GroupsIni:KeyName(I), GroupsIni:KeyName(I), defaultValue == GroupsIni:KeyName(I) )
end end
return [[<select name="]] .. name .. [[">]] .. Groups .. [[</select>]] return [[<select name="]] .. name .. [[">]] .. Groups .. [[</select>]]
@ -90,7 +90,7 @@ local function AddPlayers( Request )
UsersIni:WriteFile() UsersIni:WriteFile()
local loopPlayers = function( Player ) local loopPlayers = function( Player )
if Player:GetName() == Request.PostParams["AddPlayer"] then if Player:GetName() == Request.PostParams["AddPlayer"] then
Player:SendMessage( cChatColor.Green .. "You were moved to group " .. Request.PostParams["AddGroup"] ) SendMessageSuccess( Player, "You were moved to group " .. Request.PostParams["AddGroup"] )
Player:LoadPermissionsFromDisk() Player:LoadPermissionsFromDisk()
end end
end end
@ -110,7 +110,7 @@ local function AddPlayers( Request )
<td>]] .. HTML_Select_Group("AddGroup", GroupsIni:KeyName(0) ) .. [[</td></tr> <td>]] .. HTML_Select_Group("AddGroup", GroupsIni:KeyName(0) ) .. [[</td></tr>
</table> </table>
<input type="submit" value="Add Player" name="AddPlayerToGroup">]] <input type="submit" value="Add Player" name="AddPlayerToGroup">]]
return Content return Content
end end
@ -123,12 +123,12 @@ function HandleRequest_Permissions( Request )
if( UsersIni:ReadFile() == false ) then if( UsersIni:ReadFile() == false ) then
return "Could not read users.ini!" return "Could not read users.ini!"
end end
local Content = "" local Content = ""
Content = Content .. AddPlayers( Request ) Content = Content .. AddPlayers( Request )
Content = Content .. ShowGroupsTable() Content = Content .. ShowGroupsTable()
Content = Content .. ShowUsersTable() Content = Content .. ShowUsersTable()
return Content return Content
end end

View File

@ -72,6 +72,8 @@ Wool = String, 1:1, 1:2, 2:1, 2:2
TNT = Gunpowder, 1:1, 3:1, 2:2, 1:3, 3:3 | Sand, 2:1, 1:2, 3:2, 2:3 TNT = Gunpowder, 1:1, 3:1, 2:2, 1:3, 3:3 | Sand, 2:1, 1:2, 3:2, 2:3
PillarQuartzBlock = QuartzSlab, 1:1, 1:2 PillarQuartzBlock = QuartzSlab, 1:1, 1:2
ChiseledQuartzBlock, 2 = QuartzBlock, 1:1, 1:2 ChiseledQuartzBlock, 2 = QuartzBlock, 1:1, 1:2
CoalBlock = Coal, 1:1, 1:2, 1:3, 2:1, 2:2, 2:3, 3:1, 3:2, 3:3
HayBale = Wheat, 1:1, 1:2, 1:3, 2:1, 2:2, 2:3, 3:1, 3:2, 3:3
# Slabs: # Slabs:
StoneSlab, 6 = Stone, 1:1, 2:1, 3:1 StoneSlab, 6 = Stone, 1:1, 2:1, 3:1
@ -105,7 +107,8 @@ SmoothSandstone, 4 = Sandstone, 1:1, 1:2, 2:1, 2:2
OrnamentSandstone = SandstoneSlab, 1:1, 1:2 OrnamentSandstone = SandstoneSlab, 1:1, 1:2
JackOLantern = Pumpkin, 1:1 | Torch, 1:2 JackOLantern = Pumpkin, 1:1 | Torch, 1:2
# Other
Carpet = Wool, 1:3, 2:3
@ -157,6 +160,7 @@ FishingRod = Stick, 3:3, 2:2, 1:1 | String, 1:2, 1:3
Shears = IronIngot, 1:1, 2:2 Shears = IronIngot, 1:1, 2:2
Shears = IronIngot, 2:1, 1:2 Shears = IronIngot, 2:1, 1:2
FireCharge = BlazePowder, * | Coal, * | Gunpowder, * FireCharge = BlazePowder, * | Coal, * | Gunpowder, *
Lead = String, 1:1, 1:2, 2:1, 3:3 | Slimeball, 2:2
@ -271,12 +275,13 @@ Bread = Wheat, 1:1, 2:1, 3:1
Sugar = Sugarcane, * Sugar = Sugarcane, *
Cake = MilkBucket, 1:1, 2:1, 3:1 | Sugar, 1:2, 3:2 | Egg, 2:2 | Wheat, 1:3, 2:3, 3:3 Cake = MilkBucket, 1:1, 2:1, 3:1 | Sugar, 1:2, 3:2 | Egg, 2:2 | Wheat, 1:3, 2:3, 3:3
Cookie = Wheat, *, * | CocoaBeans, * Cookie = Wheat, *, * | CocoaBeans, *
GoldenApple = RedApple, 2:2 | GoldNugget, 1:1, 1:2, 1:3, 2:1, 2:3, 3:1, 3:2, 3:3 GoldenApple = RedApple, 2:2 | GoldIngot, 1:1, 1:2, 1:3, 2:1, 2:3, 3:1, 3:2, 3:3
EnchantedGoldenApple = RedApple, 2:2 | GoldBlock, 1:1, 1:2, 1:3, 2:1, 2:3, 3:1, 3:2, 3:3 EnchantedGoldenApple = RedApple, 2:2 | GoldBlock, 1:1, 1:2, 1:3, 2:1, 2:3, 3:1, 3:2, 3:3
Melon = MelonSlice, 1:1, 1:2, 1:3, 2:1, 2:2, 2:3, 3:1, 3:2, 3:3 Melon = MelonSlice, 1:1, 1:2, 1:3, 2:1, 2:2, 2:3, 3:1, 3:2, 3:3
MelonSeeds = MelonSlice, * MelonSeeds = MelonSlice, *
PumpkinSeeds, 4 = Pumpkin, * PumpkinSeeds, 4 = Pumpkin, *
PumpkinPie = Pumpkin, * | Sugar, * | egg, * PumpkinPie = Pumpkin, * | Sugar, * | egg, *
Wheat, 9 = Haybale, *
@ -293,6 +298,8 @@ Diamond, 9 = DiamondBlock, *
LapisLazuli, 9 = LapisBlock, * LapisLazuli, 9 = LapisBlock, *
Emerald, 9 = EmeraldBlock, * Emerald, 9 = EmeraldBlock, *
RedstoneDust, 9 = RedstoneBlock, * RedstoneDust, 9 = RedstoneBlock, *
Coal, 9 = CoalBlock, *
Clay, 4 = ClayBlock, *
Painting = Stick, 1:1, 1:2, 1:3, 2:1, 2:3, 3:1, 3:2, 3:3 | Wool, 2:2 Painting = Stick, 1:1, 1:2, 1:3, 2:1, 2:3, 3:1, 3:2, 3:3 | Wool, 2:2
ItemFrame = Stick, 1:1, 1:2, 1:3, 2:1, 2:3, 3:1, 3:2, 3:3 | Leather, 2:2 ItemFrame = Stick, 1:1, 1:2, 1:3, 2:1, 2:3, 3:1, 3:2, 3:3 | Leather, 2:2
@ -382,7 +389,7 @@ BrewingStand = Cobblestone, 1:2, 2:2, 3:2 | BlazeRod, 2:1
BlazePowder, 2 = BlazeRod, * BlazePowder, 2 = BlazeRod, *
MagmaCream = SlimeBall, * | BlazePowder, * MagmaCream = SlimeBall, * | BlazePowder, *
FermentedSpiderEye = SpiderEye, * | Sugar, * | BrownMushroom, * FermentedSpiderEye = SpiderEye, * | Sugar, * | BrownMushroom, *
GlisteringMelon = MelonSlice, * | GoldNugget, * GlisteringMelon = MelonSlice, 2:2 | GoldNugget, 1:1, 1:2, 1:3, 2:1, 2:3, 3:1, 3:2, 3:3
GoldNugget, 9 = GoldIngot, * GoldNugget, 9 = GoldIngot, *
EnchantmentTable = Obsidian, 1:3, 2:3, 3:3, 2:2 | Diamond, 1:2, 3:2 | Book, 2:1 EnchantmentTable = Obsidian, 1:3, 2:3, 3:3, 2:2 | Diamond, 1:2, 3:2 | Book, 2:1

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
/* /*
** Lua binding: AllToLua ** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 08/09/13 14:50:49. ** Generated automatically by tolua++-1.0.92 on 08/12/13 11:15:34.
*/ */
/* Exported function */ /* Exported function */
TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S); TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S);

View File

@ -7,6 +7,7 @@
#include "HopperEntity.h" #include "HopperEntity.h"
#include "../Chunk.h" #include "../Chunk.h"
#include "../Player.h" #include "../Player.h"
#include "../PluginManager.h"
#include "ChestEntity.h" #include "ChestEntity.h"
#include "DropSpenserEntity.h" #include "DropSpenserEntity.h"
#include "FurnaceEntity.h" #include "FurnaceEntity.h"
@ -162,12 +163,26 @@ bool cHopperEntity::MoveItemsIn(cChunk & a_Chunk, Int64 a_CurrentTick)
bool res = false; bool res = false;
switch (a_Chunk.GetBlock(m_RelX, m_PosY + 1, m_RelZ)) switch (a_Chunk.GetBlock(m_RelX, m_PosY + 1, m_RelZ))
{ {
case E_BLOCK_CHEST: res = MoveItemsFromChest(a_Chunk); break; case E_BLOCK_CHEST:
case E_BLOCK_FURNACE: res = MoveItemsFromFurnace(a_Chunk); break; {
// Chests have special handling because of double-chests
res = MoveItemsFromChest(a_Chunk);
break;
}
case E_BLOCK_LIT_FURNACE:
case E_BLOCK_FURNACE:
{
// Furnaces have special handling because only the output and leftover fuel buckets shall be moved
res = MoveItemsFromFurnace(a_Chunk);
break;
}
case E_BLOCK_DISPENSER: case E_BLOCK_DISPENSER:
case E_BLOCK_DROPPER: res = MoveItemsFromGrid(((cDropSpenserEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ))->GetContents()); break; case E_BLOCK_DROPPER:
case E_BLOCK_HOPPER: res = MoveItemsFromGrid(((cHopperEntity *) a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ))->GetContents()); break; case E_BLOCK_HOPPER:
case E_BLOCK_LIT_FURNACE: res = MoveItemsFromFurnace(a_Chunk); break; {
res = MoveItemsFromGrid(*(cBlockEntityWithItems *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ));
break;
}
} }
// If the item has been moved, reset the last tick: // If the item has been moved, reset the last tick:
@ -230,12 +245,26 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick)
bool res = false; bool res = false;
switch (DestChunk->GetBlock(rx, by, rz)) switch (DestChunk->GetBlock(rx, by, rz))
{ {
case E_BLOCK_CHEST: res = MoveItemsToChest(*DestChunk, bx, by, bz); break; case E_BLOCK_CHEST:
case E_BLOCK_FURNACE: res = MoveItemsToFurnace(*DestChunk, bx, by, bz, Meta); break; {
// Chests have special handling because of double-chests
res = MoveItemsToChest(*DestChunk, bx, by, bz);
break;
}
case E_BLOCK_LIT_FURNACE:
case E_BLOCK_FURNACE:
{
// Furnaces have special handling because of the direction-to-slot relation
res = MoveItemsToFurnace(*DestChunk, bx, by, bz, Meta);
break;
}
case E_BLOCK_DISPENSER: case E_BLOCK_DISPENSER:
case E_BLOCK_DROPPER: res = MoveItemsToGrid(((cDropSpenserEntity *)DestChunk->GetBlockEntity(bx, by, bz))->GetContents()); break; case E_BLOCK_DROPPER:
case E_BLOCK_HOPPER: res = MoveItemsToGrid(((cHopperEntity *) DestChunk->GetBlockEntity(bx, by, bz))->GetContents()); break; case E_BLOCK_HOPPER:
case E_BLOCK_LIT_FURNACE: res = MoveItemsToFurnace(*DestChunk, bx, by, bz, Meta); break; {
res = MoveItemsToGrid(*(cBlockEntityWithItems *)DestChunk->GetBlockEntity(bx, by, bz));
break;
}
} }
// If the item has been moved, reset the last tick: // If the item has been moved, reset the last tick:
@ -254,7 +283,7 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick)
/// Moves items from a chest (dblchest) above the hopper into this hopper. Returns true if contents have changed. /// Moves items from a chest (dblchest) above the hopper into this hopper. Returns true if contents have changed.
bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk) bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk)
{ {
if (MoveItemsFromGrid(((cChestEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ))->GetContents())) if (MoveItemsFromGrid(*(cChestEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ)))
{ {
// Moved the item from the chest directly above the hopper // Moved the item from the chest directly above the hopper
return true; return true;
@ -284,7 +313,7 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk)
{ {
continue; continue;
} }
if (MoveItemsFromGrid(((cChestEntity *)Neighbor->GetBlockEntity(x, m_PosY, z))->GetContents())) if (MoveItemsFromGrid(*(cChestEntity *)Neighbor->GetBlockEntity(x, m_PosY, z)))
{ {
return true; return true;
} }
@ -306,7 +335,7 @@ bool cHopperEntity::MoveItemsFromFurnace(cChunk & a_Chunk)
ASSERT(Furnace != NULL); ASSERT(Furnace != NULL);
// Try move from the output slot: // Try move from the output slot:
if (MoveItemsFromSlot(Furnace->GetOutputSlot(), true)) if (MoveItemsFromSlot(*Furnace, cFurnaceEntity::fsOutput, true))
{ {
cItem NewOutput(Furnace->GetOutputSlot()); cItem NewOutput(Furnace->GetOutputSlot());
Furnace->SetOutputSlot(NewOutput.AddCount(-1)); Furnace->SetOutputSlot(NewOutput.AddCount(-1));
@ -316,7 +345,7 @@ bool cHopperEntity::MoveItemsFromFurnace(cChunk & a_Chunk)
// No output moved, check if we can move an empty bucket out of the fuel slot: // No output moved, check if we can move an empty bucket out of the fuel slot:
if (Furnace->GetFuelSlot().m_ItemType == E_ITEM_BUCKET) if (Furnace->GetFuelSlot().m_ItemType == E_ITEM_BUCKET)
{ {
if (MoveItemsFromSlot(Furnace->GetFuelSlot(), true)) if (MoveItemsFromSlot(*Furnace, cFurnaceEntity::fsFuel, true))
{ {
Furnace->SetFuelSlot(cItem()); Furnace->SetFuelSlot(cItem());
return true; return true;
@ -331,21 +360,21 @@ bool cHopperEntity::MoveItemsFromFurnace(cChunk & a_Chunk)
/// Moves items from the specified ItemGrid into this hopper. Returns true if contents have changed. bool cHopperEntity::MoveItemsFromGrid(cBlockEntityWithItems & a_Entity)
bool cHopperEntity::MoveItemsFromGrid(cItemGrid & a_Grid)
{ {
int NumSlots = a_Grid.GetNumSlots(); cItemGrid & Grid = a_Entity.GetContents();
int NumSlots = Grid.GetNumSlots();
// First try adding items of types already in the hopper: // First try adding items of types already in the hopper:
for (int i = 0; i < NumSlots; i++) for (int i = 0; i < NumSlots; i++)
{ {
if (a_Grid.IsSlotEmpty(i)) if (Grid.IsSlotEmpty(i))
{ {
continue; continue;
} }
if (MoveItemsFromSlot(a_Grid.GetSlot(i), false)) if (MoveItemsFromSlot(a_Entity, i, false))
{ {
a_Grid.ChangeSlotCount(i, -1); Grid.ChangeSlotCount(i, -1);
return true; return true;
} }
} }
@ -353,13 +382,13 @@ bool cHopperEntity::MoveItemsFromGrid(cItemGrid & a_Grid)
// No already existing stack can be topped up, try again with allowing new stacks: // No already existing stack can be topped up, try again with allowing new stacks:
for (int i = 0; i < NumSlots; i++) for (int i = 0; i < NumSlots; i++)
{ {
if (a_Grid.IsSlotEmpty(i)) if (Grid.IsSlotEmpty(i))
{ {
continue; continue;
} }
if (MoveItemsFromSlot(a_Grid.GetSlot(i), true)) if (MoveItemsFromSlot(a_Entity, i, true))
{ {
a_Grid.ChangeSlotCount(i, -1); Grid.ChangeSlotCount(i, -1);
return true; return true;
} }
} }
@ -370,13 +399,36 @@ bool cHopperEntity::MoveItemsFromGrid(cItemGrid & a_Grid)
/// Moves one of the specified itemstack into this hopper. Returns true if contents have changed. Doesn't change the itemstack. /// Moves one piece of the specified a_Entity's slot itemstack into this hopper. Returns true if contents have changed. Doesn't change the itemstack.
bool cHopperEntity::MoveItemsFromSlot(const cItem & a_ItemStack, bool a_AllowNewStacks) bool cHopperEntity::MoveItemsFromSlot(cBlockEntityWithItems & a_Entity, int a_SlotNum, bool a_AllowNewStacks)
{ {
cItem One(a_ItemStack.CopyOne()); cItem One(a_Entity.GetSlot(a_SlotNum).CopyOne());
if (m_Contents.AddItem(One, a_AllowNewStacks) > 0) for (int i = 0; i < ContentsWidth * ContentsHeight; i++)
{ {
return true; if (m_Contents.IsSlotEmpty(i))
{
if (a_AllowNewStacks)
{
if (cPluginManager::Get()->CallHookHopperPullingItem(*m_World, *this, i, a_Entity, a_SlotNum))
{
// Plugin disagrees with the move
continue;
}
}
m_Contents.SetSlot(i, One);
return true;
}
else if (m_Contents.GetSlot(i).IsStackableWith(One))
{
if (cPluginManager::Get()->CallHookHopperPullingItem(*m_World, *this, i, a_Entity, a_SlotNum))
{
// Plugin disagrees with the move
continue;
}
m_Contents.ChangeSlotCount(i, 1);
return true;
}
} }
return false; return false;
} }
@ -389,7 +441,7 @@ bool cHopperEntity::MoveItemsFromSlot(const cItem & a_ItemStack, bool a_AllowNew
bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ) bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ)
{ {
// Try the chest directly connected to the hopper: // Try the chest directly connected to the hopper:
if (MoveItemsToGrid(((cChestEntity *)a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ))->GetContents())) if (MoveItemsToGrid(*(cChestEntity *)a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ)))
{ {
return true; return true;
} }
@ -418,7 +470,7 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_Block
{ {
continue; continue;
} }
if (MoveItemsToGrid(((cChestEntity *)Neighbor->GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ))->GetContents())) if (MoveItemsToGrid(*(cChestEntity *)Neighbor->GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ)))
{ {
return true; return true;
} }
@ -440,12 +492,12 @@ bool cHopperEntity::MoveItemsToFurnace(cChunk & a_Chunk, int a_BlockX, int a_Blo
if (a_HopperMeta == E_META_HOPPER_FACING_YM) if (a_HopperMeta == E_META_HOPPER_FACING_YM)
{ {
// Feed the input slot of the furnace // Feed the input slot of the furnace
return MoveItemsToSlot(Furnace->GetContents(), cFurnaceEntity::fsInput); return MoveItemsToSlot(*Furnace, cFurnaceEntity::fsInput);
} }
else else
{ {
// Feed the fuel slot of the furnace // Feed the fuel slot of the furnace
return MoveItemsToSlot(Furnace->GetContents(), cFurnaceEntity::fsFuel); return MoveItemsToSlot(*Furnace, cFurnaceEntity::fsFuel);
} }
return false; return false;
} }
@ -454,22 +506,14 @@ bool cHopperEntity::MoveItemsToFurnace(cChunk & a_Chunk, int a_BlockX, int a_Blo
/// Moves items to the specified ItemGrid. Returns true if contents have changed bool cHopperEntity::MoveItemsToGrid(cBlockEntityWithItems & a_Entity)
bool cHopperEntity::MoveItemsToGrid(cItemGrid & a_ItemGrid)
{ {
// Iterate through our slots, try to move from each one: // Iterate through our slots, try to move from each one:
for (int i = 0; i < ContentsWidth * ContentsHeight; i++) int NumSlots = a_Entity.GetContents().GetNumSlots();
for (int i = 0; i < NumSlots; i++)
{ {
const cItem & SrcItem = m_Contents.GetSlot(i); if (MoveItemsToSlot(a_Entity, i))
if (SrcItem.IsEmpty())
{ {
continue;
}
cItem ToAdd = SrcItem.CopyOne();
if (a_ItemGrid.AddItem(ToAdd) > 0)
{
m_Contents.ChangeSlotCount(i, -1);
return true; return true;
} }
} }
@ -480,17 +524,22 @@ bool cHopperEntity::MoveItemsToGrid(cItemGrid & a_ItemGrid)
/// Moves one piece to the specified ItemGrid's slot. Returns true if contents have changed. bool cHopperEntity::MoveItemsToSlot(cBlockEntityWithItems & a_Entity, int a_DstSlotNum)
bool cHopperEntity::MoveItemsToSlot(cItemGrid & a_ItemGrid, int a_DestSlotNum)
{ {
if (a_ItemGrid.IsSlotEmpty(a_DestSlotNum)) cItemGrid & Grid = a_Entity.GetContents();
if (Grid.IsSlotEmpty(a_DstSlotNum))
{ {
// The slot is empty, move the first non-empty slot from our contents: // The slot is empty, move the first non-empty slot from our contents:
for (int i = 0; i < ContentsWidth * ContentsHeight; i++) for (int i = 0; i < ContentsWidth * ContentsHeight; i++)
{ {
if (!m_Contents.IsSlotEmpty(i)) if (!m_Contents.IsSlotEmpty(i))
{ {
a_ItemGrid.SetSlot(a_DestSlotNum, m_Contents.GetSlot(i).CopyOne()); if (cPluginManager::Get()->CallHookHopperPushingItem(*m_World, *this, i, a_Entity, a_DstSlotNum))
{
// A plugin disagrees with the move
continue;
}
Grid.SetSlot(a_DstSlotNum, m_Contents.GetSlot(i).CopyOne());
m_Contents.ChangeSlotCount(i, -1); m_Contents.ChangeSlotCount(i, -1);
return true; return true;
} }
@ -500,7 +549,7 @@ bool cHopperEntity::MoveItemsToSlot(cItemGrid & a_ItemGrid, int a_DestSlotNum)
else else
{ {
// The slot is taken, try to top it up: // The slot is taken, try to top it up:
const cItem & DestSlot = a_ItemGrid.GetSlot(a_DestSlotNum); const cItem & DestSlot = Grid.GetSlot(a_DstSlotNum);
if (DestSlot.IsFullStack()) if (DestSlot.IsFullStack())
{ {
return false; return false;
@ -509,7 +558,12 @@ bool cHopperEntity::MoveItemsToSlot(cItemGrid & a_ItemGrid, int a_DestSlotNum)
{ {
if (m_Contents.GetSlot(i).IsStackableWith(DestSlot)) if (m_Contents.GetSlot(i).IsStackableWith(DestSlot))
{ {
a_ItemGrid.ChangeSlotCount(a_DestSlotNum, 1); if (cPluginManager::Get()->CallHookHopperPushingItem(*m_World, *this, i, a_Entity, a_DstSlotNum))
{
// A plugin disagrees with the move
continue;
}
Grid.ChangeSlotCount(a_DstSlotNum, 1);
m_Contents.ChangeSlotCount(i, -1); m_Contents.ChangeSlotCount(i, -1);
return true; return true;
} }

View File

@ -78,11 +78,11 @@ protected:
/// Moves items from a furnace above the hopper into this hopper. Returns true if contents have changed. /// Moves items from a furnace above the hopper into this hopper. Returns true if contents have changed.
bool MoveItemsFromFurnace(cChunk & a_Chunk); bool MoveItemsFromFurnace(cChunk & a_Chunk);
/// Moves items from the specified ItemGrid into this hopper. Returns true if contents have changed. /// Moves items from the specified a_Entity's Contents into this hopper. Returns true if contents have changed.
bool MoveItemsFromGrid(cItemGrid & a_Grid); bool MoveItemsFromGrid(cBlockEntityWithItems & a_Entity);
/// Moves one piece from the specified itemstack into this hopper. Returns true if contents have changed. Doesn't change the itemstack. /// Moves one piece from the specified itemstack into this hopper. Returns true if contents have changed. Doesn't change the itemstack.
bool MoveItemsFromSlot(const cItem & a_ItemStack, bool a_AllowNewStacks); bool MoveItemsFromSlot(cBlockEntityWithItems & a_Entity, int a_SrcSlotNum, bool a_AllowNewStacks);
/// Moves items to the chest at the specified coords. Returns true if contents have changed /// Moves items to the chest at the specified coords. Returns true if contents have changed
bool MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ); bool MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ);
@ -91,10 +91,10 @@ protected:
bool MoveItemsToFurnace(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_HopperMeta); bool MoveItemsToFurnace(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_HopperMeta);
/// Moves items to the specified ItemGrid. Returns true if contents have changed /// Moves items to the specified ItemGrid. Returns true if contents have changed
bool MoveItemsToGrid(cItemGrid & a_ItemGrid); bool MoveItemsToGrid(cBlockEntityWithItems & a_Entity);
/// Moves one piece to the specified ItemGrid's slot. Returns true if contents have changed. /// Moves one piece to the specified entity's contents' slot. Returns true if contents have changed.
bool MoveItemsToSlot(cItemGrid & a_ItemGrid, int a_DestSlotNum); bool MoveItemsToSlot(cBlockEntityWithItems & a_Entity, int a_DstSlotNum);
} ; } ;

View File

@ -165,6 +165,7 @@ enum ENUM_BLOCK_ID
E_BLOCK_NETHER_QUARTZ_ORE = 153, E_BLOCK_NETHER_QUARTZ_ORE = 153,
E_BLOCK_HOPPER = 154, E_BLOCK_HOPPER = 154,
E_BLOCK_QUARTZ_BLOCK = 155, E_BLOCK_QUARTZ_BLOCK = 155,
E_BLOCK_QUARTZ_STAIR = 156,
E_BLOCK_ACTIVATOR_RAIL = 157, E_BLOCK_ACTIVATOR_RAIL = 157,
E_BLOCK_DROPPER = 158, E_BLOCK_DROPPER = 158,

View File

@ -152,6 +152,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
case E_BLOCK_PISTON_EXTENSION: return new cBlockPistonHeadHandler (); case E_BLOCK_PISTON_EXTENSION: return new cBlockPistonHeadHandler ();
case E_BLOCK_PLANKS: return new cBlockWoodHandler (a_BlockType); case E_BLOCK_PLANKS: return new cBlockWoodHandler (a_BlockType);
case E_BLOCK_PUMPKIN_STEM: return new cBlockStemsHandler (a_BlockType); case E_BLOCK_PUMPKIN_STEM: return new cBlockStemsHandler (a_BlockType);
case E_BLOCK_QUARTZ_STAIR: return new cBlockStairsHandler (a_BlockType);
case E_BLOCK_RAIL: return new cBlockRailHandler (a_BlockType); case E_BLOCK_RAIL: return new cBlockRailHandler (a_BlockType);
case E_BLOCK_POTATOES: return new cBlockCropsHandler (a_BlockType); case E_BLOCK_POTATOES: return new cBlockCropsHandler (a_BlockType);
case E_BLOCK_POWERED_RAIL: return new cBlockRailHandler (a_BlockType); case E_BLOCK_POWERED_RAIL: return new cBlockRailHandler (a_BlockType);

View File

@ -213,7 +213,7 @@ void cItemGrid::Clear(void)
int cItemGrid::HowManyCanFit(const cItem & a_ItemStack) int cItemGrid::HowManyCanFit(const cItem & a_ItemStack, bool a_AllowNewStacks)
{ {
char NumLeft = a_ItemStack.m_ItemCount; char NumLeft = a_ItemStack.m_ItemCount;
int MaxStack = ItemHandler(a_ItemStack.m_ItemType)->GetMaxStackSize(); int MaxStack = ItemHandler(a_ItemStack.m_ItemType)->GetMaxStackSize();
@ -221,7 +221,10 @@ int cItemGrid::HowManyCanFit(const cItem & a_ItemStack)
{ {
if (m_Slots[i].IsEmpty()) if (m_Slots[i].IsEmpty())
{ {
NumLeft -= MaxStack; if (a_AllowNewStacks)
{
NumLeft -= MaxStack;
}
} }
else if (m_Slots[i].IsStackableWith(a_ItemStack)) else if (m_Slots[i].IsStackableWith(a_ItemStack))
{ {

View File

@ -72,7 +72,7 @@ public:
void Clear(void); void Clear(void);
/// Returns number of items out of a_ItemStack that can fit in the storage /// Returns number of items out of a_ItemStack that can fit in the storage
int HowManyCanFit(const cItem & a_ItemStack); int HowManyCanFit(const cItem & a_ItemStack, bool a_AllowNewStacks = true);
/** Adds as many items out of a_ItemStack as can fit. /** Adds as many items out of a_ItemStack as can fit.
If a_AllowNewStacks is set to false, only existing stacks can be topped up; If a_AllowNewStacks is set to false, only existing stacks can be topped up;

View File

@ -138,7 +138,7 @@ void cLog::Log(const char * a_Format, va_list argList)
#if defined (_WIN32) && defined(_DEBUG) #if defined (_WIN32) && defined(_DEBUG)
// In a Windows Debug build, output the log to debug console as well: // In a Windows Debug build, output the log to debug console as well:
OutputDebugStringA(Line.c_str()); OutputDebugStringA((Line + "\n").c_str());
#endif // _WIN32 #endif // _WIN32
} }

View File

@ -677,6 +677,32 @@ void cLuaState::Push(void * a_Ptr)
void cLuaState::Push(cHopperEntity * a_Hopper)
{
ASSERT(IsValid());
ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
tolua_pushusertype(m_LuaState, a_Hopper, "cHopperEntity");
m_NumCurrentFunctionArgs += 1;
}
void cLuaState::Push(cBlockEntity * a_BlockEntity)
{
ASSERT(IsValid());
ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
tolua_pushusertype(m_LuaState, a_BlockEntity, "cBlockEntity");
m_NumCurrentFunctionArgs += 1;
}
void cLuaState::GetReturn(int a_StackPos, bool & a_ReturnedVal) void cLuaState::GetReturn(int a_StackPos, bool & a_ReturnedVal)
{ {
a_ReturnedVal = (tolua_toboolean(m_LuaState, a_StackPos, a_ReturnedVal ? 1 : 0) > 0); a_ReturnedVal = (tolua_toboolean(m_LuaState, a_StackPos, a_ReturnedVal ? 1 : 0) > 0);

View File

@ -53,6 +53,8 @@ struct HTTPTemplateRequest;
class cTNTEntity; class cTNTEntity;
class cCreeper; class cCreeper;
class Vector3i; class Vector3i;
class cHopperEntity;
class cBlockEntity;
@ -178,6 +180,8 @@ public:
void Push(cCreeper * a_Creeper); void Push(cCreeper * a_Creeper);
void Push(Vector3i * a_Vector); void Push(Vector3i * a_Vector);
void Push(void * a_Ptr); void Push(void * a_Ptr);
void Push(cHopperEntity * a_Hopper);
void Push(cBlockEntity * a_BlockEntity);
/// Call any 0-param 0-return Lua function in a single line: /// Call any 0-param 0-return Lua function in a single line:
template <typename FnT> template <typename FnT>

View File

@ -75,7 +75,9 @@ cMCLogger::~cMCLogger()
m_Log->Log("--- Stopped Log ---\n"); m_Log->Log("--- Stopped Log ---\n");
delete m_Log; delete m_Log;
if (this == s_MCLogger) if (this == s_MCLogger)
{
s_MCLogger = NULL; s_MCLogger = NULL;
}
} }

View File

@ -54,9 +54,9 @@ cIsThread::cIsThread(const AString & iThreadName) :
m_ThreadName(iThreadName), m_ThreadName(iThreadName),
m_ShouldTerminate(false), m_ShouldTerminate(false),
#ifdef _WIN32 #ifdef _WIN32
m_Handle(NULL) m_Handle(NULL)
#else // _WIN32 #else // _WIN32
m_HasStarted(false) m_HasStarted(false)
#endif // else _WIN32 #endif // else _WIN32
{ {
} }

View File

@ -26,18 +26,24 @@ In the descending class' constructor call the Start() method to start the thread
class cIsThread class cIsThread
{ {
protected: protected:
virtual void Execute(void) = 0; // This function is called in the new thread's context /// This is the main thread entrypoint
virtual void Execute(void) = 0;
volatile bool m_ShouldTerminate; // The overriden Execute() method should check this periodically and terminate if this is true /// The overriden Execute() method should check this value periodically and terminate if this is true
volatile bool m_ShouldTerminate;
public: public:
cIsThread(const AString & iThreadName); cIsThread(const AString & iThreadName);
~cIsThread(); ~cIsThread();
bool Start(void); // Starts the thread /// Starts the thread; returns without waiting for the actual start
bool Wait(void); // Waits for the thread to finish bool Start(void);
static unsigned long GetCurrentID(void); // Returns the OS-dependent thread ID for the caller's thread /// Waits for the thread to finish. Doesn't signalize the ShouldTerminate flag
bool Wait(void);
/// Returns the OS-dependent thread ID for the caller's thread
static unsigned long GetCurrentID(void);
private: private:
AString m_ThreadName; AString m_ThreadName;

View File

@ -777,8 +777,8 @@ void cPlayer::SendMessage(const AString & a_Message)
void cPlayer::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) void cPlayer::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ)
{ {
m_LastGroundHeight = (float)a_PosY;
SetPosition( a_PosX, a_PosY, a_PosZ ); SetPosition( a_PosX, a_PosY, a_PosZ );
m_LastGroundHeight = (float)a_PosY;
m_World->BroadcastTeleportEntity(*this, GetClientHandle()); m_World->BroadcastTeleportEntity(*this, GetClientHandle());
m_ClientHandle->SendPlayerMoveLook(); m_ClientHandle->SendPlayerMoveLook();

View File

@ -61,6 +61,8 @@ public:
virtual bool OnExploded (cWorld & a_World, double a_ExplosionSize, bool a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData) = 0; virtual bool OnExploded (cWorld & a_World, double a_ExplosionSize, bool a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData) = 0;
virtual bool OnExploding (cWorld & a_World, double & a_ExplosionSize, bool & a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData) = 0; virtual bool OnExploding (cWorld & a_World, double & a_ExplosionSize, bool & a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData) = 0;
virtual bool OnHandshake (cClientHandle * a_Client, const AString & a_Username) = 0; virtual bool OnHandshake (cClientHandle * a_Client, const AString & a_Username) = 0;
virtual bool OnHopperPullingItem (cWorld & a_World, cHopperEntity & a_Hopper, int a_DstSlotNum, cBlockEntityWithItems & a_SrcEntity, int a_SrcSlotNum) = 0;
virtual bool OnHopperPushingItem (cWorld & a_World, cHopperEntity & a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems & a_DstEntity, int a_DstSlotNum) = 0;
virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer) = 0; virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer) = 0;
virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username) = 0; virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username) = 0;
virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) = 0; virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) = 0;

View File

@ -326,6 +326,30 @@ bool cPlugin_NewLua::OnHandshake(cClientHandle * a_Client, const AString & a_Use
bool cPlugin_NewLua::OnHopperPullingItem(cWorld & a_World, cHopperEntity & a_Hopper, int a_DstSlotNum, cBlockEntityWithItems & a_SrcEntity, int a_SrcSlotNum)
{
cCSLock Lock(m_CriticalSection);
bool res = false;
m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_HOPPER_PULLING_ITEM), &a_World, &a_Hopper, a_DstSlotNum, &a_SrcEntity, a_SrcSlotNum, cLuaState::Return, res);
return res;
}
bool cPlugin_NewLua::OnHopperPushingItem(cWorld & a_World, cHopperEntity & a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems & a_DstEntity, int a_DstSlotNum)
{
cCSLock Lock(m_CriticalSection);
bool res = false;
m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_HOPPER_PUSHING_ITEM), &a_World, &a_Hopper, a_SrcSlotNum, &a_DstEntity, a_DstSlotNum, cLuaState::Return, res);
return res;
}
bool cPlugin_NewLua::OnKilling(cEntity & a_Victim, cEntity * a_Killer) bool cPlugin_NewLua::OnKilling(cEntity & a_Victim, cEntity * a_Killer)
{ {
cCSLock Lock(m_CriticalSection); cCSLock Lock(m_CriticalSection);

View File

@ -57,6 +57,8 @@ public:
virtual bool OnExploded (cWorld & a_World, double a_ExplosionSize, bool a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData) override; virtual bool OnExploded (cWorld & a_World, double a_ExplosionSize, bool a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData) override;
virtual bool OnExploding (cWorld & a_World, double & a_ExplosionSize, bool & a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData) override; virtual bool OnExploding (cWorld & a_World, double & a_ExplosionSize, bool & a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData) override;
virtual bool OnHandshake (cClientHandle * a_Client, const AString & a_Username) override; virtual bool OnHandshake (cClientHandle * a_Client, const AString & a_Username) override;
virtual bool OnHopperPullingItem (cWorld & a_World, cHopperEntity & a_Hopper, int a_DstSlotNum, cBlockEntityWithItems & a_SrcEntity, int a_SrcSlotNum) override;
virtual bool OnHopperPushingItem (cWorld & a_World, cHopperEntity & a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems & a_DstEntity, int a_DstSlotNum) override;
virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer) override; virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer) override;
virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username) override; virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username) override;
virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) override; virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) override;

View File

@ -489,6 +489,48 @@ bool cPluginManager::CallHookHandshake(cClientHandle * a_ClientHandle, const ASt
bool cPluginManager::CallHookHopperPullingItem(cWorld & a_World, cHopperEntity & a_Hopper, int a_DstSlotNum, cBlockEntityWithItems & a_SrcEntity, int a_SrcSlotNum)
{
HookMap::iterator Plugins = m_Hooks.find(HOOK_HOPPER_PULLING_ITEM);
if (Plugins == m_Hooks.end())
{
return false;
}
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
{
if ((*itr)->OnHopperPullingItem(a_World, a_Hopper, a_DstSlotNum, a_SrcEntity, a_SrcSlotNum))
{
return true;
}
}
return false;
}
bool cPluginManager::CallHookHopperPushingItem(cWorld & a_World, cHopperEntity & a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems & a_DstEntity, int a_DstSlotNum)
{
HookMap::iterator Plugins = m_Hooks.find(HOOK_HOPPER_PUSHING_ITEM);
if (Plugins == m_Hooks.end())
{
return false;
}
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
{
if ((*itr)->OnHopperPushingItem(a_World, a_Hopper, a_SrcSlotNum, a_DstEntity, a_DstSlotNum))
{
return true;
}
}
return false;
}
bool cPluginManager::CallHookKilling(cEntity & a_Victim, cEntity * a_Killer) bool cPluginManager::CallHookKilling(cEntity & a_Victim, cEntity * a_Killer)
{ {
HookMap::iterator Plugins = m_Hooks.find(HOOK_KILLING); HookMap::iterator Plugins = m_Hooks.find(HOOK_KILLING);

View File

@ -38,6 +38,12 @@ class cPawn;
// fwd: CommandOutput.h // fwd: CommandOutput.h
class cCommandOutputCallback; class cCommandOutputCallback;
// fwd: BlockEntities/HopperEntity.h
class cHopperEntity;
// fwd: BlockEntities/BlockEntityWithItems.h
class cBlockEntityWithItems;
@ -66,6 +72,8 @@ public: // tolua_export
HOOK_EXPLODED, HOOK_EXPLODED,
HOOK_EXPLODING, HOOK_EXPLODING,
HOOK_HANDSHAKE, HOOK_HANDSHAKE,
HOOK_HOPPER_PULLING_ITEM,
HOOK_HOPPER_PUSHING_ITEM,
HOOK_KILLING, HOOK_KILLING,
HOOK_LOGIN, HOOK_LOGIN,
HOOK_PLAYER_ANIMATION, HOOK_PLAYER_ANIMATION,
@ -143,6 +151,8 @@ public: // tolua_export
bool CallHookExploded (cWorld & a_World, double a_ExplosionSize, bool a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData); bool CallHookExploded (cWorld & a_World, double a_ExplosionSize, bool a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData);
bool CallHookExploding (cWorld & a_World, double & a_ExplosionSize, bool & a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData); bool CallHookExploding (cWorld & a_World, double & a_ExplosionSize, bool & a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData);
bool CallHookHandshake (cClientHandle * a_ClientHandle, const AString & a_Username); bool CallHookHandshake (cClientHandle * a_ClientHandle, const AString & a_Username);
bool CallHookHopperPullingItem (cWorld & a_World, cHopperEntity & a_Hopper, int a_DstSlotNum, cBlockEntityWithItems & a_SrcEntity, int a_SrcSlotNum);
bool CallHookHopperPushingItem (cWorld & a_World, cHopperEntity & a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems & a_DstEntity, int a_DstSlotNum);
bool CallHookKilling (cEntity & a_Victim, cEntity * a_Killer); bool CallHookKilling (cEntity & a_Victim, cEntity * a_Killer);
bool CallHookLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username); bool CallHookLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username);
bool CallHookPlayerAnimation (cPlayer & a_Player, int a_Animation); bool CallHookPlayerAnimation (cPlayer & a_Player, int a_Animation);

View File

@ -694,6 +694,13 @@ void cWorld::TickSpawnMobs(float a_Dt)
case 6: MobType = E_ENTITY_TYPE_ZOMBIE_PIGMAN; break; case 6: MobType = E_ENTITY_TYPE_ZOMBIE_PIGMAN; break;
} }
} }
else if (GetBiomeAt((int)SpawnPos.x, (int)SpawnPos.z) == biSky)
{
switch (nightRand)
{
case 5: MobType = E_ENTITY_TYPE_ENDERMAN; break;
}
}
else else
{ {
switch (nightRand) switch (nightRand)