From 1056c06ac4d0f7e7c4a434c46db165ae1d2f45d8 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 26 Jul 2016 18:13:55 +1000 Subject: [PATCH] Fix /copy @ with rotate flips too. (Thanks goodlyay) --- Commands/Information/CmdOpStats.cs | 4 ++-- Commands/Moderation/CmdInfoSwap.cs | 27 ++++++++------------------- Commands/building/CmdCopy.cs | 3 ++- Drawing/CopyState.cs | 4 ---- Drawing/Flip.cs | 25 +++++++++++++++---------- Player/PlayerInfo.cs | 11 ++++++----- 6 files changed, 33 insertions(+), 41 deletions(-) diff --git a/Commands/Information/CmdOpStats.cs b/Commands/Information/CmdOpStats.cs index cc328e017..ad6981bf8 100644 --- a/Commands/Information/CmdOpStats.cs +++ b/Commands/Information/CmdOpStats.cs @@ -98,8 +98,8 @@ namespace MCGalaxy.Commands { } static void DoQuery(Player p, string group, string start, string end, string name, string cmd, string msg) { - DataTable table = Database.fillData("SELECT COUNT(ID) FROM Opstats WHERE Time >= '" + start + "' AND Time < '" + end + - "' AND Name LIKE '" + name + "' AND Cmd LIKE '" + cmd +"' AND Cmdmsg " + msg); + DataTable table = Database.Fill("SELECT COUNT(ID) FROM Opstats WHERE Time >= @0 AND Time < @1 " + + "AND Name LIKE @2 AND Cmd LIKE @3 AND Cmdmsg " + msg, start, end, name, cmd); // don't use colour codes in cli or gui Player.Message(p, (p == null ? "" : "&a") + group + (p == null ? "" : "&5") + table.Rows[0]["COUNT(id)"]); table.Dispose(); diff --git a/Commands/Moderation/CmdInfoSwap.cs b/Commands/Moderation/CmdInfoSwap.cs index bf3d7aa10..b02840691 100644 --- a/Commands/Moderation/CmdInfoSwap.cs +++ b/Commands/Moderation/CmdInfoSwap.cs @@ -56,26 +56,15 @@ namespace MCGalaxy.Commands { const string format = "yyyy-MM-dd HH:mm:ss"; void Swap(OfflinePlayer src, OfflinePlayer dst) { - ParameterisedQuery query = ParameterisedQuery.Create(); - query.AddParam("@Name", dst.name); - query.AddParam("@Blocks", src.blocks); - query.AddParam("@Color", Colors.Name(src.color)); - query.AddParam("@Deaths", src.deaths); - query.AddParam("@First", DateTime.Parse(src.firstLogin).ToString(format)); - query.AddParam("@IP", src.ip); - query.AddParam("@Kicks", src.kicks); - query.AddParam("@Last", DateTime.Parse(src.lastLogin).ToString(format)); - query.AddParam("@Logins", src.logins); - query.AddParam("@Money", src.money); - query.AddParam("@Title", src.title); - query.AddParam("@TColor", Colors.Name(src.titleColor)); - query.AddParam("@Time", src.totalTime); + string first = DateTime.Parse(src.firstLogin).ToString(format); + string last = DateTime.Parse(src.lastLogin).ToString(format); + const string syntax = "UPDATE Players SET totalBlocks=@0, color=@1, totalDeaths=@2" + + ", FirstLogin=@3, IP=@4, totalKicked=@5, LastLogin=@6, totalLogin=@7" + + ", Money=@8, Title=@9, title_color=@10, TimeSpent=@11 WHERE Name=@12"; - Database.executeQuery(query, "UPDATE Players SET totalBlocks=@Blocks,color=@Color," - + "totalDeaths=@Deaths,FirstLogin=@First,IP=@IP," - + "totalKicked=@Kicks,LastLogin=@Last,totalLogin=@Logins," - + "Money=@Money,Title=@Title,title_color=@TColor,TimeSpent=@Time" - + " WHERE Name=@Name"); + Database.Execute(syntax, src.blocks, src.color, src.deaths, + first, src.ip, src.kicks, last, src.logins, + src.money, src.title, src.titleColor, src.totalTime, dst.name); } void SwapGroups(OfflinePlayer src, OfflinePlayer dst) { diff --git a/Commands/building/CmdCopy.cs b/Commands/building/CmdCopy.cs index 7bb1700d1..539ae09e6 100644 --- a/Commands/building/CmdCopy.cs +++ b/Commands/building/CmdCopy.cs @@ -97,7 +97,8 @@ namespace MCGalaxy.Commands.Building { CopyState cState = new CopyState(minX, minY, minZ, maxX - minX + 1, maxY - minY + 1, maxZ - minZ + 1); - cState.SetOrigin(m[0].X, m[0].Y, m[0].Z); + cState.OriginX = m[0].X; cState.OriginY = m[0].Y; cState.OriginZ = m[0].Z; + int index = 0; cState.UsedBlocks = 0; cState.PasteAir = cArgs.type == 2; diff --git a/Drawing/CopyState.cs b/Drawing/CopyState.cs index ecc16bea5..39d04521c 100644 --- a/Drawing/CopyState.cs +++ b/Drawing/CopyState.cs @@ -58,10 +58,6 @@ namespace MCGalaxy.Drawing { ExtBlocks = null; } - public void SetOrigin(int x, int y, int z) { - OriginX = x; OriginY = y; OriginZ = z; - } - public void GetCoords(int index, out ushort x, out ushort y, out ushort z) { y = (ushort)(index / Width / Length); index -= y * Width * Length; diff --git a/Drawing/Flip.cs b/Drawing/Flip.cs index 1d7464c1e..b57f614ef 100644 --- a/Drawing/Flip.cs +++ b/Drawing/Flip.cs @@ -54,23 +54,28 @@ namespace MCGalaxy.Drawing { return Rotate(state, newState, m); } - static CopyState Rotate(CopyState state, CopyState newState, int[] m) { + static CopyState Rotate(CopyState state, CopyState flipped, int[] m) { byte[] blocks = state.Blocks, extBlocks = state.ExtBlocks; for (int i = 0; i < blocks.Length; i++) { ushort x, y, z; state.GetCoords(i, out x, out y, out z); - newState.Set(blocks[i], extBlocks[i], - Rotate(m[0], x, y, z, state), - Rotate(m[1], x, y, z, state), - Rotate(m[2], x, y, z, state)); + flipped.Set(blocks[i], extBlocks[i], + Rotate(m[0], x, y, z, state), + Rotate(m[1], x, y, z, state), + Rotate(m[2], x, y, z, state)); } int oX = state.OriginX - state.X, oY = state.OriginY - state.Y, oZ = state.OriginZ - state.Z; - newState.SetOrigin( - state.X + Rotate(m[0], oX, oY, oZ, state), - state.Y + Rotate(m[1], oX, oY, oZ, state), - state.Z + Rotate(m[2], oX, oY, oZ, state)); - return newState; + flipped.OriginX = state.X + Rotate(m[0], oX, oY, oZ, state); + flipped.OriginY = state.Y + Rotate(m[1], oX, oY, oZ, state); + flipped.OriginZ = state.Z + Rotate(m[2], oX, oY, oZ, state); + + // Offset is relative to Origin + oX += state.Offset.X; oY += state.Offset.Y; oZ += state.Offset.Z; + flipped.Offset.X = state.X + Rotate(m[0], oX, oY, oZ, state) - flipped.OriginX; + flipped.Offset.Y = state.Y + Rotate(m[1], oX, oY, oZ, state) - flipped.OriginY; + flipped.Offset.Z = state.Z + Rotate(m[2], oX, oY, oZ, state) - flipped.OriginZ; + return flipped; } const int posX = 0x100, negX = 0x200, posY = 0x010, negY = 0x020, posZ = 0x001, negZ = 0x002; diff --git a/Player/PlayerInfo.cs b/Player/PlayerInfo.cs index a75057a68..96eb28d07 100644 --- a/Player/PlayerInfo.cs +++ b/Player/PlayerInfo.cs @@ -102,12 +102,13 @@ namespace MCGalaxy { p.totalKicked = 0; p.overallDeath = 0; p.overallBlocks = 0; + string now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - const string query = "INSERT INTO Players (Name, IP, FirstLogin, LastLogin, totalLogin, Title, totalDeaths, Money, totalBlocks, totalKicked, TimeSpent) " + - "VALUES ('{0}', '{1}', '{2:yyyy-MM-dd HH:mm:ss}', '{3:yyyy-MM-dd HH:mm:ss}', {4}, '{5}', {6}, {7}, {8}, {9}, '{10}')"; - Database.executeQuery(String.Format(query, p.name, p.ip, p.firstLogin, DateTime.Now, p.totalLogins, - p.title, p.overallDeath, p.money, p.loginBlocks, p.totalKicked, p.time.ToDBTime())); - string ecoQuery = "INSERT INTO Economy (player, money, total, purchase, payment, salary, fine) " + + const string query = "INSERT INTO Players (Name, IP, FirstLogin, LastLogin, totalLogin, Title, totalDeaths" + + ", Money, totalBlocks, totalKicked, TimeSpent) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10)"; + Database.Execute(query, p.name, p.ip, now, now, 1, "", 0, 0, 0, 0, p.time.ToDBTime()); + + const string ecoQuery = "INSERT INTO Economy (player, money, total, purchase, payment, salary, fine) " + "VALUES (@0, @1, @2, @3, @4, @5, @6)"; Database.Execute(ecoQuery, p.name, p.money, 0, "%cNone", "%cNone", "%cNone", "%cNone"); }