Implemented /plan m disable kickcount #389

This commit is contained in:
Rsl1122 2017-10-31 10:10:26 +02:00
parent 16ab5070be
commit 8f506740d6
4 changed files with 54 additions and 1 deletions

View File

@ -181,6 +181,7 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
if (!reloading) {
registerListeners();
}
PlanPlayerListener.setCountKicks(true);
registerTasks();
this.api = new API(this);

View File

@ -44,5 +44,6 @@ public class ManageCommand extends TreeCommand<Plan> {
commands.add(new ManageClearCommand(plugin));
commands.add(new ManageDumpCommand(plugin));
commands.add(new ManageSetupCommand(plugin));
commands.add(new ManageDisableCommand());
}
}

View File

@ -0,0 +1,45 @@
package main.java.com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.systems.listeners.PlanPlayerListener;
import main.java.com.djrapitops.plan.utilities.Check;
/**
* This manage SubCommand is used to disable some features of the plugin temporarily.
*
* @author Rsl1122
* @since 4.0.4
*/
public class ManageDisableCommand extends SubCommand {
/**
* Class Constructor.
*/
public ManageDisableCommand() {
super("disable",
CommandType.CONSOLE_WITH_ARGUMENTS,
Permissions.MANAGE.getPermission(),
"Used to disable some features of the Plugin temporarily",
"<feature>");
}
@Override
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
if (!Check.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse(this.getArguments()), sender)) {
return true;
}
switch (args[0].toLowerCase()) {
case "kickcount":
PlanPlayerListener.setCountKicks(false);
sender.sendMessage("§aDisabled Kick Counting temporarily until next plugin reload.");
break;
default:
sender.sendMessage("§eDefine a feature to disable! (currently supports only kickCount)");
}
return true;
}
}

View File

@ -26,6 +26,8 @@ import java.util.UUID;
*/
public class PlanPlayerListener implements Listener {
private static boolean countKicks = true;
private final Plan plugin;
private final DataCache cache;
@ -61,7 +63,7 @@ public class PlanPlayerListener implements Listener {
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerKick(PlayerKickEvent event) {
if (event.isCancelled()) {
if (!countKicks || event.isCancelled()) {
return;
}
UUID uuid = event.getPlayer().getUniqueId();
@ -132,4 +134,8 @@ public class PlanPlayerListener implements Listener {
plugin.addToProcessQueue(new FirstLeaveProcessor(uuid, time, messagesSent));
}
}
public static void setCountKicks(boolean value) {
countKicks = value;
}
}