Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Commit

Permalink
Fix setting world options
Browse files Browse the repository at this point in the history
  • Loading branch information
vexyl committed Aug 7, 2018
1 parent 816c154 commit 255e330
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion plugins/essentials/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ EssentialsPlugin = {}
EssentialsPlugin.name = "essentials" -- should match folder name!

EssentialsPlugin.init = function()
Server.AddCommand("shutdown", "", EssentialsPlugin.Server_ShutdownCommand, "shutdown [message] - shutdowns the server", 0, 0)
Server.AddCommand("shutdown", "", EssentialsPlugin.Server_ShutdownCommand, "shutdown [message] - shuts down the server", 0, 0)
Server.AddCommand("ban", "", EssentialsPlugin.Ban_BanCommand, "ban <player> [reason] - bans player from server", 1, 0)
Server.AddCommand("unban", "", EssentialsPlugin.Ban_UnbanCommand, "unban <player> - unbans player from server", 1, 0)
Server.AddCommand("banip", "", EssentialsPlugin.Ban_BanIpCommand, "banip <ip address> [reason] - bans ip from server", 1, 0)
Expand Down
9 changes: 6 additions & 3 deletions plugins/essentials/world.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Command_Set = function(client, args)

if (#args == 1) then
local value = world:GetOption(option)
if (value ~= nil) then
if (value ~= "") then
Server.SendMessage(client, "&e" .. option .. "=" .. value)
else
Server.SendMessage(client, "&cInvalid option")
Expand All @@ -97,8 +97,11 @@ Command_Set = function(client, args)
return
end

world:SetOption(option, value)
Server.SendMessage(client, "&eSet option " .. option .. " to " .. value)
if (world:SetOption(option, value)) then
Server.SendMessage(client, "&eSet option " .. option .. " to " .. value)
else
Server.SendMessage(client, "&cInvalid option")
end
end,

Command_Save = function(client, args)
Expand Down
22 changes: 10 additions & 12 deletions src/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// m_mapChanged set to true so when the .ini first saves the map file gets saved too
World::World(std::string name) : m_name(name), m_active(false), m_mapChanged(true)
{
SetOption("build", "true");
SetOption("autosave", "false");
SetOption("autoload", "false");
SetOption("build", "true", true);
SetOption("autosave", "false", true);
SetOption("autoload", "false", true);
}

World::World() : World("")
Expand Down Expand Up @@ -164,9 +164,12 @@ void World::SetSpawnPosition(Position spawnPosition)
m_spawnPosition = spawnPosition;
}

void World::SetOption(std::string option, std::string value)
bool World::SetOption(std::string option, std::string value, bool createNewOption)
{
if (!IsValidOption(option) && !createNewOption)
return false;
m_options[option] = value;
return true;
}

std::vector<std::string> World::GetOptionNames()
Expand All @@ -181,19 +184,14 @@ std::vector<std::string> World::GetOptionNames()

std::string World::GetOption(std::string option)
{
if (!IsValidOption(option))
return "";
return m_options[option];
}

bool World::IsValidOption(std::string option)
{
bool result = false;

for (auto& obj : m_options) {
if (option == obj.first)
result = true;
}

return result;
return m_options.find(option) != m_options.end();
}

void World::Tick()
Expand Down
2 changes: 1 addition & 1 deletion src/World.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class World {

void SetActive(bool active);
void SetSpawnPosition(Position spawnPosition);
void SetOption(std::string option, std::string value);
bool SetOption(std::string option, std::string value, bool createNewOption=false);
bool IsValidOption(std::string option);

std::vector<std::string> GetOptionNames();
Expand Down

0 comments on commit 255e330

Please sign in to comment.