From 2100dbd42d1a45d82fd2c946e987ca23616e9787 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 29 Oct 2017 10:53:28 +1100 Subject: [PATCH] Allow up/ua yourself, fix /ua with no args behaving incorrectly. (Thanks StarlightGlimmer) --- MCGalaxy/Commands/Moderation/CmdUndoPlayer.cs | 13 ++++++---- MCGalaxy/Entity/Entity.cs | 24 +++---------------- .../LavaSurvival/LavaSurvival.Settings.cs | 2 +- MCGalaxy/util/Utils.cs | 8 ------- 4 files changed, 12 insertions(+), 35 deletions(-) diff --git a/MCGalaxy/Commands/Moderation/CmdUndoPlayer.cs b/MCGalaxy/Commands/Moderation/CmdUndoPlayer.cs index 492b163f2..253d4172b 100644 --- a/MCGalaxy/Commands/Moderation/CmdUndoPlayer.cs +++ b/MCGalaxy/Commands/Moderation/CmdUndoPlayer.cs @@ -30,12 +30,14 @@ namespace MCGalaxy.Commands.Moderation { public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public override CommandAlias[] Aliases { get { return new[] { new CommandAlias("XUndo", null, "all"), - new CommandAlias("UndoArea", "area"), new CommandAlias("ua", "area") }; } + new CommandAlias("UndoArea", "-area"), new CommandAlias("ua", "-area") }; } } public override void Use(Player p, string message) { - bool area = message.CaselessStarts("area "); - if (area) message = message.Substring("area ".Length); + bool area = message.CaselessStarts("-area"); + if (area) { + message = message.Substring("-area".Length).TrimStart(); + } if (CheckSuper(p, message, "player name")) return; if (message.Length == 0) { Player.Message(p, "You need to provide a player name."); return; } @@ -118,7 +120,8 @@ namespace MCGalaxy.Commands.Moderation { if (names[i] == null) return null; Group grp = Group.GroupIn(names[i]); - if (p != null && grp.Permission >= p.Rank) { + bool canUndo = p == null || grp.Permission < p.Rank || p.name.CaselessEq(names[i]); + if (!canUndo) { MessageTooHighRank(p, "undo", false); return null; } @@ -130,7 +133,7 @@ namespace MCGalaxy.Commands.Moderation { public override void Help(Player p) { Player.Message(p, "%T/UndoPlayer [player1] "); Player.Message(p, "%HUndoes the block changes of [players] in the past "); - Player.Message(p, "%T/UndoPlayer area [player1] "); + Player.Message(p, "%T/UndoPlayer -area [player1] "); Player.Message(p, "%HOnly undoes block changes in the specified region."); Player.Message(p, "%H If is not given, undoes 30 minutes."); if (p == null || p.group.MaxUndo == -1 || p.group.MaxUndo == int.MaxValue) diff --git a/MCGalaxy/Entity/Entity.cs b/MCGalaxy/Entity/Entity.cs index 8689abc2c..b6741d52c 100644 --- a/MCGalaxy/Entity/Entity.cs +++ b/MCGalaxy/Entity/Entity.cs @@ -20,8 +20,6 @@ using System.Threading; using MCGalaxy.Maths; namespace MCGalaxy { - - /// Represents a player or an NPC. public abstract class Entity { // Raw orientation/position - access must be threadsafe @@ -33,44 +31,28 @@ namespace MCGalaxy { protected internal Position lastPos; internal bool hasExtPositions; - - /// Model name of this entity. public string Model = "humanoid"; - - /// AABB of the model of this entity. public AABB ModelBB; - - /// Skin name of this entity. - public string SkinName; - - - /// Gets or sets the orientation of this entity. + public string SkinName; + public Orientation Rot { get { return Orientation.Unpack(_rot); } set { _rot = value.Pack(); OnSetRot(); } } - /// Gets or sets the position of this entity. public Position Pos { get { return Position.Unpack(Interlocked.Read(ref _pos)); } set { Interlocked.Exchange(ref _pos, value.Pack()); OnSetPos(); } } - /// Sets only the yaw and pitch of the orientation of this entity. public void SetYawPitch(byte yaw, byte pitch) { Orientation rot = Rot; rot.RotY = yaw; rot.HeadX = pitch; Rot = rot; } - - - /// Returns whether this entity can see the given entity in the world/level. + public abstract bool CanSeeEntity(Entity other); - - /// Gets the entity/player ID of this entity. public abstract byte EntityID { get; } - - /// Gets the world/level this entity is on. public abstract Level Level { get; } protected virtual void OnSetPos() { } diff --git a/MCGalaxy/Games/LavaSurvival/LavaSurvival.Settings.cs b/MCGalaxy/Games/LavaSurvival/LavaSurvival.Settings.cs index 0b8628f2f..93a06d256 100644 --- a/MCGalaxy/Games/LavaSurvival/LavaSurvival.Settings.cs +++ b/MCGalaxy/Games/LavaSurvival/LavaSurvival.Settings.cs @@ -55,7 +55,7 @@ namespace MCGalaxy.Games { switch (key.ToLower()) { case "start-on-startup": startOnStartup = bool.Parse(value); break; case "send-afk-to-main": sendAfkMain = bool.Parse(value); break; - case "vote-count": voteCount = (byte)Utils.Clamp(decimal.Parse(value), 2, 10); break; + case "vote-count": voteCount = (byte)Utils.Clamp(int.Parse(value), 2, 10); break; case "vote-time": voteTime = double.Parse(value); break; case "lives": lifeNum = int.Parse(value); break; diff --git a/MCGalaxy/util/Utils.cs b/MCGalaxy/util/Utils.cs index b286f64f5..2fe465a27 100644 --- a/MCGalaxy/util/Utils.cs +++ b/MCGalaxy/util/Utils.cs @@ -73,14 +73,6 @@ namespace MCGalaxy { return Math.Max(Math.Min(value, hi), lo); } - public static decimal Clamp(decimal value, decimal lo, decimal hi) { - return Math.Max(Math.Min(value, hi), lo); - } - - public static double Clamp(double value, double lo, double hi) { - return Math.Max(Math.Min(value, hi), lo); - } - /// Divides by 16, rounding up if there is a remainder. public static int CeilDiv16(int x) { return (x + 15) / 16; }