Allow up/ua yourself, fix /ua with no args behaving incorrectly. (Thanks StarlightGlimmer)

This commit is contained in:
UnknownShadow200 2017-10-29 10:53:28 +11:00
parent 3d66680b42
commit 2100dbd42d
4 changed files with 12 additions and 35 deletions

View File

@ -30,12 +30,14 @@ namespace MCGalaxy.Commands.Moderation {
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public override CommandAlias[] Aliases { public override CommandAlias[] Aliases {
get { return new[] { new CommandAlias("XUndo", null, "all"), 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) { public override void Use(Player p, string message) {
bool area = message.CaselessStarts("area "); bool area = message.CaselessStarts("-area");
if (area) message = message.Substring("area ".Length); if (area) {
message = message.Substring("-area".Length).TrimStart();
}
if (CheckSuper(p, message, "player name")) return; if (CheckSuper(p, message, "player name")) return;
if (message.Length == 0) { Player.Message(p, "You need to provide a 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; if (names[i] == null) return null;
Group grp = Group.GroupIn(names[i]); 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; MessageTooHighRank(p, "undo", false); return null;
} }
@ -130,7 +133,7 @@ namespace MCGalaxy.Commands.Moderation {
public override void Help(Player p) { public override void Help(Player p) {
Player.Message(p, "%T/UndoPlayer [player1] <player2..> <timespan>"); Player.Message(p, "%T/UndoPlayer [player1] <player2..> <timespan>");
Player.Message(p, "%HUndoes the block changes of [players] in the past <timespan>"); Player.Message(p, "%HUndoes the block changes of [players] in the past <timespan>");
Player.Message(p, "%T/UndoPlayer area [player1] <player2..> <timespan>"); Player.Message(p, "%T/UndoPlayer -area [player1] <player2..> <timespan>");
Player.Message(p, "%HOnly undoes block changes in the specified region."); Player.Message(p, "%HOnly undoes block changes in the specified region.");
Player.Message(p, "%H If <timespan> is not given, undoes 30 minutes."); Player.Message(p, "%H If <timespan> is not given, undoes 30 minutes.");
if (p == null || p.group.MaxUndo == -1 || p.group.MaxUndo == int.MaxValue) if (p == null || p.group.MaxUndo == -1 || p.group.MaxUndo == int.MaxValue)

View File

@ -20,8 +20,6 @@ using System.Threading;
using MCGalaxy.Maths; using MCGalaxy.Maths;
namespace MCGalaxy { namespace MCGalaxy {
/// <summary> Represents a player or an NPC. </summary>
public abstract class Entity { public abstract class Entity {
// Raw orientation/position - access must be threadsafe // Raw orientation/position - access must be threadsafe
@ -33,44 +31,28 @@ namespace MCGalaxy {
protected internal Position lastPos; protected internal Position lastPos;
internal bool hasExtPositions; internal bool hasExtPositions;
/// <summary> Model name of this entity. </summary>
public string Model = "humanoid"; public string Model = "humanoid";
/// <summary> AABB of the model of this entity. </summary>
public AABB ModelBB; public AABB ModelBB;
public string SkinName;
/// <summary> Skin name of this entity. </summary>
public string SkinName;
/// <summary> Gets or sets the orientation of this entity. </summary>
public Orientation Rot { public Orientation Rot {
get { return Orientation.Unpack(_rot); } get { return Orientation.Unpack(_rot); }
set { _rot = value.Pack(); OnSetRot(); } set { _rot = value.Pack(); OnSetRot(); }
} }
/// <summary> Gets or sets the position of this entity. </summary>
public Position Pos { public Position Pos {
get { return Position.Unpack(Interlocked.Read(ref _pos)); } get { return Position.Unpack(Interlocked.Read(ref _pos)); }
set { Interlocked.Exchange(ref _pos, value.Pack()); OnSetPos(); } set { Interlocked.Exchange(ref _pos, value.Pack()); OnSetPos(); }
} }
/// <summary> Sets only the yaw and pitch of the orientation of this entity. </summary>
public void SetYawPitch(byte yaw, byte pitch) { public void SetYawPitch(byte yaw, byte pitch) {
Orientation rot = Rot; Orientation rot = Rot;
rot.RotY = yaw; rot.HeadX = pitch; rot.RotY = yaw; rot.HeadX = pitch;
Rot = rot; Rot = rot;
} }
/// <summary> Returns whether this entity can see the given entity in the world/level. </summary>
public abstract bool CanSeeEntity(Entity other); public abstract bool CanSeeEntity(Entity other);
/// <summary> Gets the entity/player ID of this entity. </summary>
public abstract byte EntityID { get; } public abstract byte EntityID { get; }
/// <summary> Gets the world/level this entity is on. </summary>
public abstract Level Level { get; } public abstract Level Level { get; }
protected virtual void OnSetPos() { } protected virtual void OnSetPos() { }

View File

@ -55,7 +55,7 @@ namespace MCGalaxy.Games {
switch (key.ToLower()) { switch (key.ToLower()) {
case "start-on-startup": startOnStartup = bool.Parse(value); break; case "start-on-startup": startOnStartup = bool.Parse(value); break;
case "send-afk-to-main": sendAfkMain = 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 "vote-time": voteTime = double.Parse(value); break;
case "lives": lifeNum = int.Parse(value); break; case "lives": lifeNum = int.Parse(value); break;

View File

@ -73,14 +73,6 @@ namespace MCGalaxy {
return Math.Max(Math.Min(value, hi), lo); 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);
}
/// <summary> Divides by 16, rounding up if there is a remainder. </summary> /// <summary> Divides by 16, rounding up if there is a remainder. </summary>
public static int CeilDiv16(int x) { return (x + 15) / 16; } public static int CeilDiv16(int x) { return (x + 15) / 16; }