Add Level::getCurrentLevelPath and Level::getCurrentLevelName

This commit is contained in:
Qiuzhizhe 2022-10-29 01:07:29 -07:00
parent 59f02218d8
commit f5888eb4da
2 changed files with 21 additions and 21 deletions

View File

@ -93,8 +93,8 @@ public:
LIAPI static void sendPacketForAllPlayers(Packet& pkt);
//LIAPI static std::string getCurrentLevelName();
//LIAPI static std::string getCurrentLevelPath();
LIAPI static std::string getCurrentLevelName();
LIAPI static std::string getCurrentLevelPath();
LIAPI static int64_t createBossEvent();
public:

View File

@ -365,26 +365,26 @@ void Level::sendPacketForAllPlayer(Packet& pkt) {
sendPacketForAllPlayers(pkt);
}
// std::string Level::getCurrentLevelName() {
// if (Global<PropertiesSettings>)
// return Global<PropertiesSettings>->getLevelName();
// std::ifstream fin("server.properties");
// string buf;
// while (getline(fin, buf)) {
// if (buf.find("level-name=") != string::npos) {
// if (buf.back() == '\n')
// buf.pop_back();
// if (buf.back() == '\r')
// buf.pop_back();
// return buf.substr(11);
// }
// }
// return "";
// }
std::string Level::getCurrentLevelName() {
if (Global<PropertiesSettings>)
return Global<PropertiesSettings>->getLevelName();
std::ifstream fin("server.properties");
string buf;
while (getline(fin, buf)) {
if (buf.find("level-name=") != string::npos) {
if (buf.back() == '\n')
buf.pop_back();
if (buf.back() == '\r')
buf.pop_back();
return buf.substr(11);
}
}
return "";
}
// std::string Level::getCurrentLevelPath() {
// return "./worlds/" + getCurrentLevelName();
// }
std::string Level::getCurrentLevelPath() {
return "./worlds/" + getCurrentLevelName();
}
int64_t BossID = 7492341231332ull;