mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 20:16:36 -04:00
Simplify /binfo output and also use relative instead of absolute time.
This commit is contained in:
parent
8631316201
commit
5c1c4cc937
@ -14,16 +14,14 @@
|
||||
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.Collections.Generic;
|
||||
using System.Data;
|
||||
using MCGalaxy.SQL;
|
||||
|
||||
namespace MCGalaxy.Commands
|
||||
{
|
||||
public sealed class CmdAbout : Command
|
||||
{
|
||||
namespace MCGalaxy.Commands {
|
||||
public sealed class CmdAbout : Command {
|
||||
public override string name { get { return "about"; } }
|
||||
public override string shortcut { get { return "b"; } }
|
||||
public override string type { get { return CommandTypes.Information; } }
|
||||
@ -41,66 +39,57 @@ namespace MCGalaxy.Commands
|
||||
void PlacedBlock(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
if (!p.staticCommands) p.ClearBlockchange();
|
||||
byte b = p.level.GetTile(x, y, z);
|
||||
if (b == Block.Zero) { Player.Message(p, "Invalid Block(" + x + "," + y + "," + z + ")!"); return; }
|
||||
p.SendBlockchange(x, y, z, b);
|
||||
if (b == Block.Zero) { Player.Message(p, "Invalid Block ({0}, {1}, {2}).", x, y, z); return; }
|
||||
p.RevertBlock(x, y, z);
|
||||
|
||||
byte id = b;
|
||||
if (b == Block.custom_block)
|
||||
id = p.level.GetExtTile(x, y, z);
|
||||
|
||||
string message = "Block (" + x + "," + y + "," + z + "): ";
|
||||
message += "&f" + id + " = " + Block.Name(b);
|
||||
Player.Message(p, message + "%S.");
|
||||
Player.Message(p, "Block ({0}, {1}, {2}): &f{3} = {4}%S.", x, y, z, id, Block.Name(b));
|
||||
DateTime now = DateTime.Now;
|
||||
bool foundOne = false;
|
||||
|
||||
//safe against SQL injections because no user input is given here
|
||||
DataTable Blocks = Database.fillData("SELECT * FROM `Block" + p.level.name + "` WHERE X=" + (int)x + " AND Y=" + (int)y + " AND Z=" + (int)z);
|
||||
string Username, TimePerformed, BlockUsed;
|
||||
bool Deleted, foundOne = false;
|
||||
|
||||
for (int i = 0; i < Blocks.Rows.Count; i++) {
|
||||
foundOne = true;
|
||||
DataRow row = Blocks.Rows[i];
|
||||
Username = row["Username"].ToString().Trim();
|
||||
TimePerformed = DateTime.Parse(row["TimePerformed"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
|
||||
BlockUsed = Block.Name(Convert.ToByte(row["Type"]));
|
||||
Deleted = Convert.ToBoolean(row["Deleted"]);
|
||||
|
||||
if (!Deleted)
|
||||
Player.Message(p, "&3Created by " + Server.FindColor(Username) + Username + "%S, using &3" + BlockUsed);
|
||||
else
|
||||
Player.Message(p, "&4Destroyed by " + Server.FindColor(Username) + Username + "%S, using &3" + BlockUsed);
|
||||
Player.Message(p, "Date and time modified: &2" + TimePerformed);
|
||||
string user = row["Username"].ToString().Trim();
|
||||
DateTime time = DateTime.Parse(row["TimePerformed"].ToString());
|
||||
byte block = Convert.ToByte(row["Type"]);
|
||||
bool deleted = Convert.ToBoolean(row["Deleted"]);
|
||||
Output(p, user, block, deleted, now - time);
|
||||
}
|
||||
Blocks.Dispose();
|
||||
|
||||
int bpIndex = p.level.PosToInt(x, y, z);
|
||||
List<Level.BlockPos> inCache = p.level.blockCache.FindAll(bP => bP.index == bpIndex);
|
||||
for (int i = 0; i < inCache.Count; i++) {
|
||||
foundOne = true;
|
||||
Deleted = (inCache[i].flags & 1) != 0;
|
||||
Username = inCache[i].name.Trim();
|
||||
string user = inCache[i].name.Trim();
|
||||
DateTime time = Server.StartTimeLocal.AddSeconds(inCache[i].flags >> 2);
|
||||
TimePerformed = time.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
byte inBlock = (inCache[i].flags & 2) != 0 ? Block.custom_block : inCache[i].rawType;
|
||||
BlockUsed = Block.Name(inBlock);
|
||||
|
||||
if (!Deleted)
|
||||
Player.Message(p, "&3Created by " + Server.FindColor(Username) + Username + "%S, using &3" + BlockUsed);
|
||||
else
|
||||
Player.Message(p, "&4Destroyed by " + Server.FindColor(Username) + Username + "%S, using &3" + BlockUsed);
|
||||
Player.Message(p, "Date and time modified: &2" + TimePerformed);
|
||||
byte block = (inCache[i].flags & 2) != 0 ? Block.custom_block : inCache[i].rawType;
|
||||
bool deleted = (inCache[i].flags & 1) != 0;
|
||||
Output(p, user, block, deleted, now - time);
|
||||
}
|
||||
|
||||
if (!foundOne)
|
||||
Player.Message(p, "This block has not been modified since the map was cleared.");
|
||||
|
||||
Blocks.Dispose();
|
||||
|
||||
Player.Message(p, "No block change records found for this block.");
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
}
|
||||
|
||||
static void Output(Player p, string user, byte block, bool deleted, TimeSpan delta) {
|
||||
string bName = Block.Name(block);
|
||||
user = Server.FindColor(user) + user;
|
||||
|
||||
Player.Message(p, "{0} ago {1} {2}", delta.Shorten(true, false), user,
|
||||
deleted ? "&4deleted%S (using " + bName + ")" : "&3placed%S " + bName);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/about");
|
||||
Player.Message(p, "%HDisplays information about a block.");
|
||||
Player.Message(p, "%HOutputs the change/edit history for a block.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,15 +21,16 @@ using System.Linq;
|
||||
namespace MCGalaxy {
|
||||
public static class TimeUtils {
|
||||
|
||||
public static string Shorten(this TimeSpan value, bool seconds = false) {
|
||||
public static string Shorten(this TimeSpan value,
|
||||
bool seconds = false, bool spaces = true) {
|
||||
string time = "";
|
||||
bool negate = value.TotalSeconds < 0;
|
||||
if (negate) value = -value;
|
||||
|
||||
Add(ref time, value.Days, 'd');
|
||||
Add(ref time, value.Hours, 'h');
|
||||
Add(ref time, value.Minutes, 'm');
|
||||
if (seconds) Add(ref time, value.Seconds, 's');
|
||||
Add(ref time, value.Days, 'd', spaces);
|
||||
Add(ref time, value.Hours, 'h', spaces);
|
||||
Add(ref time, value.Minutes, 'm', spaces);
|
||||
if (seconds) Add(ref time, value.Seconds, 's', spaces);
|
||||
|
||||
if (time == "") time = seconds ? "0s" : "0m";
|
||||
return negate ? "-" + time : time;
|
||||
@ -83,10 +84,13 @@ namespace MCGalaxy {
|
||||
int.Parse(parts[2]), int.Parse(parts[3]));
|
||||
}
|
||||
|
||||
static void Add(ref string time, int amount, char suffix) {
|
||||
static void Add(ref string time, int amount, char suffix, bool spaces) {
|
||||
if (amount == 0) return;
|
||||
if (time == "") time = "" + amount + suffix;
|
||||
else time = time + " " + amount + suffix;
|
||||
|
||||
if (time == "")
|
||||
time = "" + amount + suffix;
|
||||
else
|
||||
time = time + (spaces ? " " : "") + amount + suffix;
|
||||
}
|
||||
|
||||
static long GetTicks(int num, char unit) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user