diff --git a/MCGalaxy/Commands/Moderation/CmdAllowGuns.cs b/MCGalaxy/Commands/Moderation/CmdAllowGuns.cs deleted file mode 100644 index b38304c52..000000000 --- a/MCGalaxy/Commands/Moderation/CmdAllowGuns.cs +++ /dev/null @@ -1,57 +0,0 @@ -/* - Written by Jack1312 - 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.IO; -namespace MCGalaxy.Commands { - public sealed class CmdAllowGuns : Command { - public override string name { get { return "allowguns"; } } - public override string shortcut { get { return "ag"; } } - public override string type { get { return CommandTypes.Moderation; } } - public override bool museumUsable { get { return true; } } - public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } - public CmdAllowGuns() { } - - public override void Use(Player p, string message) { - if (CheckSuper(p, message, "level name")) return; - Level lvl = p.level; - if (message != "") { - lvl = LevelInfo.FindMatches(p, message); - if (lvl == null) return; - } - - if (lvl.guns) { - Chat.MessageAll("&9Gun usage has been disabled on &c{0}&9!", lvl.name); - Player[] players = PlayerInfo.Online.Items; - foreach (Player pl in players) - if (pl.level.name.CaselessEq(lvl.name)) - pl.aiming = false; - } else { - Chat.MessageAll("&9Gun usage has been enabled on &c{0}&9!", lvl.name); - } - lvl.guns = !lvl.guns; - Level.SaveSettings(lvl); - } - - public override void Help(Player p) { - Player.Message(p, "%T/allowguns [level]"); - Player.Message(p, "%HAllows/disallows guns and missiles on the specified level."); - Player.Message(p, "%HIf no [level] is given, uses your current level."); - } - } -} \ No newline at end of file diff --git a/MCGalaxy/Commands/World/CmdMap.cs b/MCGalaxy/Commands/World/CmdMap.cs index 4c84aa65f..b6244ab9c 100644 --- a/MCGalaxy/Commands/World/CmdMap.cs +++ b/MCGalaxy/Commands/World/CmdMap.cs @@ -29,7 +29,8 @@ namespace MCGalaxy.Commands.World { new CommandPerm(LevelPermission.Admin, "+ can set realm owners") }; } } public override CommandAlias[] Aliases { - get { return new[] { new CommandAlias("ps", "physicspeed") }; } + get { return new[] { new CommandAlias("ps", "physicspeed"), + new CommandAlias("allowguns", null, "guns") }; } } public override void Use(Player p, string message) { diff --git a/MCGalaxy/Levels/LevelOptions.cs b/MCGalaxy/Levels/LevelOptions.cs index 78e098527..a3bd4a7ce 100644 --- a/MCGalaxy/Levels/LevelOptions.cs +++ b/MCGalaxy/Levels/LevelOptions.cs @@ -31,20 +31,21 @@ namespace MCGalaxy { { "Overload", (p, l, value) => SetPhysicsOverload(p, l, value, "Physics overload") }, { "Fall", (p, l, value) => SetInt(p, l, ref l.fall, value, "Fall distance") }, { "Drown", (p, l, value) => SetInt(p, l, ref l.drown, value, "Drown time (in tenths of a second)") }, - { "Finite", (p, l, value) => Set(p, l, ref l.finite, "Finite mode") }, - { "AI", (p, l, value) => Set(p, l, ref l.ai, "Animal AI") }, - { "Edge", (p, l, value) => Set(p, l, ref l.edgeWater, "Edge water") }, - { "Grass", (p, l, value) => Set(p, l, ref l.GrassGrow, "Growing grass") }, - { "Death", (p, l, value) => Set(p, l, ref l.Death, "Survival death") }, - { "Killer", (p, l, value) => Set(p, l, ref l.Killer, "Killer blocks") }, - { "Unload", (p, l, value) => Set(p, l, ref l.unload, "Auto unload") }, - { "LoadOnGoto", (p, l, value) => Set(p, l, ref l.loadOnGoto, "Load on goto") }, - { "LeafDecay", (p, l, value) => Set(p, l, ref l.leafDecay, "Leaf decay") }, - { "RandomFlow", (p, l, value) => Set(p, l, ref l.randomFlow, "Random flow") }, - { "GrowTrees", (p, l, value) => Set(p, l, ref l.growTrees, "Tree growing") }, - { "Chat", (p, l, value) => Set(p, l, ref l.worldChat, "Roleplay (level only) chat: ", true) }, - { "Buildable", (p, l, value) => SetPerms(p, l, ref l.Buildable, "Buildable") }, - { "Deletable", (p, l, value) => SetPerms(p, l, ref l.Deletable, "Deletable") }, + { "Finite", (p, l, value) => Toggle(p, l, ref l.finite, "Finite mode") }, + { "AI", (p, l, value) => Toggle(p, l, ref l.ai, "Animal AI") }, + { "Edge", (p, l, value) => Toggle(p, l, ref l.edgeWater, "Edge water") }, + { "Grass", (p, l, value) => Toggle(p, l, ref l.GrassGrow, "Growing grass") }, + { "Death", (p, l, value) => Toggle(p, l, ref l.Death, "Survival death") }, + { "Killer", (p, l, value) => Toggle(p, l, ref l.Killer, "Killer blocks") }, + { "Unload", (p, l, value) => Toggle(p, l, ref l.unload, "Auto unload") }, + { "LoadOnGoto", (p, l, value) => Toggle(p, l, ref l.loadOnGoto, "Load on goto") }, + { "LeafDecay", (p, l, value) => Toggle(p, l, ref l.leafDecay, "Leaf decay") }, + { "RandomFlow", (p, l, value) => Toggle(p, l, ref l.randomFlow, "Random flow") }, + { "GrowTrees", (p, l, value) => Toggle(p, l, ref l.growTrees, "Tree growing") }, + { "Chat", (p, l, value) => Toggle(p, l, ref l.worldChat, "Roleplay (level only) chat: ", true) }, + { "Guns", ToggleGuns }, + { "Buildable", (p, l, value) => TogglePerms(p, l, ref l.Buildable, "Buildable") }, + { "Deletable", (p, l, value) => TogglePerms(p, l, ref l.Deletable, "Deletable") }, }; public static Dictionary Help = new Dictionary() { @@ -66,6 +67,7 @@ namespace MCGalaxy { { "RandomFlow", "%HWhether flooding liquids flow less uniformly." }, { "GrowTrees", "%HWhether saplings grow into trees after a while." }, { "Chat", "%HWhether chat is only seen from and sent to players in the map." }, + { "Guns", "%HWhether guns and missiles can be used" }, { "Buildable", "%HWhether any blocks can be placed by players." }, { "Deletable", "%HWhether any blocks can be deleted by players." }, }; @@ -81,6 +83,24 @@ namespace MCGalaxy { } static string GetBool(bool value) { return value ? "&aON" : "&cOFF"; } + + static void SetMotd(Player p, Level lvl, string value) { + lvl.motd = value == "" ? "ignore" : value; + lvl.ChatLevel("Map's MOTD was changed to: &b" + lvl.motd); + + Player[] players = PlayerInfo.Online.Items; + foreach (Player pl in players) { + if (pl.level != lvl || !pl.HasCpeExt(CpeExt.HackControl)) continue; + pl.Send(Hacks.MakeHackControl(pl)); + } + } + + static void SetRealmOwner(Player p, Level lvl, string value) { + lvl.RealmOwner = value; + if (value == "") Player.Message(p, "Removed realm owner for this level."); + else Player.Message(p, "Set realm owner/owners of this level to {0}.", value); + } + static void SetPhysicsSpeed(Player p, Level lvl, string value, string name) { SetInt(p, lvl, ref lvl.speedPhysics, value, name, PhysicsSpeedValidator); @@ -105,38 +125,6 @@ namespace MCGalaxy { return true; } - - static void SetMotd(Player p, Level lvl, string value) { - lvl.motd = value == "" ? "ignore" : value; - lvl.ChatLevel("Map's MOTD was changed to: &b" + lvl.motd); - - Player[] players = PlayerInfo.Online.Items; - foreach (Player pl in players) { - if (pl.level != lvl || !pl.HasCpeExt(CpeExt.HackControl)) continue; - pl.Send(Hacks.MakeHackControl(pl)); - } - } - - static void SetRealmOwner(Player p, Level lvl, string value) { - lvl.RealmOwner = value; - if (value == "") Player.Message(p, "Removed realm owner for this level."); - else Player.Message(p, "Set realm owner/owners of this level to {0}.", value); - } - - static void SetPerms(Player p, Level lvl, ref bool target, string name) { - Set(p, lvl, ref target, name); - lvl.UpdateBlockPermissions(); - } - - static void Set(Player p, Level lvl, ref bool target, string name, bool not = false) { - target = !target; - bool display = not ? !target : target; - lvl.ChatLevel(name + ": " + GetBool(display)); - - if (p == null || p.level != lvl) - Player.Message(p, name + ": " + GetBool(display)); - } - static void SetInt(Player p, Level lvl, ref int target, string value, string name, Func validator = null) { if (value == "") { Player.Message(p, "You must provide an integer."); return; } @@ -147,5 +135,31 @@ namespace MCGalaxy { target = raw; lvl.ChatLevel(name + ": &b" + target); } + + + static void ToggleGuns(Player p, Level lvl, string value) { + Toggle(p, lvl, ref lvl.guns, "Guns allowed"); + if (lvl.guns) return; + + Player[] players = PlayerInfo.Online.Items; + foreach (Player pl in players) { + if (pl.level.name.CaselessEq(lvl.name)) + pl.aiming = false; + } + } + + static void TogglePerms(Player p, Level lvl, ref bool target, string name) { + Toggle(p, lvl, ref target, name); + lvl.UpdateBlockPermissions(); + } + + static void Toggle(Player p, Level lvl, ref bool target, string name, bool not = false) { + target = !target; + bool display = not ? !target : target; + lvl.ChatLevel(name + ": " + GetBool(display)); + + if (p == null || p.level != lvl) + Player.Message(p, name + ": " + GetBool(display)); + } } } diff --git a/MCGalaxy/MCGalaxy_.csproj b/MCGalaxy/MCGalaxy_.csproj index 2fb122bc4..c0bbc8191 100644 --- a/MCGalaxy/MCGalaxy_.csproj +++ b/MCGalaxy/MCGalaxy_.csproj @@ -277,7 +277,6 @@ -