summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLogicParrot <LogicParrot@users.noreply.github.com>2016-02-08 11:35:15 +0100
committerLogicParrot <LogicParrot@users.noreply.github.com>2016-02-08 11:35:15 +0100
commit345eec5a2e3d60adb58e63185abd9b319d657765 (patch)
tree398522505d124f696735b07c82701b0829110158
parentMerge pull request #2961 from LogicParrot/enforce (diff)
parentremove cWorld::createAndInitializeWorld (diff)
downloadcuberite-345eec5a2e3d60adb58e63185abd9b319d657765.tar
cuberite-345eec5a2e3d60adb58e63185abd9b319d657765.tar.gz
cuberite-345eec5a2e3d60adb58e63185abd9b319d657765.tar.bz2
cuberite-345eec5a2e3d60adb58e63185abd9b319d657765.tar.lz
cuberite-345eec5a2e3d60adb58e63185abd9b319d657765.tar.xz
cuberite-345eec5a2e3d60adb58e63185abd9b319d657765.tar.zst
cuberite-345eec5a2e3d60adb58e63185abd9b319d657765.zip
-rw-r--r--Server/Plugins/APIDump/APIDesc.lua1
-rw-r--r--src/Entities/Entity.cpp14
-rw-r--r--src/Entities/Player.cpp2
-rw-r--r--src/Root.cpp29
-rw-r--r--src/Root.h13
5 files changed, 14 insertions, 45 deletions
diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua
index 97e17c7c6..0cbdff479 100644
--- a/Server/Plugins/APIDump/APIDesc.lua
+++ b/Server/Plugins/APIDump/APIDesc.lua
@@ -2126,7 +2126,6 @@ a_Player:OpenWindow(Window);
BroadcastChatLeave = { Params = "MessageText", Return = "", Notes = "Broadcasts the specified message to all players, with its message type set to mtLeave. Use for players leaving the server." },
BroadcastChatSuccess = { Params = "MessageText", Return = "", Notes = "Broadcasts the specified message to all players, with its message type set to mtSuccess. Use for success messages." },
BroadcastChatWarning = { Params = "MessageText", Return = "", Notes = "Broadcasts the specified message to all players, with its message type set to mtWarning. Use for concerning events, such as plugin reload etc." },
- CreateAndInitializeWorld = { Params = "WorldName", Return = "{{cWorld|cWorld}}", Notes = "Creates a new world and initializes it. If there is a world whith the same name it returns nil.<br><br><b>NOTE:</b> This function is currently unsafe, do not use!" },
FindAndDoWithPlayer = { Params = "PlayerName, CallbackFunction", Return = "bool", Notes = "Calls the given callback function for the player with the name best matching the name string provided.<br>This function is case-insensitive and will match partial names.<br>Returns false if player not found or there is ambiguity, true otherwise. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cPlayer|Player}})</pre>" },
DoWithPlayerByUUID = { Params = "PlayerUUID, CallbackFunction", Return = "bool", Notes = "If there is the player with the uuid, calls the CallbackFunction with the {{cPlayer}} parameter representing the player. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cPlayer|Player}})</pre> The function returns false if the player was not found, or whatever bool value the callback returned if the player was found." },
ForEachPlayer = { Params = "CallbackFunction", Return = "", Notes = "Calls the given callback function for each player. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cPlayer|cPlayer}})</pre>" },
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index b207e79c9..d0540b4eb 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -1392,7 +1392,8 @@ bool cEntity::DetectPortal()
TargetPos.x *= 8.0;
TargetPos.z *= 8.0;
- cWorld * TargetWorld = cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetLinkedOverworldName(), dimNether, GetWorld()->GetName(), true);
+ cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedOverworldName());
+ ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start()
LOGD("Jumping nether -> overworld");
new cNetherPortalScanner(this, TargetWorld, TargetPos, 256);
return true;
@@ -1416,7 +1417,8 @@ bool cEntity::DetectPortal()
TargetPos.x /= 8.0;
TargetPos.z /= 8.0;
- cWorld * TargetWorld = cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetLinkedNetherWorldName(), dimNether, GetWorld()->GetName(), true);
+ cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedNetherWorldName());
+ ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start()
LOGD("Jumping overworld -> nether");
new cNetherPortalScanner(this, TargetWorld, TargetPos, 128);
return true;
@@ -1446,7 +1448,9 @@ bool cEntity::DetectPortal()
Player->GetClientHandle()->SendRespawn(dimOverworld);
}
- return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetLinkedOverworldName()), false);
+ cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedOverworldName());
+ ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start()
+ return MoveToWorld(TargetWorld, false);
}
else
{
@@ -1463,7 +1467,9 @@ bool cEntity::DetectPortal()
reinterpret_cast<cPlayer *>(this)->GetClientHandle()->SendRespawn(dimEnd);
}
- return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetLinkedEndWorldName(), dimEnd, GetWorld()->GetName()), false);
+ cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedEndWorldName());
+ ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start()
+ return MoveToWorld(TargetWorld, false);
}
}
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 5606e9668..b7f6f4d05 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -1871,7 +1871,7 @@ bool cPlayer::LoadFromFile(const AString & a_FileName, cWorldPtr & a_World)
cEnderChestEntity::LoadFromJson(root["enderchestinventory"], m_EnderChestContents);
m_LoadedWorldName = root.get("world", "world").asString();
- a_World = cRoot::Get()->GetWorld(GetLoadedWorldName(), false);
+ a_World = cRoot::Get()->GetWorld(GetLoadedWorldName());
if (a_World == nullptr)
{
a_World = cRoot::Get()->GetDefaultWorld();
diff --git a/src/Root.cpp b/src/Root.cpp
index 1a39b09a5..4ada5c196 100644
--- a/src/Root.cpp
+++ b/src/Root.cpp
@@ -510,29 +510,6 @@ void cRoot::LoadWorlds(cSettingsRepositoryInterface & a_Settings, bool a_IsNewIn
-cWorld * cRoot::CreateAndInitializeWorld(const AString & a_WorldName, eDimension a_Dimension, const AString & a_OverworldName, bool a_InitSpawn)
-{
- cWorld * World = m_WorldsByName[a_WorldName];
- if (World != nullptr)
- {
- return World;
- }
-
- cWorld * NewWorld = new cWorld(a_WorldName.c_str(), a_Dimension, a_OverworldName);
- m_WorldsByName[a_WorldName] = NewWorld;
- NewWorld->Start();
- if (a_InitSpawn)
- {
- NewWorld->InitializeSpawn();
- }
- m_PluginManager->CallHookWorldStarted(*NewWorld);
- return NewWorld;
-}
-
-
-
-
-
void cRoot::StartWorlds(void)
{
for (WorldMap::iterator itr = m_WorldsByName.begin(); itr != m_WorldsByName.end(); ++itr)
@@ -582,7 +559,7 @@ cWorld * cRoot::GetDefaultWorld()
-cWorld * cRoot::GetWorld(const AString & a_WorldName, bool a_SearchForFolder)
+cWorld * cRoot::GetWorld(const AString & a_WorldName)
{
WorldMap::iterator itr = m_WorldsByName.find(a_WorldName);
if (itr != m_WorldsByName.end())
@@ -590,10 +567,6 @@ cWorld * cRoot::GetWorld(const AString & a_WorldName, bool a_SearchForFolder)
return itr->second;
}
- if (a_SearchForFolder && cFile::IsFolder(FILE_IO_PREFIX + a_WorldName))
- {
- return CreateAndInitializeWorld(a_WorldName);
- }
return nullptr;
}
diff --git a/src/Root.h b/src/Root.h
index 2ce0e7c32..24c8216d9 100644
--- a/src/Root.h
+++ b/src/Root.h
@@ -64,17 +64,8 @@ public:
cServer * GetServer(void) { return m_Server; }
cWorld * GetDefaultWorld(void);
- /** Returns a pointer to the world specified
- If no world of that name was currently loaded and a_SearchForFolder was true, it will consult cFile::IsFolder() to see if a world folder of that name exists and if so, initialise a world based on that name
- */
- cWorld * GetWorld(const AString & a_WorldName, bool a_SearchForFolder = false);
-
-
- /** Returns a pointer to a world of specified name - will search loaded worlds first, then create anew if not found
- The dimension parameter is used to create a world with a specific dimension
- a_OverworldName should be set for non-overworld dimensions if one wishes that world to link back to an overworld via portals
- */
- cWorld * CreateAndInitializeWorld(const AString & a_WorldName, eDimension a_Dimension = dimOverworld, const AString & a_OverworldName = "", bool a_InitSpawn = true);
+ /** Returns a pointer to the world specified. If no world of that name exists, returns a nullptr. */
+ cWorld * GetWorld(const AString & a_WorldName);
/** Returns the up time of the server in seconds */
int GetServerUpTime(void)