forked from LogBlock/LogBlock
API: Added option to run commands sync or async with the caller thread
This commit is contained in:
@@ -202,7 +202,7 @@ public class CommandsHandler implements CommandExecutor
|
|||||||
} else if (args[0].equalsIgnoreCase("savequeue")) {
|
} else if (args[0].equalsIgnoreCase("savequeue")) {
|
||||||
if (logblock.hasPermission(sender, "logblock.rollback"))
|
if (logblock.hasPermission(sender, "logblock.rollback"))
|
||||||
try {
|
try {
|
||||||
new CommandSaveQueue(sender, null);
|
new CommandSaveQueue(sender, null, true);
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
sender.sendMessage(ChatColor.RED + ex.getMessage());
|
sender.sendMessage(ChatColor.RED + ex.getMessage());
|
||||||
}
|
}
|
||||||
@@ -218,7 +218,7 @@ public class CommandsHandler implements CommandExecutor
|
|||||||
params.order = Order.DESC;
|
params.order = Order.DESC;
|
||||||
params.sum = SummarizationMode.NONE;
|
params.sum = SummarizationMode.NONE;
|
||||||
params.bct = BlockChangeType.ALL;
|
params.bct = BlockChangeType.ALL;
|
||||||
new CommandRollback(sender, params);
|
new CommandRollback(sender, params, true);
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
sender.sendMessage(ChatColor.RED + ex.getMessage());
|
sender.sendMessage(ChatColor.RED + ex.getMessage());
|
||||||
}
|
}
|
||||||
@@ -234,7 +234,7 @@ public class CommandsHandler implements CommandExecutor
|
|||||||
params.order = Order.ASC;
|
params.order = Order.ASC;
|
||||||
params.sum = SummarizationMode.NONE;
|
params.sum = SummarizationMode.NONE;
|
||||||
params.bct = BlockChangeType.ALL;
|
params.bct = BlockChangeType.ALL;
|
||||||
new CommandRedo(sender, params);
|
new CommandRedo(sender, params, true);
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
sender.sendMessage(ChatColor.RED + ex.getMessage());
|
sender.sendMessage(ChatColor.RED + ex.getMessage());
|
||||||
}
|
}
|
||||||
@@ -249,7 +249,7 @@ public class CommandsHandler implements CommandExecutor
|
|||||||
params.setPlayer(player.getName());
|
params.setPlayer(player.getName());
|
||||||
params.sum = SummarizationMode.TYPES;
|
params.sum = SummarizationMode.TYPES;
|
||||||
params.world = player.getWorld();
|
params.world = player.getWorld();
|
||||||
new CommandLookup(sender, params);
|
new CommandLookup(sender, params, true);
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
sender.sendMessage(ChatColor.RED + ex.getMessage());
|
sender.sendMessage(ChatColor.RED + ex.getMessage());
|
||||||
}
|
}
|
||||||
@@ -264,7 +264,7 @@ public class CommandsHandler implements CommandExecutor
|
|||||||
params.limit = -1;
|
params.limit = -1;
|
||||||
params.bct = BlockChangeType.ALL;
|
params.bct = BlockChangeType.ALL;
|
||||||
params.sum = SummarizationMode.NONE;
|
params.sum = SummarizationMode.NONE;
|
||||||
new CommandWriteLogFile(sender, params);
|
new CommandWriteLogFile(sender, params, true);
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
sender.sendMessage(ChatColor.RED + ex.getMessage());
|
sender.sendMessage(ChatColor.RED + ex.getMessage());
|
||||||
}
|
}
|
||||||
@@ -276,7 +276,7 @@ public class CommandsHandler implements CommandExecutor
|
|||||||
final QueryParams params = new QueryParams(logblock, sender, ArgsToList(args, 1));
|
final QueryParams params = new QueryParams(logblock, sender, ArgsToList(args, 1));
|
||||||
params.bct = BlockChangeType.ALL;
|
params.bct = BlockChangeType.ALL;
|
||||||
params.limit = -1;
|
params.limit = -1;
|
||||||
new CommandClearLog(sender, params);
|
new CommandClearLog(sender, params, true);
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
sender.sendMessage(ChatColor.RED + ex.getMessage());
|
sender.sendMessage(ChatColor.RED + ex.getMessage());
|
||||||
}
|
}
|
||||||
@@ -286,7 +286,7 @@ public class CommandsHandler implements CommandExecutor
|
|||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
if (logblock.hasPermission(sender, "logblock.tp"))
|
if (logblock.hasPermission(sender, "logblock.tp"))
|
||||||
try {
|
try {
|
||||||
new CommandTeleport(sender, new QueryParams(logblock, sender, ArgsToList(args, 1)));
|
new CommandTeleport(sender, new QueryParams(logblock, sender, ArgsToList(args, 1)), true);
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
sender.sendMessage(ChatColor.RED + ex.getMessage());
|
sender.sendMessage(ChatColor.RED + ex.getMessage());
|
||||||
}
|
}
|
||||||
@@ -300,7 +300,7 @@ public class CommandsHandler implements CommandExecutor
|
|||||||
final List<String> argsList = new ArrayList<String>(Arrays.asList(args));
|
final List<String> argsList = new ArrayList<String>(Arrays.asList(args));
|
||||||
if (command.equals("lookup"))
|
if (command.equals("lookup"))
|
||||||
argsList.remove(0);
|
argsList.remove(0);
|
||||||
new CommandLookup(sender, new QueryParams(logblock, sender, argsList));
|
new CommandLookup(sender, new QueryParams(logblock, sender, argsList), true);
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
sender.sendMessage(ChatColor.RED + ex.getMessage());
|
sender.sendMessage(ChatColor.RED + ex.getMessage());
|
||||||
}
|
}
|
||||||
@@ -320,13 +320,16 @@ public class CommandsHandler implements CommandExecutor
|
|||||||
protected Statement state = null;
|
protected Statement state = null;
|
||||||
protected ResultSet rs = null;
|
protected ResultSet rs = null;
|
||||||
|
|
||||||
protected LBCommand(CommandSender sender, QueryParams params) throws Exception {
|
protected LBCommand(CommandSender sender, QueryParams params, boolean async) throws Exception {
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.params = params;
|
this.params = params;
|
||||||
conn = logblock.getConnection();
|
conn = logblock.getConnection();
|
||||||
state = conn.createStatement();
|
state = conn.createStatement();
|
||||||
if (scheduler.scheduleAsyncDelayedTask(logblock, this) == -1)
|
if (async) {
|
||||||
throw new Exception("Failed to schedule the command");
|
if (scheduler.scheduleAsyncDelayedTask(logblock, this) == -1)
|
||||||
|
throw new Exception("Failed to schedule the command");
|
||||||
|
} else
|
||||||
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -346,8 +349,8 @@ public class CommandsHandler implements CommandExecutor
|
|||||||
|
|
||||||
public class CommandLookup extends LBCommand
|
public class CommandLookup extends LBCommand
|
||||||
{
|
{
|
||||||
public CommandLookup(CommandSender sender, QueryParams params) throws Exception {
|
public CommandLookup(CommandSender sender, QueryParams params, boolean async) throws Exception {
|
||||||
super(sender, params);
|
super(sender, params, async);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -378,8 +381,8 @@ public class CommandsHandler implements CommandExecutor
|
|||||||
|
|
||||||
public class CommandWriteLogFile extends LBCommand
|
public class CommandWriteLogFile extends LBCommand
|
||||||
{
|
{
|
||||||
CommandWriteLogFile(CommandSender sender, QueryParams params) throws Exception {
|
CommandWriteLogFile(CommandSender sender, QueryParams params, boolean async) throws Exception {
|
||||||
super(sender, params);
|
super(sender, params, async);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -413,8 +416,8 @@ public class CommandsHandler implements CommandExecutor
|
|||||||
|
|
||||||
public class CommandSaveQueue extends LBCommand
|
public class CommandSaveQueue extends LBCommand
|
||||||
{
|
{
|
||||||
public CommandSaveQueue(CommandSender sender, QueryParams params) throws Exception {
|
public CommandSaveQueue(CommandSender sender, QueryParams params, boolean async) throws Exception {
|
||||||
super(sender, params);
|
super(sender, params, async);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -429,8 +432,8 @@ public class CommandsHandler implements CommandExecutor
|
|||||||
|
|
||||||
public class CommandTeleport extends LBCommand
|
public class CommandTeleport extends LBCommand
|
||||||
{
|
{
|
||||||
public CommandTeleport(CommandSender sender, QueryParams params) throws Exception {
|
public CommandTeleport(CommandSender sender, QueryParams params, boolean async) throws Exception {
|
||||||
super(sender, params);
|
super(sender, params, async);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -455,8 +458,8 @@ public class CommandsHandler implements CommandExecutor
|
|||||||
|
|
||||||
public class CommandRollback extends LBCommand
|
public class CommandRollback extends LBCommand
|
||||||
{
|
{
|
||||||
public CommandRollback(CommandSender sender, QueryParams params) throws Exception {
|
public CommandRollback(CommandSender sender, QueryParams params, boolean async) throws Exception {
|
||||||
super(sender, params);
|
super(sender, params, async);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -464,7 +467,7 @@ public class CommandsHandler implements CommandExecutor
|
|||||||
try {
|
try {
|
||||||
if (logblock.getConsumer().getQueueSize() > 50)
|
if (logblock.getConsumer().getQueueSize() > 50)
|
||||||
try {
|
try {
|
||||||
new CommandSaveQueue(sender, null);
|
new CommandSaveQueue(sender, null, true);
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
sender.sendMessage(ChatColor.RED + ex.getMessage());
|
sender.sendMessage(ChatColor.RED + ex.getMessage());
|
||||||
}
|
}
|
||||||
@@ -499,8 +502,8 @@ public class CommandsHandler implements CommandExecutor
|
|||||||
|
|
||||||
public class CommandRedo extends LBCommand
|
public class CommandRedo extends LBCommand
|
||||||
{
|
{
|
||||||
public CommandRedo(CommandSender sender, QueryParams params) throws Exception {
|
public CommandRedo(CommandSender sender, QueryParams params, boolean async) throws Exception {
|
||||||
super(sender, params);
|
super(sender, params, async);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -537,8 +540,8 @@ public class CommandsHandler implements CommandExecutor
|
|||||||
|
|
||||||
public class CommandClearLog extends LBCommand
|
public class CommandClearLog extends LBCommand
|
||||||
{
|
{
|
||||||
public CommandClearLog(CommandSender sender, QueryParams params) throws Exception {
|
public CommandClearLog(CommandSender sender, QueryParams params, boolean async) throws Exception {
|
||||||
super(sender, params);
|
super(sender, params, async);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -43,15 +43,15 @@ class LBToolListener extends PlayerListener
|
|||||||
params.setLocation(event.getClickedBlock().getLocation());
|
params.setLocation(event.getClickedBlock().getLocation());
|
||||||
try {
|
try {
|
||||||
if (mode == ToolMode.ROLLBACK)
|
if (mode == ToolMode.ROLLBACK)
|
||||||
handler.new CommandRollback(player, params);
|
handler.new CommandRollback(player, params, true);
|
||||||
else if (mode == ToolMode.REDO)
|
else if (mode == ToolMode.REDO)
|
||||||
handler.new CommandRedo(player, params);
|
handler.new CommandRedo(player, params, true);
|
||||||
else if (mode == ToolMode.CLEARLOG)
|
else if (mode == ToolMode.CLEARLOG)
|
||||||
handler.new CommandClearLog(player, params);
|
handler.new CommandClearLog(player, params, true);
|
||||||
else if (mode == ToolMode.WRITELOGFILE)
|
else if (mode == ToolMode.WRITELOGFILE)
|
||||||
handler.new CommandWriteLogFile(player, params);
|
handler.new CommandWriteLogFile(player, params, true);
|
||||||
else
|
else
|
||||||
handler.new CommandLookup(player, params);
|
handler.new CommandLookup(player, params, true);
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
player.sendMessage(ChatColor.RED + ex.getMessage());
|
player.sendMessage(ChatColor.RED + ex.getMessage());
|
||||||
}
|
}
|
||||||
|
@@ -98,7 +98,7 @@ public class LogBlock extends JavaPlugin
|
|||||||
if (config.tables.containsKey(world.getName().hashCode())) {
|
if (config.tables.containsKey(world.getName().hashCode())) {
|
||||||
params.world = world;
|
params.world = world;
|
||||||
try {
|
try {
|
||||||
commandsHandler.new CommandClearLog(new ConsoleCommandSender(getServer()), params);
|
commandsHandler.new CommandClearLog(new ConsoleCommandSender(getServer()), params, true);
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
log.severe("Failed to schedule ClearLog: " + ex.getMessage());
|
log.severe("Failed to schedule ClearLog: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
|
@@ -100,7 +100,9 @@ public class QueryParams implements Cloneable
|
|||||||
title.append("destructions ");
|
title.append("destructions ");
|
||||||
else
|
else
|
||||||
title.append("changes ");
|
title.append("changes ");
|
||||||
if (!players.isEmpty()) {
|
if (players.size() > 10)
|
||||||
|
title.append("from many players ");
|
||||||
|
else if (!players.isEmpty()) {
|
||||||
title.append("from player ");
|
title.append("from player ");
|
||||||
for (int i = 0; i < players.size(); i++)
|
for (int i = 0; i < players.size(); i++)
|
||||||
title.append(players.get(i) + ", ");
|
title.append(players.get(i) + ", ");
|
||||||
|
Reference in New Issue
Block a user