forked from LogBlock/LogBlock
Added /lb redo
This commit is contained in:
@@ -189,7 +189,7 @@ public class LogBlock extends JavaPlugin
|
||||
player.sendMessage(ChatColor.RED + "Usage: /lb block [type] <radius>");
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "You aren't allowed to do this");
|
||||
} else if (args[0].equalsIgnoreCase("rollback")) {
|
||||
} else if (args[0].equalsIgnoreCase("rollback") || args[0].equalsIgnoreCase("undo")) {
|
||||
if (CheckPermission(player,"logblock.rollback")) {
|
||||
if (args.length >= 2) {
|
||||
int minutes = config.defaultTime;
|
||||
@@ -198,7 +198,7 @@ public class LogBlock extends JavaPlugin
|
||||
if (args.length == 5)
|
||||
minutes = parseTimeSpec(args[3], args[4]);
|
||||
player.sendMessage(ChatColor.GREEN + "Rolling back " + args[2] + " by " + minutes + " minutes.");
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(player, conn, this, args[2], minutes, table));
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(player, conn, this, args[2], -1, null, minutes, table, false));
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Usage: /lb rollback player [name] <time> <minutes|hours|days>");
|
||||
} else if (args[1].equalsIgnoreCase("area")) {
|
||||
@@ -207,7 +207,7 @@ public class LogBlock extends JavaPlugin
|
||||
minutes = parseTimeSpec(args[3], args[4]);
|
||||
if (isInt(args[2])) {
|
||||
player.sendMessage(ChatColor.GREEN + "Rolling back area within " + args[2] + " blocks of you by " + minutes + " minutes.");
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(player, conn, this, Integer.parseInt(args[2]), minutes, table));
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(player, conn, this, null, Integer.parseInt(args[2]), null, minutes, table, false));
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Can't parse to an int: " + args[2]);
|
||||
} else
|
||||
@@ -218,7 +218,7 @@ public class LogBlock extends JavaPlugin
|
||||
minutes = parseTimeSpec(args[4], args[5]);
|
||||
if (isInt(args[3])) {
|
||||
player.sendMessage(ChatColor.GREEN + "Rolling back " + args[2] + " within " + args[3] + " blocks by " + minutes + " minutes.");
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(player, conn, this, args[2], Integer.parseInt(args[3]), minutes, table));
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(player, conn, this, args[2], Integer.parseInt(args[3]), null, minutes, table, false));
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Can't parse to an int: " + args[3]);
|
||||
} else
|
||||
@@ -233,7 +233,7 @@ public class LogBlock extends JavaPlugin
|
||||
if (sel != null) {
|
||||
if (sel instanceof CuboidSelection) {
|
||||
player.sendMessage(ChatColor.GREEN + "Rolling back selection by " + minutes + " minutes.");
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(player, conn, this, sel.getMinimumPoint(), sel.getMaximumPoint(), minutes, table));
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(player, conn, this, null, -1, sel, minutes, table, false));
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "You have to define a cuboid selection");
|
||||
} else
|
||||
@@ -253,6 +253,70 @@ public class LogBlock extends JavaPlugin
|
||||
}
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "You aren't allowed to do this");
|
||||
} else if (args[0].equalsIgnoreCase("redo")) {
|
||||
if (CheckPermission(player,"logblock.rollback")) {
|
||||
if (args.length >= 2) {
|
||||
int minutes = config.defaultTime;
|
||||
if (args[1].equalsIgnoreCase("player")) {
|
||||
if (args.length == 3 || args.length == 5) {
|
||||
if (args.length == 5)
|
||||
minutes = parseTimeSpec(args[3], args[4]);
|
||||
player.sendMessage(ChatColor.GREEN + "Redoing " + args[2] + " for " + minutes + " minutes.");
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(player, conn, this, args[2], -1, null, minutes, table, true));
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Usage: /lb redo player [name] <time> <minutes|hours|days>");
|
||||
} else if (args[1].equalsIgnoreCase("area")) {
|
||||
if (args.length == 3 || args.length == 5) {
|
||||
if (args.length == 5)
|
||||
minutes = parseTimeSpec(args[3], args[4]);
|
||||
if (isInt(args[2])) {
|
||||
player.sendMessage(ChatColor.GREEN + "Redoing area within " + args[2] + " blocks of you for " + minutes + " minutes.");
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(player, conn, this, null, Integer.parseInt(args[2]), null, minutes, table, true));
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Can't parse to an int: " + args[2]);
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Usage /lb redo area [radius] <time> <minutes|hours|days>");
|
||||
} else if (args[1].equalsIgnoreCase("playerarea")) {
|
||||
if (args.length == 4 || args.length == 6) {
|
||||
if (args.length == 6)
|
||||
minutes = parseTimeSpec(args[4], args[5]);
|
||||
if (isInt(args[3])) {
|
||||
player.sendMessage(ChatColor.GREEN + "Redoing " + args[2] + " within " + args[3] + " blocks for " + minutes + " minutes.");
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(player, conn, this, args[2], Integer.parseInt(args[3]), null, minutes, table, true));
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Can't parse to an int: " + args[3]);
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Usage: /lb redo playerarea [player] [radius] <time> <minutes|hours|days>");
|
||||
} else if (args[1].equalsIgnoreCase("selection")) {
|
||||
if (args.length == 2 || args.length == 4) {
|
||||
if (args.length == 4)
|
||||
minutes = parseTimeSpec(args[2], args[3]);
|
||||
Plugin we = getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
if (we != null) {
|
||||
Selection sel = ((WorldEditPlugin)we).getSelection(player);
|
||||
if (sel != null) {
|
||||
if (sel instanceof CuboidSelection) {
|
||||
player.sendMessage(ChatColor.GREEN + "Redoing selection for " + minutes + " minutes.");
|
||||
getServer().getScheduler().scheduleAsyncDelayedTask(this, new Rollback(player, conn, this, null, -1, sel, minutes, table, true));
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "You have to define a cuboid selection");
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "No selection defined");
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "WorldEdit plugin not found");
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Usage: /lb redo selection <time> <minutes|hours|days>");
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "Wrong redo mode");
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "Usage:");
|
||||
player.sendMessage(ChatColor.RED + "/lb redo player [name] <time> <minutes|hours|days>");
|
||||
player.sendMessage(ChatColor.RED + "/lb redo area [radius] <time> <minutes|hours|days>");
|
||||
player.sendMessage(ChatColor.RED + "/lb redo playerarea [name] [radius] <time> <minutes|hours|days>");
|
||||
player.sendMessage(ChatColor.RED + "/lb redo selection <time> <minutes|hours|days>");
|
||||
}
|
||||
} else
|
||||
player.sendMessage(ChatColor.RED + "You aren't allowed to do this");
|
||||
} else if (args[0].equalsIgnoreCase("writelogfile")) {
|
||||
if (CheckPermission(player,"logblock.rollback")) {
|
||||
if (args.length == 2) {
|
||||
|
@@ -1,101 +1,56 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.selections.Selection;
|
||||
|
||||
public class Rollback implements Runnable
|
||||
{
|
||||
|
||||
PreparedStatement ps = null;
|
||||
private Player player;
|
||||
private Connection conn;
|
||||
private LogBlock logblock;
|
||||
private String query;
|
||||
private boolean redo;
|
||||
|
||||
Rollback(Player player, Connection conn, LogBlock logblock, String name, int minutes, String table) {
|
||||
Rollback(Player player, Connection conn, LogBlock logblock, String name, int radius, Selection sel, int minutes, String table, boolean redo) {
|
||||
this.player = player;
|
||||
this.conn = conn;
|
||||
this.logblock = logblock;
|
||||
try {
|
||||
conn.setAutoCommit(false);
|
||||
ps = conn.prepareStatement("SELECT type, data, replaced, x, y, z FROM `" + table + "` INNER JOIN `lb-players` USING (`playerid`) WHERE playername = ? AND date > date_sub(now(), INTERVAL ? MINUTE) ORDER BY date DESC");
|
||||
ps.setString(1, name);
|
||||
ps.setInt(2, minutes);
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, this.getClass().getName() + " SQL exception", ex);
|
||||
player.sendMessage(ChatColor.RED + "Error, check server logs.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Rollback(Player player, Connection conn, LogBlock logblock, String name, int radius, int minutes, String table) {
|
||||
this.player = player;
|
||||
this.conn = conn;
|
||||
this.logblock = logblock;
|
||||
try {
|
||||
conn.setAutoCommit(false);
|
||||
ps = conn.prepareStatement("SELECT type, data, replaced, x, y, z FROM `" + table + "` INNER JOIN `lb-players` USING (`playerid`) WHERE playername = ? AND x > ? AND x < ? AND z > ? AND z < ? AND date > date_sub(now(), INTERVAL ? MINUTE) ORDER BY date DESC");
|
||||
ps.setString(1, name);
|
||||
ps.setInt(2, player.getLocation().getBlockX()-radius);
|
||||
ps.setInt(3, player.getLocation().getBlockX()+radius);
|
||||
ps.setInt(4, player.getLocation().getBlockZ()-radius);
|
||||
ps.setInt(5, player.getLocation().getBlockZ()+radius);
|
||||
ps.setInt(6, minutes);
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, this.getClass().getName() + " SQL exception", ex);
|
||||
player.sendMessage(ChatColor.RED + "Error, check server logs.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Rollback(Player player, Connection conn, LogBlock logblock, int radius, int minutes, String table) {
|
||||
this.player = player;
|
||||
this.conn = conn;
|
||||
this.logblock = logblock;
|
||||
try {
|
||||
conn.setAutoCommit(false);
|
||||
ps = conn.prepareStatement("SELECT type, data, replaced, x, y, z FROM `" + table + "` WHERE x > ? AND x < ? AND z > ? AND z < ? AND date > date_sub(now(), INTERVAL ? MINUTE) ORDER BY date DESC");
|
||||
ps.setInt(1, player.getLocation().getBlockX()-radius);
|
||||
ps.setInt(2, player.getLocation().getBlockX()+radius);
|
||||
ps.setInt(3, player.getLocation().getBlockZ()-radius);
|
||||
ps.setInt(4, player.getLocation().getBlockZ()+radius);
|
||||
ps.setInt(5, minutes);
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, this.getClass().getName() + " SQL exception", ex);
|
||||
player.sendMessage(ChatColor.RED + "Error, check server logs.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Rollback(Player player, Connection conn, LogBlock logblock, Location loc1, Location loc2, int minutes, String table) {
|
||||
this.player = player;
|
||||
this.conn = conn;
|
||||
this.logblock = logblock;
|
||||
try {
|
||||
conn.setAutoCommit(false);
|
||||
ps = conn.prepareStatement("SELECT type, data, replaced, x, y, z FROM `" + table + "` WHERE x >= ? AND x <= ? AND y >= ? AND y <= ? AND z >= ? AND z <= ? AND date > date_sub(now(), INTERVAL ? MINUTE) ORDER BY date DESC", Statement.RETURN_GENERATED_KEYS);
|
||||
ps.setInt(1, Math.min(loc1.getBlockX(), loc2.getBlockX()));
|
||||
ps.setInt(2, Math.max(loc1.getBlockX(), loc2.getBlockX()));
|
||||
ps.setInt(3, Math.min(loc1.getBlockY(), loc2.getBlockY()));
|
||||
ps.setInt(4, Math.max(loc1.getBlockY(), loc2.getBlockY()));
|
||||
ps.setInt(5, Math.min(loc1.getBlockZ(), loc2.getBlockZ()));
|
||||
ps.setInt(6, Math.max(loc1.getBlockZ(), loc2.getBlockZ()));
|
||||
ps.setInt(7, minutes);
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, this.getClass().getName() + " SQL exception", ex);
|
||||
player.sendMessage(ChatColor.RED + "Error, check server logs.");
|
||||
return;
|
||||
}
|
||||
this.redo = redo;
|
||||
if (!redo)
|
||||
query = "SELECT replaced, type, data, x, y, z FROM `" + table + "` INNER JOIN `lb-players` USING (playerid) WHERE ";
|
||||
else
|
||||
query = "SELECT type AS replaced, replaced AS type, data, x, y, z FROM `" + table + "` INNER JOIN `lb-players` USING (playerid) WHERE ";
|
||||
if (name != null)
|
||||
query += "playername = '" + name + "' AND ";
|
||||
if (radius != -1)
|
||||
query += "x > '" + (player.getLocation().getBlockX() - radius)
|
||||
+ "' AND x < '" + (player.getLocation().getBlockX() + radius)
|
||||
+ "' AND z > '" + (player.getLocation().getBlockZ() - radius)
|
||||
+ "' AND z < '" + (player.getLocation().getBlockZ() + radius) + "' AND ";
|
||||
if (sel != null)
|
||||
query += "x >= '"+ Math.min(sel.getMinimumPoint().getBlockX(), sel.getMaximumPoint().getBlockX())
|
||||
+ "' AND x <= '" + Math.max(sel.getMinimumPoint().getBlockX(), sel.getMaximumPoint().getBlockX())
|
||||
+ "' AND y >= '" + Math.min(sel.getMinimumPoint().getBlockY(), sel.getMaximumPoint().getBlockY())
|
||||
+ "' AND y <= '" + Math.max(sel.getMinimumPoint().getBlockY(), sel.getMaximumPoint().getBlockY())
|
||||
+ "' AND z >= '" + Math.min(sel.getMinimumPoint().getBlockZ(), sel.getMaximumPoint().getBlockZ())
|
||||
+ "' AND z <= '" + Math.max(sel.getMinimumPoint().getBlockZ(), sel.getMaximumPoint().getBlockZ()) + "' AND ";
|
||||
if (minutes >= 0)
|
||||
query += "date > date_sub(now(), INTERVAL " + minutes + " MINUTE) AND ";
|
||||
query = query.substring(0, query.length() - 4);
|
||||
if (!redo)
|
||||
query += "ORDER BY date DESC, id DESC";
|
||||
else
|
||||
query += "ORDER BY date ASC, id ASC";
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@@ -103,25 +58,23 @@ public class Rollback implements Runnable
|
||||
LinkedBlockingQueue<Edit> edits = new LinkedBlockingQueue<Edit>();
|
||||
edits.clear();
|
||||
try {
|
||||
rs = ps.executeQuery();
|
||||
rs = conn.createStatement().executeQuery(query);
|
||||
while (rs.next()) {
|
||||
Edit e = new Edit(rs.getInt("type"), rs.getInt("replaced"), rs.getByte("data"), rs.getInt("x"), rs.getInt("y"), rs.getInt("z"), player.getWorld());
|
||||
edits.offer(e);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, this.getClass().getName() + " SQL exception", ex);
|
||||
player.sendMessage(ChatColor.RED + "<EFBFBD>cError, check server logs.");
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock Rollback] SQL exception", ex);
|
||||
player.sendMessage(ChatColor.RED + "Error, check server logs.");
|
||||
return;
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null)
|
||||
rs.close();
|
||||
if (ps != null)
|
||||
ps.close();
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
LogBlock.log.log(Level.SEVERE, this.getClass().getName() + " SQL exception on close", ex);
|
||||
LogBlock.log.log(Level.SEVERE, "[LogBlock Rollback] SQL exception on close", ex);
|
||||
player.sendMessage(ChatColor.RED + "Error, check server logs.");
|
||||
return;
|
||||
}
|
||||
@@ -143,8 +96,13 @@ public class Rollback implements Runnable
|
||||
}
|
||||
}
|
||||
logblock.getServer().getScheduler().cancelTask(taskID);
|
||||
player.sendMessage(ChatColor.GREEN + "Rollback finished successfully");
|
||||
player.sendMessage(ChatColor.GREEN + "Undid " + perform.rolledBack + " of " + changes + " changes");
|
||||
if (!redo) {
|
||||
player.sendMessage(ChatColor.GREEN + "Rollback finished successfully");
|
||||
player.sendMessage(ChatColor.GREEN + "Undid " + perform.rolledBack + " of " + changes + " changes");
|
||||
} else {
|
||||
player.sendMessage(ChatColor.GREEN + "Redo finished successfully");
|
||||
player.sendMessage(ChatColor.GREEN + "Redid " + perform.rolledBack + " of " + changes + " changes");
|
||||
}
|
||||
player.sendMessage(ChatColor.GREEN + "Took: " + (System.currentTimeMillis() - start) + "ms");
|
||||
}
|
||||
|
||||
@@ -182,7 +140,7 @@ public class Rollback implements Runnable
|
||||
int x, y, z;
|
||||
byte data;
|
||||
World world;
|
||||
|
||||
|
||||
Edit(int type, int replaced, byte data, int x, int y, int z, World world) {
|
||||
this.type = type;
|
||||
this.replaced = replaced;
|
||||
|
Reference in New Issue
Block a user