mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-12 05:16:55 +00:00
reload command
This commit is contained in:
@@ -12,6 +12,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class TogglePvP extends JavaPlugin {
|
||||
|
||||
@@ -43,8 +44,8 @@ public final class TogglePvP extends JavaPlugin {
|
||||
getServer().getPluginManager().registerEvents(new WolfTargettingListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new WolfAttackPlayerListener(), this);
|
||||
|
||||
getCommand("pvp").setExecutor(new MainCommand());
|
||||
getCommand("pvp").setTabCompleter(new MainCommand());
|
||||
Objects.requireNonNull(getCommand("pvp")).setExecutor(new MainCommand());
|
||||
Objects.requireNonNull(getCommand("pvp")).setTabCompleter(new MainCommand());
|
||||
}
|
||||
|
||||
public void reloadPluginConfig() {
|
||||
|
||||
@@ -13,7 +13,7 @@ public class MainCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if (sender.hasPermission("togglepvp.command"))
|
||||
if (sender.hasPermission("togglepvp.command")) {
|
||||
if (args.length >= 1) {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "help":
|
||||
@@ -30,6 +30,9 @@ public class MainCommand implements TabExecutor {
|
||||
case "disable":
|
||||
PvpToggleCommand.disable(sender, args);
|
||||
break;
|
||||
case "reload":
|
||||
ReloadCommand.reload(sender);
|
||||
break;
|
||||
default:
|
||||
sender.sendMessage(PluginMessages.parseMessage(TogglePvP.getPlugin().getConfigCache().getNo_such_command()));
|
||||
break;
|
||||
@@ -37,6 +40,10 @@ public class MainCommand implements TabExecutor {
|
||||
} else {
|
||||
HelpCommand.help(sender, args);
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(PluginMessages.parseMessage(TogglePvP.getPlugin().getConfigCache().getNo_such_command()));
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -49,6 +56,9 @@ public class MainCommand implements TabExecutor {
|
||||
List<String> noPerm = new ArrayList<>();
|
||||
noPerm.add("help");
|
||||
|
||||
List<String> reloadPerm = new ArrayList<>();
|
||||
reloadPerm.add("reload");
|
||||
|
||||
List<String> togglePerm = new ArrayList<>();
|
||||
togglePerm.add("toggle");
|
||||
togglePerm.add("on");
|
||||
@@ -57,16 +67,22 @@ public class MainCommand implements TabExecutor {
|
||||
togglePerm.add("disable");
|
||||
|
||||
if (args.length == 1) {
|
||||
for (String noPermCmd : noPerm) {
|
||||
if (noPermCmd.startsWith(arg1))
|
||||
commands.add(noPermCmd);
|
||||
}
|
||||
if (sender.hasPermission("togglepvp.command.toggle")) {
|
||||
for (String noPermCmd : noPerm) {
|
||||
if (noPermCmd.startsWith(arg1))
|
||||
commands.add(noPermCmd);
|
||||
}
|
||||
for (String togglePermCmd : togglePerm) {
|
||||
if (togglePermCmd.startsWith(arg1))
|
||||
commands.add(togglePermCmd);
|
||||
}
|
||||
}
|
||||
if (sender.hasPermission("togglepvp.command.reload")) {
|
||||
for (String reloadPermCmd : reloadPerm) {
|
||||
if (reloadPermCmd.startsWith(arg1))
|
||||
commands.add(reloadPermCmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return commands;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package eu.endermite.togglepvp.commands;
|
||||
|
||||
import eu.endermite.togglepvp.TogglePvP;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class ReloadCommand {
|
||||
|
||||
public static void reload(CommandSender sender) {
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(TogglePvP.getPlugin(), () -> {
|
||||
if (!sender.hasPermission("togglepvp.command.reload")) {
|
||||
String message = TogglePvP.getPlugin().getConfigCache().getNo_permission();
|
||||
BaseComponent[] component = TextComponent.fromLegacyText(message);
|
||||
sender.spigot().sendMessage(component);
|
||||
return;
|
||||
}
|
||||
TogglePvP.getPlugin().reloadPluginConfig(sender);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,4 +13,7 @@ permissions:
|
||||
description: Allows usage of /pvp command
|
||||
togglepvp.command.toggle:
|
||||
default: true
|
||||
description: Allows usage of /pvp toggle/enable/disable command
|
||||
description: Allows usage of /pvp toggle/enable/disable command
|
||||
togglepvp.command.reload:
|
||||
default: op
|
||||
description: Allows usage of /pvp reload command
|
||||
Reference in New Issue
Block a user