diff --git a/src/main/java/com/alttd/afkdectector/AFKDetector.java b/src/main/java/com/alttd/afkdectector/AFKDetector.java index 3cd6bdc..3a539eb 100755 --- a/src/main/java/com/alttd/afkdectector/AFKDetector.java +++ b/src/main/java/com/alttd/afkdectector/AFKDetector.java @@ -3,9 +3,11 @@ package com.alttd.afkdectector; import com.alttd.afkdectector.afkplayer.AFKPlayer; import com.alttd.afkdectector.command.AFKCheckCommand; import com.alttd.afkdectector.command.AFKListCommand; +import com.alttd.afkdectector.command.ReloadCommand; import com.alttd.afkdectector.config.Config; import com.alttd.afkdectector.config.MessagesConfig; import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -40,13 +42,13 @@ public class AFKDetector extends JavaPlugin implements Listener{ public void onEnable() { try { instance = this; - Config.reload(); - MessagesConfig.reload(); + loadConfig(null); settupAfkState(); getServer().getPluginManager().registerEvents(this, this); //getCommand("afk").setExecutor(new AFKCommand(this)); getCommand("afklist").setExecutor(new AFKListCommand(this)); getCommand("afkcheck").setExecutor(new AFKCheckCommand(this)); + getCommand("reloadafkdetector").setExecutor(new ReloadCommand(this)); new AFKCheckTimer(this).init(); } catch (Throwable t) { getLogger().severe("An error has occured while loading AFKDetector"); @@ -173,4 +175,12 @@ public class AFKDetector extends JavaPlugin implements Listener{ public static AFKDetector getInstance() { return instance; } + + public void loadConfig(CommandSender sender) { + Config.reload(); + MessagesConfig.reload(); + if(sender != null) { + sender.sendMessage("Configuration reloaded"); + } + } } diff --git a/src/main/java/com/alttd/afkdectector/command/ReloadCommand.java b/src/main/java/com/alttd/afkdectector/command/ReloadCommand.java new file mode 100755 index 0000000..338cdcf --- /dev/null +++ b/src/main/java/com/alttd/afkdectector/command/ReloadCommand.java @@ -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 onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) { + return null; + } +} \ No newline at end of file diff --git a/src/main/java/com/alttd/afkdectector/config/AbstractConfig.java b/src/main/java/com/alttd/afkdectector/config/AbstractConfig.java index 8acad15..fde4450 100644 --- a/src/main/java/com/alttd/afkdectector/config/AbstractConfig.java +++ b/src/main/java/com/alttd/afkdectector/config/AbstractConfig.java @@ -23,10 +23,17 @@ import java.util.*; abstract class AbstractConfig { File file; YamlConfiguration yaml; + File configPath; 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(); + if (!this.file.getParentFile().exists()) { + if(!this.file.getParentFile().mkdirs()) { + return; + } + } try { yaml.load(file); } catch (IOException ignore) { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index fc5d0ee..a2611dc 100755 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -17,6 +17,11 @@ commands: permission: afkdetector.afkcheck permission-message: You do not have permission! usage: /afkcheck + reloadafkdetector: + description: Reloads the plugin config + permission: afkdetector.reload + permission-message: You do not have permission! + usage: /afkdetectorreload permissions: afkdetector.admin: @@ -27,11 +32,15 @@ permissions: afkdetector.afklist: true afkdetector.afkcheck: true afkdetector.notify: true + afkdetector.reload: true afkdetector.bypass: description: Bypass the AFKplugin. default: op children: afkdetector.kickexempt: true + afkdetector.reload: + description: Allows reloading the afkdetector plugin config. + default: op afkdetector.kickexempt: description: Doesn't kick you automatically for AFK. default: op diff --git a/upload.sh b/upload.sh new file mode 100755 index 0000000..04d3016 --- /dev/null +++ b/upload.sh @@ -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 \ No newline at end of file