mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Delay command should work in milliseconds. Fixes #475.
This commit is contained in:
parent
ebab87ca9e
commit
c5b642f1e1
@ -54,7 +54,7 @@ namespace MCGalaxy.Commands {
|
|||||||
|
|
||||||
/// <summary> Attempts to parse the given argument as an timespan in short form. </summary>
|
/// <summary> Attempts to parse the given argument as an timespan in short form. </summary>
|
||||||
public static bool GetTimespan(Player p, string input, ref TimeSpan span,
|
public static bool GetTimespan(Player p, string input, ref TimeSpan span,
|
||||||
string action, char defUnit) {
|
string action, string defUnit) {
|
||||||
span = TimeSpan.Zero;
|
span = TimeSpan.Zero;
|
||||||
try {
|
try {
|
||||||
span = input.ParseShort(defUnit);
|
span = input.ParseShort(defUnit);
|
||||||
|
@ -158,7 +158,7 @@ namespace MCGalaxy.Commands.Maintenance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TimeSpan span = TimeSpan.Zero;
|
TimeSpan span = TimeSpan.Zero;
|
||||||
if (!CommandParser.GetTimespan(p, args[2], ref span, "set time spent to", 'm')) return;
|
if (!CommandParser.GetTimespan(p, args[2], ref span, "set time spent to", "m")) return;
|
||||||
|
|
||||||
if (who != null) {
|
if (who != null) {
|
||||||
setter(span);
|
setter(span);
|
||||||
|
@ -45,7 +45,7 @@ namespace MCGalaxy.Commands.Moderation {
|
|||||||
} else {
|
} else {
|
||||||
if (args.Length < 2) { Help(p); return; }
|
if (args.Length < 2) { Help(p); return; }
|
||||||
TimeSpan duration = TimeSpan.Zero;
|
TimeSpan duration = TimeSpan.Zero;
|
||||||
if (!CommandParser.GetTimespan(p, args[1], ref duration, "freeze for", 'm')) return;
|
if (!CommandParser.GetTimespan(p, args[1], ref duration, "freeze for", "m")) return;
|
||||||
|
|
||||||
string reason = args.Length > 2 ? args[2] : "";
|
string reason = args.Length > 2 ? args[2] : "";
|
||||||
reason = ModActionCmd.ExpandReason(p, reason);
|
reason = ModActionCmd.ExpandReason(p, reason);
|
||||||
|
@ -42,7 +42,7 @@ namespace MCGalaxy.Commands.Moderation {
|
|||||||
string[] parts = message.SplitSpaces();
|
string[] parts = message.SplitSpaces();
|
||||||
|
|
||||||
if (parts.Length >= 2) {
|
if (parts.Length >= 2) {
|
||||||
if (!CommandParser.GetTimespan(p, parts[1], ref delta, "highlight the past", 's')) return;
|
if (!CommandParser.GetTimespan(p, parts[1], ref delta, "highlight the past", "s")) return;
|
||||||
} else if (ParseTimespan(parts[0], out delta)) {
|
} else if (ParseTimespan(parts[0], out delta)) {
|
||||||
parts[0] = p.name;
|
parts[0] = p.name;
|
||||||
} else {
|
} else {
|
||||||
@ -99,7 +99,7 @@ namespace MCGalaxy.Commands.Moderation {
|
|||||||
|
|
||||||
static bool ParseTimespan(string input, out TimeSpan delta) {
|
static bool ParseTimespan(string input, out TimeSpan delta) {
|
||||||
delta = TimeSpan.Zero;
|
delta = TimeSpan.Zero;
|
||||||
try { delta = input.ParseShort('s'); return true;
|
try { delta = input.ParseShort("s"); return true;
|
||||||
} catch (ArgumentException) { return false;
|
} catch (ArgumentException) { return false;
|
||||||
} catch (FormatException) { return false;
|
} catch (FormatException) { return false;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ namespace MCGalaxy.Commands.Moderation {
|
|||||||
if (args.Length < 2) { Help(p); return; }
|
if (args.Length < 2) { Help(p); return; }
|
||||||
|
|
||||||
TimeSpan duration = TimeSpan.Zero;
|
TimeSpan duration = TimeSpan.Zero;
|
||||||
if (!CommandParser.GetTimespan(p, args[1], ref duration, "mute for", 's')) return;
|
if (!CommandParser.GetTimespan(p, args[1], ref duration, "mute for", "s")) return;
|
||||||
|
|
||||||
string reason = args.Length > 2 ? args[2] : "";
|
string reason = args.Length > 2 ? args[2] : "";
|
||||||
reason = ModActionCmd.ExpandReason(p, reason);
|
reason = ModActionCmd.ExpandReason(p, reason);
|
||||||
|
@ -47,7 +47,7 @@ namespace MCGalaxy.Commands.Moderation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TimeSpan span = TimeSpan.FromHours(1);
|
TimeSpan span = TimeSpan.FromHours(1);
|
||||||
if (args.Length > 1 && !CommandParser.GetTimespan(p, args[1], ref span, "temp ban for", 'm')) return;
|
if (args.Length > 1 && !CommandParser.GetTimespan(p, args[1], ref span, "temp ban for", "m")) return;
|
||||||
if (span.TotalSeconds < 1) { Player.Message(p, "Cannot temp ban someone for less than a second."); return; }
|
if (span.TotalSeconds < 1) { Player.Message(p, "Cannot temp ban someone for less than a second."); return; }
|
||||||
|
|
||||||
reason = ModActionCmd.ExpandReason(p, reason);
|
reason = ModActionCmd.ExpandReason(p, reason);
|
||||||
|
@ -58,7 +58,7 @@ namespace MCGalaxy.Commands.Moderation {
|
|||||||
Group newRank = Matcher.FindRanks(p, args[1]);
|
Group newRank = Matcher.FindRanks(p, args[1]);
|
||||||
if (newRank == null) return;
|
if (newRank == null) return;
|
||||||
TimeSpan duration = TimeSpan.Zero;
|
TimeSpan duration = TimeSpan.Zero;
|
||||||
if (!CommandParser.GetTimespan(p, args[2], ref duration, "temp rank for", 'h')) return;
|
if (!CommandParser.GetTimespan(p, args[2], ref duration, "temp rank for", "h")) return;
|
||||||
|
|
||||||
if (Server.tempRanks.Contains(target)) {
|
if (Server.tempRanks.Contains(target)) {
|
||||||
Player.Message(p, "&cThe player already has a temporary rank assigned!"); return;
|
Player.Message(p, "&cThe player already has a temporary rank assigned!"); return;
|
||||||
|
@ -198,9 +198,9 @@ namespace MCGalaxy.Commands.World {
|
|||||||
BlockProps.Save("core", scope, i=> true);
|
BlockProps.Save("core", scope, i=> true);
|
||||||
Level[] loaded = LevelInfo.Loaded.Items;
|
Level[] loaded = LevelInfo.Loaded.Items;
|
||||||
|
|
||||||
foreach (Level lvl in loaded) {
|
foreach (Level lvl in loaded) {
|
||||||
|
lvl.BlockProps[block.Index] = Block.Props[block.Index];
|
||||||
lvl.UpdateBlockHandler(block);
|
lvl.UpdateBlockHandler(block);
|
||||||
lvl.BlockProps[block.Index] = BlockDefinition.GlobalProps[block.Index];
|
|
||||||
}
|
}
|
||||||
} else if (scope == BlockDefinition.GlobalProps) {
|
} else if (scope == BlockDefinition.GlobalProps) {
|
||||||
Level[] loaded = LevelInfo.Loaded.Items;
|
Level[] loaded = LevelInfo.Loaded.Items;
|
||||||
|
@ -203,7 +203,7 @@ namespace MCGalaxy.Commands.Building {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void GetCoreNames(List<string> names, Level lvl) {
|
static void GetCoreNames(List<string> names, Level lvl) {
|
||||||
BlockProps[] props = lvl == null ? lvl.BlockProps : Block.Props;
|
BlockProps[] props = lvl != null ? lvl.BlockProps : Block.Props;
|
||||||
for (int i = Block.air; i < Block.Count; i++) {
|
for (int i = Block.air; i < Block.Count; i++) {
|
||||||
ExtBlock block = ExtBlock.FromIndex(i);
|
ExtBlock block = ExtBlock.FromIndex(i);
|
||||||
if (block.BlockID == Block.custom_block) continue;
|
if (block.BlockID == Block.custom_block) continue;
|
||||||
|
@ -206,7 +206,7 @@ namespace MCGalaxy.Commands.Building {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void GetCoreNames(List<string> names, Level lvl) {
|
static void GetCoreNames(List<string> names, Level lvl) {
|
||||||
BlockProps[] props = lvl == null ? lvl.BlockProps : Block.Props;
|
BlockProps[] props = lvl != null ? lvl.BlockProps : Block.Props;
|
||||||
for (int i = Block.air; i < Block.Count; i++) {
|
for (int i = Block.air; i < Block.Count; i++) {
|
||||||
ExtBlock block = ExtBlock.FromIndex(i);
|
ExtBlock block = ExtBlock.FromIndex(i);
|
||||||
if (block.BlockID == Block.custom_block) continue;
|
if (block.BlockID == Block.custom_block) continue;
|
||||||
|
@ -115,7 +115,7 @@ namespace MCGalaxy.Commands.Building {
|
|||||||
|
|
||||||
if (timespan.CaselessEq("all")) {
|
if (timespan.CaselessEq("all")) {
|
||||||
return TimeSpan.FromSeconds(canAll ? int.MaxValue : p.group.MaxUndo);
|
return TimeSpan.FromSeconds(canAll ? int.MaxValue : p.group.MaxUndo);
|
||||||
} else if (!CommandParser.GetTimespan(p, timespan, ref delta, "undo the past", 's')) {
|
} else if (!CommandParser.GetTimespan(p, timespan, ref delta, "undo the past", "s")) {
|
||||||
return TimeSpan.MinValue;
|
return TimeSpan.MinValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ namespace MCGalaxy.Commands.World {
|
|||||||
|
|
||||||
public override void Use(Player p, string message) {
|
public override void Use(Player p, string message) {
|
||||||
TimeSpan duration = TimeSpan.Zero;
|
TimeSpan duration = TimeSpan.Zero;
|
||||||
if (!CommandParser.GetTimespan(p, message, ref duration, "wait for", 's')) return;
|
if (!CommandParser.GetTimespan(p, message, ref duration, "wait for", "ms")) return;
|
||||||
|
|
||||||
if (duration.TotalSeconds > 60) {
|
if (duration.TotalSeconds > 60) {
|
||||||
Player.Message(p, "Can only wait for a minute at most."); return;
|
Player.Message(p, "Can only wait for a minute at most."); return;
|
||||||
@ -48,8 +48,9 @@ namespace MCGalaxy.Commands.World {
|
|||||||
public override void Help(Player p) {
|
public override void Help(Player p) {
|
||||||
Player.Message(p, "%T/delay [timespan]");
|
Player.Message(p, "%T/delay [timespan]");
|
||||||
Player.Message(p, "%HWaits for a certain amount of time.");
|
Player.Message(p, "%HWaits for a certain amount of time.");
|
||||||
Player.Message(p, "%HThis is mainly designed for use in %T/mb%H, to run a command after a certain delay.");
|
Player.Message(p, "%HMain use is to run a command after a certain delay in a %T/mb");
|
||||||
Player.Message(p, "%H e.g. %T/mb air /delay 10 |/help me");
|
Player.Message(p, "%H e.g. %T/mb air /delay 1000ms |/help me %Hruns %T/help me " +
|
||||||
|
"%H1000 milliseconds (1 second) after the mb is clicked");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ namespace MCGalaxy.Network {
|
|||||||
req.UserAgent = Server.SoftwareNameVersioned;
|
req.UserAgent = Server.SoftwareNameVersioned;
|
||||||
return (WebRequest)req;
|
return (WebRequest)req;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static IPEndPoint BindIPEndPointCallback(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount) {
|
static IPEndPoint BindIPEndPointCallback(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount) {
|
||||||
IPAddress localIP = null;
|
IPAddress localIP = null;
|
||||||
|
@ -36,27 +36,6 @@ namespace MCGalaxy {
|
|||||||
return negate ? "-" + time : time;
|
return negate ? "-" + time : time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TimeSpan ParseShort(this string value, char defUnit) {
|
|
||||||
int num = 0;
|
|
||||||
long amount = 0, total = 0;
|
|
||||||
|
|
||||||
foreach (char c in value) {
|
|
||||||
if (c == ' ') continue;
|
|
||||||
if (c >= '0' && c <= '9') {
|
|
||||||
num = checked(num * 10); num += (c - '0');
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
amount = GetTicks(num, c);
|
|
||||||
total = checked(total + amount);
|
|
||||||
num = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
amount = GetTicks(num, defUnit);
|
|
||||||
total = checked(total + amount);
|
|
||||||
return TimeSpan.FromTicks(total);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Add(ref string time, int amount, char suffix, bool spaces) {
|
static void Add(ref string time, int amount, char suffix, bool spaces) {
|
||||||
if (amount == 0) return;
|
if (amount == 0) return;
|
||||||
|
|
||||||
@ -65,19 +44,53 @@ namespace MCGalaxy {
|
|||||||
else
|
else
|
||||||
time = time + (spaces ? " " : "") + amount + suffix;
|
time = time + (spaces ? " " : "") + amount + suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static long GetTicks(int num, char unit) {
|
public static TimeSpan ParseShort(this string value, string defaultUnit) {
|
||||||
if (unit == 's' || unit == 'S')
|
int num = 0;
|
||||||
return num * TimeSpan.TicksPerSecond;
|
long amount = 0, total = 0;
|
||||||
if (unit == 'm' || unit == 'M')
|
|
||||||
return num * TimeSpan.TicksPerMinute;
|
for (int i = 0; i < value.Length; i++) {
|
||||||
if (unit == 'h' || unit == 'H')
|
char c = value[i];
|
||||||
return num * TimeSpan.TicksPerHour;
|
if (c == ' ') continue;
|
||||||
if (unit == 'd' || unit == 'D')
|
|
||||||
return num * TimeSpan.TicksPerDay;
|
if (c >= '0' && c <= '9') {
|
||||||
if (unit == 'w' || unit == 'W')
|
num = checked(num * 10); num += (c - '0');
|
||||||
return num * TimeSpan.TicksPerDay * 7;
|
continue;
|
||||||
throw new FormatException(unit.ToString());
|
}
|
||||||
|
|
||||||
|
amount = GetTicks(num, GetUnit(value, i));
|
||||||
|
total = checked(total + amount);
|
||||||
|
num = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
amount = GetTicks(num, defaultUnit);
|
||||||
|
total = checked(total + amount);
|
||||||
|
return TimeSpan.FromTicks(total);
|
||||||
|
}
|
||||||
|
|
||||||
|
static long GetTicks(int num, string unit) {
|
||||||
|
if (unit == "s" || unit == "S") return num * TimeSpan.TicksPerSecond;
|
||||||
|
if (unit == "m" || unit == "M") return num * TimeSpan.TicksPerMinute;
|
||||||
|
if (unit == "h" || unit == "H") return num * TimeSpan.TicksPerHour;
|
||||||
|
if (unit == "d" || unit == "D") return num * TimeSpan.TicksPerDay;
|
||||||
|
if (unit == "w" || unit == "W") return num * TimeSpan.TicksPerDay * 7;
|
||||||
|
|
||||||
|
if (unit == "ms" || unit == "MS") return num * TimeSpan.TicksPerMillisecond;
|
||||||
|
throw new FormatException(unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
static string GetUnit(string value, int i) {
|
||||||
|
string unit = "";
|
||||||
|
// Find all alphabetical chars
|
||||||
|
for (; i < value.Length; i++) {
|
||||||
|
char c = value[i];
|
||||||
|
if (c == ' ') continue;
|
||||||
|
|
||||||
|
if (c >= '0' && c <= '9') break;
|
||||||
|
unit += value[i];
|
||||||
|
}
|
||||||
|
return unit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user