Core: Combine /allowguns and /map

This commit is contained in:
UnknownShadow200 2016-10-05 16:58:29 +11:00
parent 28039c1bc7
commit ba51b97366
4 changed files with 62 additions and 105 deletions

View File

@ -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.");
}
}
}

View File

@ -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) {

View File

@ -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<string, string> Help = new Dictionary<string, string>() {
@ -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<Player, int, bool> 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));
}
}
}

View File

@ -277,7 +277,6 @@
<Compile Include="Commands\Information\CmdWhois.cs" />
<Compile Include="Commands\Information\CmdWhoNick.cs" />
<Compile Include="Commands\Information\WhoInfo.cs" />
<Compile Include="Commands\Moderation\CmdAllowGuns.cs" />
<Compile Include="Commands\Moderation\CmdBan.cs" />
<Compile Include="Commands\Moderation\CmdBanEdit.cs" />
<Compile Include="Commands\Moderation\CmdBanip.cs" />