Fix /copy @ with rotate flips too. (Thanks goodlyay)

This commit is contained in:
UnknownShadow200 2016-07-26 18:13:55 +10:00
parent 740ee15e40
commit 1056c06ac4
6 changed files with 33 additions and 41 deletions

View File

@ -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();

View File

@ -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) {

View File

@ -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;

View File

@ -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;

View File

@ -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],
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;

View File

@ -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");
}