add a reload command

This commit is contained in:
destro174 2021-08-22 10:50:39 +02:00
parent e8a1c330de
commit 6c35c704c3
5 changed files with 69 additions and 3 deletions

View File

@ -3,9 +3,11 @@ package com.alttd.afkdectector;
import com.alttd.afkdectector.afkplayer.AFKPlayer; import com.alttd.afkdectector.afkplayer.AFKPlayer;
import com.alttd.afkdectector.command.AFKCheckCommand; import com.alttd.afkdectector.command.AFKCheckCommand;
import com.alttd.afkdectector.command.AFKListCommand; import com.alttd.afkdectector.command.AFKListCommand;
import com.alttd.afkdectector.command.ReloadCommand;
import com.alttd.afkdectector.config.Config; import com.alttd.afkdectector.config.Config;
import com.alttd.afkdectector.config.MessagesConfig; import com.alttd.afkdectector.config.MessagesConfig;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -40,13 +42,13 @@ public class AFKDetector extends JavaPlugin implements Listener{
public void onEnable() { public void onEnable() {
try { try {
instance = this; instance = this;
Config.reload(); loadConfig(null);
MessagesConfig.reload();
settupAfkState(); settupAfkState();
getServer().getPluginManager().registerEvents(this, this); getServer().getPluginManager().registerEvents(this, this);
//getCommand("afk").setExecutor(new AFKCommand(this)); //getCommand("afk").setExecutor(new AFKCommand(this));
getCommand("afklist").setExecutor(new AFKListCommand(this)); getCommand("afklist").setExecutor(new AFKListCommand(this));
getCommand("afkcheck").setExecutor(new AFKCheckCommand(this)); getCommand("afkcheck").setExecutor(new AFKCheckCommand(this));
getCommand("reloadafkdetector").setExecutor(new ReloadCommand(this));
new AFKCheckTimer(this).init(); new AFKCheckTimer(this).init();
} catch (Throwable t) { } catch (Throwable t) {
getLogger().severe("An error has occured while loading AFKDetector"); getLogger().severe("An error has occured while loading AFKDetector");
@ -173,4 +175,12 @@ public class AFKDetector extends JavaPlugin implements Listener{
public static AFKDetector getInstance() { public static AFKDetector getInstance() {
return instance; return instance;
} }
public void loadConfig(CommandSender sender) {
Config.reload();
MessagesConfig.reload();
if(sender != null) {
sender.sendMessage("Configuration reloaded");
}
}
} }

View File

@ -0,0 +1,36 @@
package com.alttd.afkdectector.command;
import com.alttd.afkdectector.AFKDetector;
import com.alttd.afkdectector.afkplayer.AFKPlayer;
import com.alttd.afkdectector.config.Config;
import com.alttd.afkdectector.config.Messages;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.Template;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import java.util.ArrayList;
import java.util.List;
public class ReloadCommand implements CommandExecutor, TabCompleter {
private AFKDetector plugin;
public ReloadCommand(AFKDetector plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
AFKDetector.getInstance().loadConfig(sender);
return true;
}
@Override
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
return null;
}
}

View File

@ -23,10 +23,17 @@ import java.util.*;
abstract class AbstractConfig { abstract class AbstractConfig {
File file; File file;
YamlConfiguration yaml; YamlConfiguration yaml;
File configPath;
AbstractConfig(String filename) { AbstractConfig(String filename) {
this.file = new File(AFKDetector.getInstance().getDataFolder(), filename); this.configPath = new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + AFKDetector.getInstance().getName());
this.file = new File(configPath, filename);
this.yaml = new YamlConfiguration(); this.yaml = new YamlConfiguration();
if (!this.file.getParentFile().exists()) {
if(!this.file.getParentFile().mkdirs()) {
return;
}
}
try { try {
yaml.load(file); yaml.load(file);
} catch (IOException ignore) { } catch (IOException ignore) {

View File

@ -17,6 +17,11 @@ commands:
permission: afkdetector.afkcheck permission: afkdetector.afkcheck
permission-message: You do not have permission! permission-message: You do not have permission!
usage: /afkcheck <target> usage: /afkcheck <target>
reloadafkdetector:
description: Reloads the plugin config
permission: afkdetector.reload
permission-message: You do not have permission!
usage: /afkdetectorreload
permissions: permissions:
afkdetector.admin: afkdetector.admin:
@ -27,11 +32,15 @@ permissions:
afkdetector.afklist: true afkdetector.afklist: true
afkdetector.afkcheck: true afkdetector.afkcheck: true
afkdetector.notify: true afkdetector.notify: true
afkdetector.reload: true
afkdetector.bypass: afkdetector.bypass:
description: Bypass the AFKplugin. description: Bypass the AFKplugin.
default: op default: op
children: children:
afkdetector.kickexempt: true afkdetector.kickexempt: true
afkdetector.reload:
description: Allows reloading the afkdetector plugin config.
default: op
afkdetector.kickexempt: afkdetector.kickexempt:
description: Doesn't kick you automatically for AFK. description: Doesn't kick you automatically for AFK.
default: op default: op

4
upload.sh Executable file
View File

@ -0,0 +1,4 @@
mvn package
#scp ./target/AFKDetector.jar sid@lyra:/home/sid/share/updates/all/plugins/AFKDetector.jar
scp ./target/AFKDetector.jar sid@leo:/home/sid/servers/meadowTest/plugins/AFKDetector.jar