Skip to content

Commit

Permalink
ZS: Allow turning off a player dying always resulting them in being t…
Browse files Browse the repository at this point in the history
…urned into a zombie (Thanks Venk)
  • Loading branch information
UnknownShadow200 committed Oct 20, 2022
1 parent 6a2c2ee commit 3865c7e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
3 changes: 3 additions & 0 deletions MCGalaxy/Commands/World/CmdMain.cs
Expand Up @@ -15,6 +15,8 @@
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using MCGalaxy.Games;

namespace MCGalaxy.Commands.World {
public sealed class CmdMain : Command2 {
public override string name { get { return "Main"; } }
Expand All @@ -32,6 +34,7 @@ public sealed class CmdMain : Command2 {
if (p.IsSuper) {
p.Message("Main level is {0}", Server.mainLevel.ColoredName);
} else if (p.level == Server.mainLevel) {
if (!IGame.CheckAllowed(p, "use &T/Main")) return;
PlayerActions.Respawn(p);
} else {
PlayerActions.ChangeMap(p, Server.mainLevel);
Expand Down
5 changes: 2 additions & 3 deletions MCGalaxy/Commands/World/CmdReload.cs
Expand Up @@ -33,11 +33,10 @@ public sealed class CmdReload : Command2 {

public override void Use(Player p, string message, CommandData data) {
if (CheckSuper(p, message, "level name")) return;
IGame game = IGame.GameOn(p.level);

if (message.Length == 0) {
if (game != null) {
p.Message("&WYou cannot use &T/Reload &Wwhile a game is running");
if (!IGame.CheckAllowed(p, "use &T/Reload")) {
// messaging handled in CheckAllowed
} else if (!Hacks.CanUseNoclip(p)) {
p.Message("You cannot use &T/Reload &Son this level");
} else {
Expand Down
7 changes: 1 addition & 6 deletions MCGalaxy/Commands/World/CmdSpawn.cs
Expand Up @@ -29,12 +29,7 @@ public sealed class CmdSpawn : Command2 {
p.Message("You cannot use &T/Spawn &Son this map.");
p.isFlying = false; return;
}

IGame game = IGame.GameOn(p.level);
if (!p.Game.Referee && game != null) {
p.Message("&WYou cannot use &T/Spawn &Wwhile a game is running");
return;
}
if (!IGame.CheckAllowed(p, "use &T/Spawn")) return;

if (message.Length > 0) { Help(p); return; }
PlayerActions.Respawn(p);
Expand Down
10 changes: 10 additions & 0 deletions MCGalaxy/Games/IGame.cs
Expand Up @@ -41,6 +41,16 @@ public abstract class IGame
return null;
}

public static bool CheckAllowed(Player p, string action) {
if (p.Game.Referee || GameOn(p.level) == null)
return true;

p.Message("&WYou cannot {0} &Wwhile a game is running", action);
return false;
}



/// <summary> Whether this game intercepts the given chat message </summary>
/// <example> RoundsGame uses this when voting for next level at end of rounds </example>
public virtual bool HandlesChatMessage(Player p, string message) { return false; }
Expand Down
4 changes: 3 additions & 1 deletion MCGalaxy/Games/ZombieSurvival/ZSConfig.cs
Expand Up @@ -34,7 +34,9 @@ public sealed class ZSConfig : RoundsGameConfig
public float MaxMoveDist = 1.5625f;

[ConfigString("human-tablist-group", "Human", "&fHumans")]
public string HumanTabListGroup = "&fHumans";
public string HumanTabListGroup = "&fHumans";
[ConfigBool("infect-upon-death", "Human", true)]
public bool InfectUponDeath = true;

[ConfigBool("no-pillaring-during-zombie", "Zombie", true)]
public bool NoPillaring = true;
Expand Down
12 changes: 6 additions & 6 deletions MCGalaxy/Games/ZombieSurvival/ZSGame.Plugin.cs
Expand Up @@ -24,7 +24,6 @@
using MCGalaxy.Events.LevelEvents;
using MCGalaxy.Events.PlayerEvents;
using MCGalaxy.Events.ServerEvents;
using MCGalaxy.Network;
using BlockID = System.UInt16;

namespace MCGalaxy.Games {
Expand All @@ -39,7 +38,7 @@ public sealed partial class ZSGame : RoundsGame {

OnPlayerConnectEvent.Register(HandlePlayerConnect, Priority.High);
OnPlayerMoveEvent.Register(HandlePlayerMove, Priority.High);
OnPlayerSpawningEvent.Register(HandlePlayerSpawning, Priority.High);
OnPlayerDeathEvent.Register(HandlePlayerDeath, Priority.High);
OnJoinedLevelEvent.Register(HandleJoinedLevel, Priority.High);
OnPlayerChatEvent.Register(HandlePlayerChat, Priority.High);
OnGettingCanSeeEntityEvent.Register(HandleCanSeeEntity, Priority.High);
Expand All @@ -56,7 +55,7 @@ public sealed partial class ZSGame : RoundsGame {

OnPlayerConnectEvent.Unregister(HandlePlayerConnect);
OnPlayerMoveEvent.Unregister(HandlePlayerMove);
OnPlayerSpawningEvent.Unregister(HandlePlayerSpawning);
OnPlayerDeathEvent.Unregister(HandlePlayerDeath);
OnJoinedLevelEvent.Unregister(HandleJoinedLevel);
OnPlayerChatEvent.Unregister(HandlePlayerChat);
OnGettingCanSeeEntityEvent.Unregister(HandleCanSeeEntity);
Expand Down Expand Up @@ -129,9 +128,10 @@ public sealed partial class ZSGame : RoundsGame {
bool reverted = p.Game.Noclip.Detect(next) || p.Game.Speed.Detect(next, Config.MaxMoveDist);
if (reverted) cancel = true;
}

void HandlePlayerSpawning(Player p, ref Position pos, ref byte yaw, ref byte pitch, bool respawning) {
if (p.level != Map) return;

void HandlePlayerDeath(Player p, BlockID cause) {
if (p.level != Map || p.cancelDeath || !Config.InfectUponDeath) return;

if (!p.Game.Referee && RoundInProgress && !IsInfected(p)) {
InfectPlayer(p, null);
}
Expand Down

0 comments on commit 3865c7e

Please sign in to comment.