diff --git a/MCGalaxy/Commands/Fun/CmdCountdown.cs b/MCGalaxy/Commands/Fun/CmdCountdown.cs index aa269c1b5..e991048ec 100644 --- a/MCGalaxy/Commands/Fun/CmdCountdown.cs +++ b/MCGalaxy/Commands/Fun/CmdCountdown.cs @@ -81,7 +81,7 @@ namespace MCGalaxy.Commands.Fun { } void HandleJoin(Player p) { - switch (Server.Countdown.gamestatus) { + switch (Server.Countdown.Status) { case CountdownGameStatus.Disabled: Player.Message(p, "Sorry - Countdown isn't enabled yet"); return; @@ -102,7 +102,7 @@ namespace MCGalaxy.Commands.Fun { void HandleLeave(Player p) { if (Server.Countdown.players.Contains(p)) { - switch (Server.Countdown.gamestatus) { + switch (Server.Countdown.Status) { case CountdownGameStatus.Disabled: Player.Message(p, "Sorry - Countdown isn't enabled yet"); return; @@ -132,7 +132,7 @@ namespace MCGalaxy.Commands.Fun { } void HandlePlayers(Player p) { - switch (Server.Countdown.gamestatus) { + switch (Server.Countdown.Status) { case CountdownGameStatus.Disabled: Player.Message(p, "The game has not been enabled yet."); break; @@ -207,7 +207,7 @@ namespace MCGalaxy.Commands.Fun { else LevelInfo.Loaded.Add(lvl); lvl.Save(); - if (Server.Countdown.gamestatus != CountdownGameStatus.Disabled) + if (Server.Countdown.Status != CountdownGameStatus.Disabled) Server.Countdown.mapon = lvl; const string format = "Generated map ({0}x{1}x{2}), sending you to it.."; @@ -221,7 +221,7 @@ namespace MCGalaxy.Commands.Fun { void HandleEnable(Player p) { if (!CheckExtraPerm(p, 2)) { MessageNeedExtra(p, 2); return; } - if (Server.Countdown.gamestatus == CountdownGameStatus.Disabled) { + if (Server.Countdown.Status == CountdownGameStatus.Disabled) { CmdLoad.LoadLevel(null, "countdown"); Server.Countdown.mapon = LevelInfo.FindExact("countdown"); @@ -236,7 +236,7 @@ namespace MCGalaxy.Commands.Fun { Server.Countdown.mapon.BuildAccess.Min = LevelPermission.Nobody; Server.Countdown.mapon.Config.MOTD = "Welcome to the Countdown map! -hax"; - Server.Countdown.gamestatus = CountdownGameStatus.Enabled; + Server.Countdown.Status = CountdownGameStatus.Enabled; Chat.MessageGlobal("Countdown has been enabled!!"); } else { Player.Message(p, "A Game is either already enabled or is already progress"); @@ -246,15 +246,15 @@ namespace MCGalaxy.Commands.Fun { void HandleDisable(Player p) { if (!CheckExtraPerm(p, 2)) { MessageNeedExtra(p, 2); return; } - if (Server.Countdown.gamestatus == CountdownGameStatus.AboutToStart || Server.Countdown.gamestatus == CountdownGameStatus.InProgress) { + if (Server.Countdown.Status == CountdownGameStatus.AboutToStart || Server.Countdown.Status == CountdownGameStatus.InProgress) { Player.Message(p, "A game is currently in progress - please wait until it is finished, or use '/cd cancel' to cancel the game"); return; - } else if (Server.Countdown.gamestatus == CountdownGameStatus.Disabled) { + } else if (Server.Countdown.Status == CountdownGameStatus.Disabled) { Player.Message(p, "Already disabled!!"); return; } else { foreach (Player pl in Server.Countdown.players) Player.Message(pl, "The countdown game was disabled."); Server.Countdown.Reset(p, true); - Server.Countdown.gamestatus = CountdownGameStatus.Disabled; + Server.Countdown.Status = CountdownGameStatus.Disabled; Player.Message(p, "Countdown Disabled"); } } @@ -262,12 +262,12 @@ namespace MCGalaxy.Commands.Fun { void HandleCancel(Player p) { if (!CheckExtraPerm(p, 2)) { MessageNeedExtra(p, 2); return; } - if (Server.Countdown.gamestatus == CountdownGameStatus.AboutToStart || Server.Countdown.gamestatus == CountdownGameStatus.InProgress) { + if (Server.Countdown.Status == CountdownGameStatus.AboutToStart || Server.Countdown.Status == CountdownGameStatus.InProgress) { Server.Countdown.cancel = true; Thread.Sleep(1500); Player.Message(p, "Countdown has been canceled"); - Server.Countdown.gamestatus = CountdownGameStatus.Enabled; - } else if (Server.Countdown.gamestatus == CountdownGameStatus.Disabled) { + Server.Countdown.Status = CountdownGameStatus.Enabled; + } else if (Server.Countdown.Status == CountdownGameStatus.Disabled) { Player.Message(p, "The game is disabled!!"); } else { foreach (Player pl in Server.Countdown.players) @@ -279,7 +279,7 @@ namespace MCGalaxy.Commands.Fun { void HandleStart(Player p, string par1, string par2) { if (!CheckExtraPerm(p, 2)) { MessageNeedExtra(p, 2); return; } - if (Server.Countdown.gamestatus != CountdownGameStatus.Enabled) { + if (Server.Countdown.Status != CountdownGameStatus.Enabled) { Player.Message(p, "Either a game is already in progress or it hasn't been enabled"); return; } if (Server.Countdown.players.Count < 2) { @@ -310,7 +310,7 @@ namespace MCGalaxy.Commands.Fun { void HandleReset(Player p, string par1) { if (!CheckExtraPerm(p, 2)) { MessageNeedExtra(p, 2); return; } - switch (Server.Countdown.gamestatus) { + switch (Server.Countdown.Status) { case CountdownGameStatus.Disabled: Player.Message(p, "Please enable countdown first."); break; case CountdownGameStatus.AboutToStart: diff --git a/MCGalaxy/Games/Countdown/CountdownGame.Game.cs b/MCGalaxy/Games/Countdown/CountdownGame.Game.cs deleted file mode 100644 index 189fd137a..000000000 --- a/MCGalaxy/Games/Countdown/CountdownGame.Game.cs +++ /dev/null @@ -1,77 +0,0 @@ -/* - Copyright 2011 MCForge - - Dual-licensed under the Educational Community License, Version 2.0 and - the GNU General Public License, Version 3 (the "Licenses"); you may - not use this file except in compliance with the Licenses. You may - obtain a copy of the Licenses at - - http://www.opensource.org/licenses/ecl2.php - http://www.gnu.org/licenses/gpl-3.0.html - - Unless required by applicable law or agreed to in writing, - software distributed under the Licenses are distributed on an "AS IS" - BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - or implied. See the Licenses for the specific language governing - permissions and limitations under the Licenses. - */ -using System; -using System.Collections.Generic; -using System.Threading; - -namespace MCGalaxy.Games { - public sealed partial class CountdownGame : IGame { - - public override void PlayerJoinedGame(Player p) { - if (!Server.Countdown.players.Contains(p)) { - Server.Countdown.players.Add(p); - Player.Message(p, "You've joined the Countdown game!!"); - Chat.MessageGlobal("{0} has joined Countdown!!", p.name); - if (p.level != Server.Countdown.mapon) - PlayerActions.ChangeMap(p, "countdown"); - p.playerofcountdown = true; - } else { - Player.Message(p, "Sorry, you have already joined!!, to leave please type /countdown leave"); - } - } - - public override void PlayerLeftServer(Player p) { - if (players.Contains(p)) { - if (playersleftlist.Contains(p)) { - mapon.ChatLevel(p.ColoredName + " %Slogged out and so is out of countdown!!"); - PlayerLeftGame(p); - } - players.Remove(p); - } - } - - public override void PlayerLeftGame(Player p) { - p.incountdown = false; - p.playerofcountdown = false; - players.Remove(p); - playersleftlist.Remove(p); - MessagePlayersLeft(); - } - - public override bool HandlesMovement(Player p, Position next, byte yaw, byte pitch) { - if( !p.incountdown || gamestatus != CountdownGameStatus.InProgress || !freezemode) - return false; - if (p.countdownsettemps) { - p.countdowntempx = next.X; - Thread.Sleep(100); - p.countdowntempz = next.Z; - Thread.Sleep(100); - p.countdownsettemps = false; - } - - if (next.X != p.countdowntempx || next.Z != p.countdowntempz) { - next.X = p.countdowntempx; next.Z = p.countdowntempz; - p.SendPos(Entities.SelfID, next, new Orientation(yaw, pitch)); - } - - p.Pos = next; - p.SetYawPitch(yaw, pitch); - return true; - } - } -} diff --git a/MCGalaxy/Games/Countdown/CountdownGame.cs b/MCGalaxy/Games/Countdown/CountdownGame.cs index d0f7714ca..81fea1f5a 100644 --- a/MCGalaxy/Games/Countdown/CountdownGame.cs +++ b/MCGalaxy/Games/Countdown/CountdownGame.cs @@ -19,8 +19,8 @@ using System; using System.Collections.Generic; using System.Threading; -namespace MCGalaxy.Games { - public sealed partial class CountdownGame { +namespace MCGalaxy.Games { + public sealed class CountdownGame : IGame { public List players = new List(); public List playersleftlist = new List(); @@ -33,10 +33,17 @@ namespace MCGalaxy.Games { public string speedtype; - public CountdownGameStatus gamestatus = CountdownGameStatus.Disabled; + public CountdownGameStatus Status = CountdownGameStatus.Disabled; + CountdownPlugin plugin; public void GameStart(Player p) { - switch (gamestatus) { + if (plugin == null) { + plugin = new CountdownPlugin(); + plugin.Game = this; + plugin.Load(false); + } + + switch (Status) { case CountdownGameStatus.Disabled: Player.Message(p, "Please enable Countdown first!!"); return; case CountdownGameStatus.AboutToStart: @@ -46,7 +53,7 @@ namespace MCGalaxy.Games { case CountdownGameStatus.Finished: Player.Message(p, "Game has finished"); return; case CountdownGameStatus.Enabled: - gamestatus = CountdownGameStatus.AboutToStart; + Status = CountdownGameStatus.AboutToStart; Thread.Sleep(2000); break; } @@ -83,7 +90,7 @@ namespace MCGalaxy.Games { playersleftlist = players; foreach (Player pl in players) - pl.incountdown = true; + pl.InCountdown = true; AfterStart(); Play(); } @@ -94,9 +101,9 @@ namespace MCGalaxy.Games { } else { SendFreezeMessages(); MessageAll("&bPlayers Frozen"); - gamestatus = CountdownGameStatus.InProgress; + Status = CountdownGameStatus.InProgress; foreach (Player pl in players) - pl.countdownsettemps = true; + pl.CountdownSetFreezePos = true; Thread.Sleep(500); RemoveGlassBlocks(); @@ -157,7 +164,7 @@ namespace MCGalaxy.Games { void RemoveRandomSquares() { while (squaresLeft.Count > 0 && playersleftlist.Count != 0 - && (gamestatus == CountdownGameStatus.InProgress || gamestatus == CountdownGameStatus.Finished)) + && (Status == CountdownGameStatus.InProgress || Status == CountdownGameStatus.Finished)) { Random number = new Random(); int index = number.Next(squaresLeft.Count); @@ -165,7 +172,7 @@ namespace MCGalaxy.Games { squaresLeft.RemoveAt(index); RemoveSquare(nextsquare); - if (squaresLeft.Count % 10 == 0 && gamestatus != CountdownGameStatus.Finished) + if (squaresLeft.Count % 10 == 0 && Status != CountdownGameStatus.Finished) mapon.ChatLevel(squaresLeft.Count + " Squares Left and " + playersleftlist.Count + " Players left!!"); if (cancel) End(null); @@ -239,18 +246,18 @@ namespace MCGalaxy.Games { Cuboid(maxX - 4, 4, 4, maxX - 4, 4, maxZ - 4, Block.air, mapon); if (!freezemode) { - gamestatus = CountdownGameStatus.InProgress; + Status = CountdownGameStatus.InProgress; } } public void Death(Player p) { mapon.ChatLevel(p.ColoredName + " %Sis out of countdown!!"); - p.incountdown = false; + p.InCountdown = false; playersleftlist.Remove(p); MessagePlayersLeft(); } - void MessagePlayersLeft() { + public void MessagePlayersLeft() { switch (playersleftlist.Count) { case 1: mapon.ChatLevel(playersleftlist[0].ColoredName + " %Sis the winner!!"); @@ -275,20 +282,20 @@ namespace MCGalaxy.Games { void End(Player winner) { squaresLeft.Clear(); - gamestatus = CountdownGameStatus.Finished; + Status = CountdownGameStatus.Finished; playersleftlist.Clear(); if (winner != null) { winner.SendMessage("Congratulations!! You won!!!"); Command.all.Find("spawn").Use(winner, ""); - winner.incountdown = false; + winner.InCountdown = false; } else { foreach (Player pl in players) { Player.Message(pl, "The countdown game was canceled!"); Command.all.Find("spawn").Use(pl, ""); } Chat.MessageGlobal("The countdown game was canceled!!"); - gamestatus = CountdownGameStatus.Enabled; + Status = CountdownGameStatus.Enabled; playersleftlist.Clear(); players.Clear(); squaresLeft.Clear(); @@ -298,8 +305,8 @@ namespace MCGalaxy.Games { } public void Reset(Player p, bool all) { - if (!(gamestatus == CountdownGameStatus.Enabled || gamestatus == CountdownGameStatus.Finished || gamestatus == CountdownGameStatus.Disabled)) { - switch (gamestatus) { + if (!(Status == CountdownGameStatus.Enabled || Status == CountdownGameStatus.Finished || Status == CountdownGameStatus.Disabled)) { + switch (Status) { case CountdownGameStatus.Disabled: Player.Message(p, "Please enable the game first"); return; default: @@ -316,9 +323,9 @@ namespace MCGalaxy.Games { if (!all) { Player.Message(p, "The Countdown map has been reset"); - if (gamestatus == CountdownGameStatus.Finished) + if (Status == CountdownGameStatus.Finished) Player.Message(p, "You do not need to re-enable it"); - gamestatus = CountdownGameStatus.Enabled; + Status = CountdownGameStatus.Enabled; Player[] online = PlayerInfo.Online.Items; foreach (Player pl in online) { @@ -334,9 +341,9 @@ namespace MCGalaxy.Games { } } else { Player.Message(p, "Countdown has been reset"); - if (gamestatus == CountdownGameStatus.Finished) + if (Status == CountdownGameStatus.Finished) Player.Message(p, "You do not need to re-enable it"); - gamestatus = CountdownGameStatus.Enabled; + Status = CountdownGameStatus.Enabled; playersleftlist.Clear(); players.Clear(); squaresLeft.Clear(); @@ -345,7 +352,7 @@ namespace MCGalaxy.Games { Player[] online = PlayerInfo.Online.Items; foreach (Player pl in online) { pl.playerofcountdown = false; - pl.incountdown = false; + pl.InCountdown = false; } } } @@ -383,6 +390,28 @@ namespace MCGalaxy.Games { public SquarePos(int x, int z) { X = (ushort)x; Z = (ushort)z; } + } + + + public override void PlayerJoinedGame(Player p) { + if (!Server.Countdown.players.Contains(p)) { + Server.Countdown.players.Add(p); + Player.Message(p, "You've joined the Countdown game!!"); + Chat.MessageGlobal("{0} has joined Countdown!!", p.name); + if (p.level != Server.Countdown.mapon) + PlayerActions.ChangeMap(p, "countdown"); + p.playerofcountdown = true; + } else { + Player.Message(p, "Sorry, you have already joined!!, to leave please type /countdown leave"); + } + } + + public override void PlayerLeftGame(Player p) { + p.InCountdown = false; + p.playerofcountdown = false; + players.Remove(p); + playersleftlist.Remove(p); + MessagePlayersLeft(); } } diff --git a/MCGalaxy/Games/Countdown/CountdownPlugin.cs b/MCGalaxy/Games/Countdown/CountdownPlugin.cs new file mode 100644 index 000000000..119dfda12 --- /dev/null +++ b/MCGalaxy/Games/Countdown/CountdownPlugin.cs @@ -0,0 +1,72 @@ +/* + Copyright 2011 MCForge + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ +using System; +using System.Threading; +using MCGalaxy.Events; + +namespace MCGalaxy.Games { + public sealed class CountdownPlugin : Plugin_Simple { + public override string creator { get { return Server.SoftwareName + " team"; } } + public override string MCGalaxy_Version { get { return Server.VersionString; } } + public override string name { get { return "Core_CountdownPlugin"; } } + public CountdownGame Game; + + public override void Load(bool startup) { + OnPlayerMoveEvent.Register(HandlePlayerMove, Priority.High, this); + OnPlayerDisconnectEvent.Register(HandlePlayerDisconnect, Priority.High, this); + } + + public override void Unload(bool shutdown) { + OnPlayerMoveEvent.UnRegister(this); + OnPlayerDisconnectEvent.UnRegister(this); + } + + + void HandlePlayerMove(Player p, Position next, byte yaw, byte pitch) { + if (!p.InCountdown || Game.Status != CountdownGameStatus.InProgress || !Game.freezemode) + return; + + if (p.CountdownSetFreezePos) { + p.CountdownFreezeX = next.X; + Thread.Sleep(100); + p.CountdownFreezeZ = next.Z; + Thread.Sleep(100); + p.CountdownSetFreezePos = false; + } + + if (next.X != p.CountdownFreezeX || next.Z != p.CountdownFreezeZ) { + next.X = p.CountdownFreezeX; next.Z = p.CountdownFreezeZ; + p.SendPos(Entities.SelfID, next, new Orientation(yaw, pitch)); + } + + p.Pos = next; + p.SetYawPitch(yaw, pitch); + Plugin.CancelPlayerEvent(PlayerEvents.PlayerMove, p); + } + + void HandlePlayerDisconnect(Player p, string reason) { + if (!Game.players.Contains(p)) return; + + if (Game.playersleftlist.Contains(p)) { + Game.mapon.ChatLevel(p.ColoredName + " %Slogged out and so is out of countdown"); + Game.PlayerLeftGame(p); + } + Game.players.Remove(p); + } + } +} diff --git a/MCGalaxy/MCGalaxy_.csproj b/MCGalaxy/MCGalaxy_.csproj index 20e8d6016..c979f49f6 100644 --- a/MCGalaxy/MCGalaxy_.csproj +++ b/MCGalaxy/MCGalaxy_.csproj @@ -483,8 +483,8 @@ - + diff --git a/MCGalaxy/Player/Player.Fields.cs b/MCGalaxy/Player/Player.Fields.cs index 85e56603d..1a617bfaa 100644 --- a/MCGalaxy/Player/Player.Fields.cs +++ b/MCGalaxy/Player/Player.Fields.cs @@ -170,10 +170,10 @@ namespace MCGalaxy { //Countdown public bool playerofcountdown = false; - public bool incountdown = false; - public int countdowntempx; - public int countdowntempz; - public bool countdownsettemps = false; + public bool InCountdown = false; + public int CountdownFreezeX; + public int CountdownFreezeZ; + public bool CountdownSetFreezePos = false; //Tnt Wars public bool PlayingTntWars = false; diff --git a/MCGalaxy/Player/Player.Handlers.cs b/MCGalaxy/Player/Player.Handlers.cs index 1c68d568e..a361e2b49 100644 --- a/MCGalaxy/Player/Player.Handlers.cs +++ b/MCGalaxy/Player/Player.Handlers.cs @@ -325,8 +325,6 @@ namespace MCGalaxy { Position next = new Position(x, y, z); CheckBlocks(next); - if (Server.Countdown.HandlesMovement(this, next, yaw, pitch)) - return; if (Server.zombie.Running && Server.zombie.HandlesMovement(this, next, yaw, pitch)) return;