summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-08-19 22:48:13 +0200
committermadmaxoft <github@xoft.cz>2013-08-19 22:48:13 +0200
commit97aff179c1e436ccb369ee2a08f25d9250ef637f (patch)
treeba4f91544aa2b0f31382dbcdbda40c903f1d3bf5
parentDeadlockDetect now uses sleep instead of timed-wait semaphores. (diff)
downloadcuberite-97aff179c1e436ccb369ee2a08f25d9250ef637f.tar
cuberite-97aff179c1e436ccb369ee2a08f25d9250ef637f.tar.gz
cuberite-97aff179c1e436ccb369ee2a08f25d9250ef637f.tar.bz2
cuberite-97aff179c1e436ccb369ee2a08f25d9250ef637f.tar.lz
cuberite-97aff179c1e436ccb369ee2a08f25d9250ef637f.tar.xz
cuberite-97aff179c1e436ccb369ee2a08f25d9250ef637f.tar.zst
cuberite-97aff179c1e436ccb369ee2a08f25d9250ef637f.zip
-rw-r--r--MCServer/Plugins/Debuggers/Debuggers.lua69
-rw-r--r--source/DeadlockDetect.cpp2
-rw-r--r--source/Entities/Player.cpp4
-rw-r--r--source/Entities/Player.h7
4 files changed, 57 insertions, 25 deletions
diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua
index d74b4ea69..90a897aa6 100644
--- a/MCServer/Plugins/Debuggers/Debuggers.lua
+++ b/MCServer/Plugins/Debuggers/Debuggers.lua
@@ -3,6 +3,7 @@ PLUGIN = {}; -- Reference to own plugin object
g_DropSpensersToActivate = {}; -- A list of dispensers and droppers (as {World, X, Y Z} quadruplets) that are to be activated every tick
g_HungerReportTick = 10;
+g_ShowFoodStats = false; -- When true, each player's food stats are sent to them every 10 ticks
@@ -22,6 +23,7 @@ function Initialize(Plugin)
PluginManager:AddHook(Plugin, cPluginManager.HOOK_TICK);
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHAT);
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_RIGHT_CLICKING_ENTITY);
+ PluginManager:AddHook(Plugin, cPluginManager.HOOK_WORLD_TICK);
PluginManager:BindCommand("/le", "debuggers", HandleListEntitiesCmd, "- Shows a list of all the loaded entities");
PluginManager:BindCommand("/ke", "debuggers", HandleKillEntitiesCmd, "- Kills all the loaded entities");
@@ -36,6 +38,7 @@ function Initialize(Plugin)
PluginManager:BindCommand("/fl", "debuggers", HandleFoodLevelCmd, "- Sets the food level to the given value");
PluginManager:BindCommand("/spidey", "debuggers", HandleSpideyCmd, "- Shoots a line of web blocks until it hits non-air");
PluginManager:BindCommand("/ench", "debuggers", HandleEnchCmd, "- Provides an instant dummy enchantment window");
+ PluginManager:BindCommand("/fs", "debuggers", HandleFoodStatsCmd, "- Turns regular foodstats message on or off");
-- Enable the following line for BlockArea / Generator interface testing:
-- PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_GENERATED);
@@ -444,19 +447,6 @@ function OnTick()
GCOnTick = GCOnTick - 1;
end
- --[[
- if (g_HungerReportTick > 0) then
- g_HungerReportTick = g_HungerReportTick - 1;
- else
- g_HungerReportTick = 10;
- cRoot:Get():GetDefaultWorld():ForEachPlayer(
- function(a_Player)
- a_Player:SendMessage("FoodStat: " .. a_Player:GetFoodLevel() .. " / " .. a_Player:GetFoodExhaustionLevel());
- end
- );
- end
- ]]
-
return false;
end
@@ -464,6 +454,27 @@ end
+function OnWorldTick(a_World, a_Dt)
+ local Tick = a_World:GetWorldAge();
+ if (not(g_ShowFoodStats) or (math.mod(Tick, 10) ~= 0)) then
+ return false;
+ end
+ a_World:ForEachPlayer(
+ function(a_Player)
+ a_Player:SendMessage(
+ tostring(Tick / 10) ..
+ " > FS: fl " .. a_Player:GetFoodLevel() ..
+ "; sat " .. a_Player:GetFoodSaturationLevel() ..
+ "; exh " .. a_Player:GetFoodExhaustionLevel()
+ );
+ end
+ );
+end
+
+
+
+
+
function OnChunkGenerated(World, ChunkX, ChunkZ, ChunkDesc)
-- Test ChunkDesc / BlockArea interaction
local BlockArea = cBlockArea();
@@ -708,7 +719,13 @@ function HandleFoodLevelCmd(a_Split, a_Player)
end
a_Player:SetFoodLevel(tonumber(a_Split[2]));
- a_Player:SendMessage("Food level set to " .. a_Player:GetFoodLevel());
+ a_Player:SetFoodSaturationLevel(5);
+ a_Player:SetFoodExhaustionLevel(0);
+ a_Player:SendMessage(
+ "Food level set to " .. a_Player:GetFoodLevel() ..
+ ", saturation reset to " .. a_Player:GetFoodSaturationLevel() ..
+ " and exhaustion reset to " .. a_Player:GetFoodExhaustionLevel()
+ );
return true;
end
@@ -748,9 +765,21 @@ end
function HandleEnchCmd(a_Split, a_Player)
- local Wnd = cLuaWindow(cWindow.Enchantment, 1, 1, "Ench")
- a_Player:OpenWindow(Wnd)
- Wnd:SetProperty(0, 10)
- Wnd:SetProperty(1, 15)
- Wnd:SetProperty(2, 25)
-end \ No newline at end of file
+ local Wnd = cLuaWindow(cWindow.Enchantment, 1, 1, "Ench");
+ a_Player:OpenWindow(Wnd);
+ Wnd:SetProperty(0, 10);
+ Wnd:SetProperty(1, 15);
+ Wnd:SetProperty(2, 25);
+end
+
+
+
+
+
+function HandleFoodStatsCmd(a_Split, a_Player)
+ g_ShowFoodStats = not(g_ShowFoodStats);
+end
+
+
+
+
diff --git a/source/DeadlockDetect.cpp b/source/DeadlockDetect.cpp
index de9a32d39..5af3f973d 100644
--- a/source/DeadlockDetect.cpp
+++ b/source/DeadlockDetect.cpp
@@ -62,7 +62,7 @@ bool cDeadlockDetect::Start(void)
void cDeadlockDetect::Execute(void)
{
- // Loop until the event is signalled
+ // Loop until the signal to terminate:
while (!m_ShouldTerminate)
{
// Check the world ages:
diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp
index 8ad071453..3ccb4ca1d 100644
--- a/source/Entities/Player.cpp
+++ b/source/Entities/Player.cpp
@@ -340,9 +340,9 @@ void cPlayer::SetFoodTickTimer(int a_FoodTickTimer)
-void cPlayer::SetFoodExhaustionLevel(double a_FoodSaturationLevel)
+void cPlayer::SetFoodExhaustionLevel(double a_FoodExhaustionLevel)
{
- m_FoodExhaustionLevel = std::max(0.0, std::min(a_FoodSaturationLevel, 4.0));
+ m_FoodExhaustionLevel = std::max(0.0, std::min(a_FoodExhaustionLevel, 4.0));
}
diff --git a/source/Entities/Player.h b/source/Entities/Player.h
index 62595f980..5dcce8421 100644
--- a/source/Entities/Player.h
+++ b/source/Entities/Player.h
@@ -171,14 +171,17 @@ public:
void SetFoodLevel (int a_FoodLevel);
void SetFoodSaturationLevel (double a_FoodSaturationLevel);
void SetFoodTickTimer (int a_FoodTickTimer);
- void SetFoodExhaustionLevel (double a_FoodSaturationLevel);
+ void SetFoodExhaustionLevel (double a_FoodExhaustionLevel);
void SetFoodPoisonedTicksRemaining(int a_FoodPoisonedTicksRemaining);
/// Adds to FoodLevel and FoodSaturationLevel, returns true if any food has been consumed, false if player "full"
bool Feed(int a_Food, double a_Saturation);
/// Adds the specified exhaustion to m_FoodExhaustion. Expects only positive values.
- void AddFoodExhaustion(double a_Exhaustion) { m_FoodExhaustionLevel += a_Exhaustion; }
+ void AddFoodExhaustion(double a_Exhaustion)
+ {
+ m_FoodExhaustionLevel += a_Exhaustion;
+ }
/// Starts the food poisoning for the specified amount of ticks; if already foodpoisoned, sets FoodPoisonedTicksRemaining to the larger of the two
void FoodPoison(int a_NumTicks);