Implement ConsecutiveExecutor
This commit is contained in:
parent
44d14001e1
commit
2b71476cfe
@ -27,6 +27,7 @@ import me.lucko.luckperms.api.Logger;
|
|||||||
import me.lucko.luckperms.api.LuckPermsApi;
|
import me.lucko.luckperms.api.LuckPermsApi;
|
||||||
import me.lucko.luckperms.api.implementation.ApiProvider;
|
import me.lucko.luckperms.api.implementation.ApiProvider;
|
||||||
import me.lucko.luckperms.api.vault.VaultHook;
|
import me.lucko.luckperms.api.vault.VaultHook;
|
||||||
|
import me.lucko.luckperms.commands.ConsecutiveExecutor;
|
||||||
import me.lucko.luckperms.commands.Sender;
|
import me.lucko.luckperms.commands.Sender;
|
||||||
import me.lucko.luckperms.constants.Message;
|
import me.lucko.luckperms.constants.Message;
|
||||||
import me.lucko.luckperms.core.LPConfiguration;
|
import me.lucko.luckperms.core.LPConfiguration;
|
||||||
@ -63,6 +64,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
private ApiProvider apiProvider;
|
private ApiProvider apiProvider;
|
||||||
private Logger log;
|
private Logger log;
|
||||||
private Importer importer;
|
private Importer importer;
|
||||||
|
private ConsecutiveExecutor consecutiveExecutor;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@ -91,6 +93,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
groupManager = new GroupManager(this);
|
groupManager = new GroupManager(this);
|
||||||
trackManager = new TrackManager();
|
trackManager = new TrackManager();
|
||||||
importer = new Importer(commandManager);
|
importer = new Importer(commandManager);
|
||||||
|
consecutiveExecutor = new ConsecutiveExecutor(commandManager);
|
||||||
|
|
||||||
int mins = getConfiguration().getSyncTime();
|
int mins = getConfiguration().getSyncTime();
|
||||||
if (mins > 0) {
|
if (mins > 0) {
|
||||||
@ -100,6 +103,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
|
|
||||||
getServer().getScheduler().runTaskTimer(this, BukkitSenderFactory.get(), 1L, 1L);
|
getServer().getScheduler().runTaskTimer(this, BukkitSenderFactory.get(), 1L, 1L);
|
||||||
getServer().getScheduler().runTaskTimerAsynchronously(this, new ExpireTemporaryTask(this), 60L, 60L);
|
getServer().getScheduler().runTaskTimerAsynchronously(this, new ExpireTemporaryTask(this), 60L, 60L);
|
||||||
|
getServer().getScheduler().runTaskTimerAsynchronously(this, consecutiveExecutor, 20L, 20L);
|
||||||
|
|
||||||
// Provide vault support
|
// Provide vault support
|
||||||
getLog().info("Attempting to hook into Vault...");
|
getLog().info("Attempting to hook into Vault...");
|
||||||
|
@ -26,6 +26,7 @@ import lombok.Getter;
|
|||||||
import me.lucko.luckperms.api.Logger;
|
import me.lucko.luckperms.api.Logger;
|
||||||
import me.lucko.luckperms.api.implementation.ApiProvider;
|
import me.lucko.luckperms.api.implementation.ApiProvider;
|
||||||
import me.lucko.luckperms.commands.CommandManager;
|
import me.lucko.luckperms.commands.CommandManager;
|
||||||
|
import me.lucko.luckperms.commands.ConsecutiveExecutor;
|
||||||
import me.lucko.luckperms.commands.Sender;
|
import me.lucko.luckperms.commands.Sender;
|
||||||
import me.lucko.luckperms.constants.Message;
|
import me.lucko.luckperms.constants.Message;
|
||||||
import me.lucko.luckperms.core.LPConfiguration;
|
import me.lucko.luckperms.core.LPConfiguration;
|
||||||
@ -64,6 +65,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
|||||||
private ApiProvider apiProvider;
|
private ApiProvider apiProvider;
|
||||||
private Logger log;
|
private Logger log;
|
||||||
private Importer importer;
|
private Importer importer;
|
||||||
|
private ConsecutiveExecutor consecutiveExecutor;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@ -91,6 +93,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
|||||||
groupManager = new GroupManager(this);
|
groupManager = new GroupManager(this);
|
||||||
trackManager = new TrackManager();
|
trackManager = new TrackManager();
|
||||||
importer = new Importer(commandManager);
|
importer = new Importer(commandManager);
|
||||||
|
consecutiveExecutor = new ConsecutiveExecutor(commandManager);
|
||||||
|
|
||||||
int mins = getConfiguration().getSyncTime();
|
int mins = getConfiguration().getSyncTime();
|
||||||
if (mins > 0) {
|
if (mins > 0) {
|
||||||
@ -100,6 +103,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
|||||||
// 20 times per second (once per "tick")
|
// 20 times per second (once per "tick")
|
||||||
getProxy().getScheduler().schedule(this, BungeeSenderFactory.get(), 50L, 50L, TimeUnit.MILLISECONDS);
|
getProxy().getScheduler().schedule(this, BungeeSenderFactory.get(), 50L, 50L, TimeUnit.MILLISECONDS);
|
||||||
getProxy().getScheduler().schedule(this, new ExpireTemporaryTask(this), 3L, 3L, TimeUnit.SECONDS);
|
getProxy().getScheduler().schedule(this, new ExpireTemporaryTask(this), 3L, 3L, TimeUnit.SECONDS);
|
||||||
|
getProxy().getScheduler().schedule(this, consecutiveExecutor, 1L, 1L, TimeUnit.SECONDS);
|
||||||
|
|
||||||
getLog().info("Registering API...");
|
getLog().info("Registering API...");
|
||||||
apiProvider = new ApiProvider(this);
|
apiProvider = new ApiProvider(this);
|
||||||
|
@ -24,6 +24,7 @@ package me.lucko.luckperms;
|
|||||||
|
|
||||||
import me.lucko.luckperms.api.Logger;
|
import me.lucko.luckperms.api.Logger;
|
||||||
import me.lucko.luckperms.api.implementation.ApiProvider;
|
import me.lucko.luckperms.api.implementation.ApiProvider;
|
||||||
|
import me.lucko.luckperms.commands.ConsecutiveExecutor;
|
||||||
import me.lucko.luckperms.commands.Sender;
|
import me.lucko.luckperms.commands.Sender;
|
||||||
import me.lucko.luckperms.constants.Message;
|
import me.lucko.luckperms.constants.Message;
|
||||||
import me.lucko.luckperms.core.LPConfiguration;
|
import me.lucko.luckperms.core.LPConfiguration;
|
||||||
@ -57,6 +58,7 @@ public interface LuckPermsPlugin {
|
|||||||
UuidCache getUuidCache();
|
UuidCache getUuidCache();
|
||||||
ApiProvider getApiProvider();
|
ApiProvider getApiProvider();
|
||||||
Importer getImporter();
|
Importer getImporter();
|
||||||
|
ConsecutiveExecutor getConsecutiveExecutor();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the version of the plugin
|
* @return the version of the plugin
|
||||||
|
@ -33,10 +33,7 @@ import me.lucko.luckperms.commands.group.GroupMainCommand;
|
|||||||
import me.lucko.luckperms.commands.group.ListGroups;
|
import me.lucko.luckperms.commands.group.ListGroups;
|
||||||
import me.lucko.luckperms.commands.log.LogMainCommand;
|
import me.lucko.luckperms.commands.log.LogMainCommand;
|
||||||
import me.lucko.luckperms.commands.migration.MigrationMainCommand;
|
import me.lucko.luckperms.commands.migration.MigrationMainCommand;
|
||||||
import me.lucko.luckperms.commands.misc.DebugCommand;
|
import me.lucko.luckperms.commands.misc.*;
|
||||||
import me.lucko.luckperms.commands.misc.ImportCommand;
|
|
||||||
import me.lucko.luckperms.commands.misc.InfoCommand;
|
|
||||||
import me.lucko.luckperms.commands.misc.SyncCommand;
|
|
||||||
import me.lucko.luckperms.commands.track.CreateTrack;
|
import me.lucko.luckperms.commands.track.CreateTrack;
|
||||||
import me.lucko.luckperms.commands.track.DeleteTrack;
|
import me.lucko.luckperms.commands.track.DeleteTrack;
|
||||||
import me.lucko.luckperms.commands.track.ListTracks;
|
import me.lucko.luckperms.commands.track.ListTracks;
|
||||||
@ -64,6 +61,7 @@ public class CommandManager {
|
|||||||
.add(new InfoCommand())
|
.add(new InfoCommand())
|
||||||
.add(new DebugCommand())
|
.add(new DebugCommand())
|
||||||
.add(new ImportCommand())
|
.add(new ImportCommand())
|
||||||
|
.add(new QueueCommand())
|
||||||
.add(new MigrationMainCommand())
|
.add(new MigrationMainCommand())
|
||||||
.add(new CreateGroup())
|
.add(new CreateGroup())
|
||||||
.add(new DeleteGroup())
|
.add(new DeleteGroup())
|
||||||
|
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.commands;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes commands consecutively
|
||||||
|
*/
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ConsecutiveExecutor implements Runnable {
|
||||||
|
private final CommandManager manager;
|
||||||
|
|
||||||
|
private final List<QueuedCommand> commands = new ArrayList<>();
|
||||||
|
|
||||||
|
public void queueCommand(QueuedCommand command) {
|
||||||
|
synchronized (commands) {
|
||||||
|
commands.add(command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
final List<QueuedCommand> toExecute = new ArrayList<>();
|
||||||
|
synchronized (commands) {
|
||||||
|
toExecute.addAll(commands);
|
||||||
|
commands.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toExecute.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (QueuedCommand command : toExecute) {
|
||||||
|
manager.onCommand(command.getSender(), "perms", command.getArgs());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class QueuedCommand {
|
||||||
|
private final Sender sender;
|
||||||
|
private final List<String> args;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.commands.misc;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.LuckPermsPlugin;
|
||||||
|
import me.lucko.luckperms.commands.CommandResult;
|
||||||
|
import me.lucko.luckperms.commands.ConsecutiveExecutor;
|
||||||
|
import me.lucko.luckperms.commands.Sender;
|
||||||
|
import me.lucko.luckperms.commands.SingleMainCommand;
|
||||||
|
import me.lucko.luckperms.constants.Constants;
|
||||||
|
import me.lucko.luckperms.constants.Permission;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class QueueCommand extends SingleMainCommand {
|
||||||
|
public QueueCommand() {
|
||||||
|
super("QueueCommand", "/%s queuecommand <command args...>", 1, Permission.MIGRATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
|
||||||
|
if (args.get(0).equalsIgnoreCase(getName())) {
|
||||||
|
// Prevent infinite loops
|
||||||
|
return CommandResult.FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getConsecutiveExecutor().queueCommand(new ConsecutiveExecutor.QueuedCommand(sender, args));
|
||||||
|
return CommandResult.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isAuthorized(Sender sender) {
|
||||||
|
return sender.getUuid().equals(Constants.getConsoleUUID());
|
||||||
|
}
|
||||||
|
}
|
@ -38,7 +38,7 @@ import java.util.*;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a list of commands sequentially in a single thread.
|
* Class to handle import operations
|
||||||
*/
|
*/
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class Importer {
|
public class Importer {
|
||||||
|
@ -26,6 +26,7 @@ import com.google.inject.Inject;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.lucko.luckperms.api.LuckPermsApi;
|
import me.lucko.luckperms.api.LuckPermsApi;
|
||||||
import me.lucko.luckperms.api.implementation.ApiProvider;
|
import me.lucko.luckperms.api.implementation.ApiProvider;
|
||||||
|
import me.lucko.luckperms.commands.ConsecutiveExecutor;
|
||||||
import me.lucko.luckperms.commands.Sender;
|
import me.lucko.luckperms.commands.Sender;
|
||||||
import me.lucko.luckperms.constants.Message;
|
import me.lucko.luckperms.constants.Message;
|
||||||
import me.lucko.luckperms.constants.Permission;
|
import me.lucko.luckperms.constants.Permission;
|
||||||
@ -90,6 +91,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
private ApiProvider apiProvider;
|
private ApiProvider apiProvider;
|
||||||
private me.lucko.luckperms.api.Logger log;
|
private me.lucko.luckperms.api.Logger log;
|
||||||
private Importer importer;
|
private Importer importer;
|
||||||
|
private ConsecutiveExecutor consecutiveExecutor;
|
||||||
|
|
||||||
@Listener
|
@Listener
|
||||||
public void onEnable(GamePreInitializationEvent event) {
|
public void onEnable(GamePreInitializationEvent event) {
|
||||||
@ -115,6 +117,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
groupManager = new GroupManager(this);
|
groupManager = new GroupManager(this);
|
||||||
trackManager = new TrackManager();
|
trackManager = new TrackManager();
|
||||||
importer = new Importer(commandManager);
|
importer = new Importer(commandManager);
|
||||||
|
consecutiveExecutor = new ConsecutiveExecutor(commandManager);
|
||||||
|
|
||||||
getLog().info("Registering API...");
|
getLog().info("Registering API...");
|
||||||
apiProvider = new ApiProvider(this);
|
apiProvider = new ApiProvider(this);
|
||||||
@ -132,6 +135,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
|
|
||||||
scheduler.createTaskBuilder().intervalTicks(1L).execute(SpongeSenderFactory.get()).submit(this);
|
scheduler.createTaskBuilder().intervalTicks(1L).execute(SpongeSenderFactory.get()).submit(this);
|
||||||
scheduler.createTaskBuilder().async().intervalTicks(60L).execute(new ExpireTemporaryTask(this)).submit(this);
|
scheduler.createTaskBuilder().async().intervalTicks(60L).execute(new ExpireTemporaryTask(this)).submit(this);
|
||||||
|
scheduler.createTaskBuilder().async().intervalTicks(20L).execute(consecutiveExecutor).submit(this);
|
||||||
|
|
||||||
getLog().info("Successfully loaded.");
|
getLog().info("Successfully loaded.");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user