mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-12 06:26:57 +00:00
reload command
This commit is contained in:
@@ -4,6 +4,10 @@ import eu.endermite.commandwhitelist.command.MainCommand;
|
||||
import eu.endermite.commandwhitelist.config.ConfigCache;
|
||||
import eu.endermite.commandwhitelist.listeners.PlayerCommandPreProcess;
|
||||
import eu.endermite.commandwhitelist.listeners.PlayerCommandSend;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class CommandWhitelist extends JavaPlugin {
|
||||
@@ -26,13 +30,22 @@ public class CommandWhitelist extends JavaPlugin {
|
||||
|
||||
public void reloadPluginConfig() {
|
||||
saveDefaultConfig();
|
||||
reloadConfig();
|
||||
configCache = new ConfigCache();
|
||||
}
|
||||
|
||||
public void reloadPluginConfig(CommandSender sender) {
|
||||
getServer().getScheduler().runTaskAsynchronously(this, () -> {
|
||||
// Don't ask why it's called twice, it somehow breaks if it's called only once.
|
||||
reloadPluginConfig();
|
||||
reloadPluginConfig();
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
p.updateCommands();
|
||||
}
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getConfigReloaded()));
|
||||
});
|
||||
}
|
||||
|
||||
public static CommandWhitelist getPlugin() {return commandWhitelist;}
|
||||
public static ConfigCache getConfigCache() {return configCache;}
|
||||
|
||||
public static <T> T TODO(final String reason) {
|
||||
throw new RuntimeException(reason);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,7 @@ public class MainCommand implements TabExecutor {
|
||||
if (args.length > 0) {
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
if (sender.hasPermission("commandwhitelist.reload")) {
|
||||
CommandWhitelist.getPlugin().reloadPluginConfig();
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getConfigReloaded()));
|
||||
|
||||
CommandWhitelist.getPlugin().reloadPluginConfig(sender);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().getPrefix() + CommandWhitelist.getConfigCache().getNoPermission()));
|
||||
}
|
||||
|
||||
@@ -9,13 +9,12 @@ import java.util.Set;
|
||||
|
||||
public class ConfigCache {
|
||||
|
||||
private Configuration config = CommandWhitelist.getPlugin().getConfig();
|
||||
private HashMap<String, List<String>> permList = new HashMap<>();
|
||||
private String prefix, commandDenied, noPermission, noSubCommand, configReloaded;
|
||||
|
||||
public ConfigCache() {
|
||||
|
||||
CommandWhitelist.getPlugin().reloadConfig();
|
||||
Configuration config = CommandWhitelist.getPlugin().getConfig();
|
||||
|
||||
prefix = config.getString("messages.prefix");
|
||||
commandDenied = config.getString("messages.command-denied");
|
||||
|
||||
Reference in New Issue
Block a user