Added reload command
This commit is contained in:
parent
1663498080
commit
54db863783
|
|
@ -1,6 +1,8 @@
|
|||
package com.alttd.playerutils;
|
||||
|
||||
import com.alttd.playerutils.commands.PlayerUtilsCommand;
|
||||
import com.alttd.playerutils.config.Config;
|
||||
import com.alttd.playerutils.config.Messages;
|
||||
import com.alttd.playerutils.event_listeners.XpBottleEvent;
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
|
@ -27,4 +29,9 @@ public final class PlayerUtils extends JavaPlugin {
|
|||
private void registerEvents() {
|
||||
getServer().getPluginManager().registerEvents(new XpBottleEvent(this, logger), this);
|
||||
}
|
||||
|
||||
public void reloadConfigs() {
|
||||
Config.reload(logger);
|
||||
Messages.reload(logger);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.alttd.playerutils.commands;
|
|||
|
||||
import com.alttd.playerutils.PlayerUtils;
|
||||
import com.alttd.playerutils.commands.playerutils_subcommands.Glow;
|
||||
import com.alttd.playerutils.commands.playerutils_subcommands.Reload;
|
||||
import com.alttd.playerutils.commands.playerutils_subcommands.XPCalc;
|
||||
import com.alttd.playerutils.commands.playerutils_subcommands.XPCheque;
|
||||
import com.alttd.playerutils.config.Messages;
|
||||
|
|
@ -32,7 +33,8 @@ public class PlayerUtilsCommand implements CommandExecutor, TabExecutor {
|
|||
subCommands = Arrays.asList(
|
||||
new Glow(logger),
|
||||
new XPCheque(playerUtils),
|
||||
new XPCalc()
|
||||
new XPCalc(),
|
||||
new Reload(playerUtils)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
package com.alttd.playerutils.commands.playerutils_subcommands;
|
||||
|
||||
import com.alttd.playerutils.PlayerUtils;
|
||||
import com.alttd.playerutils.commands.SubCommand;
|
||||
import com.alttd.playerutils.config.Messages;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Reload extends SubCommand {
|
||||
|
||||
private final PlayerUtils playerUtils;
|
||||
|
||||
public Reload(PlayerUtils playerUtils) {
|
||||
this.playerUtils = playerUtils;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||
playerUtils.reloadConfigs();
|
||||
commandSender.sendMiniMessage(Messages.RELOAD.RELOADED, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "reload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabComplete(CommandSender commandSender, String[] args) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return Messages.HELP.RELOAD;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +1,27 @@
|
|||
package com.alttd.playerutils.config;
|
||||
|
||||
import com.alttd.playerutils.PlayerUtils;
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Config extends AbstractConfig{
|
||||
|
||||
static Config config;
|
||||
private Logger logger;
|
||||
|
||||
Config(PlayerUtils playerUtils, Logger logger) {
|
||||
super(playerUtils, "config.yml", logger);
|
||||
Config(Logger logger) {
|
||||
super(
|
||||
new File(System.getProperty("user.home") + File.separator
|
||||
+ "share" + File.separator
|
||||
+ "configs" + File.separator
|
||||
+ "PlayerUtils"),
|
||||
"config.yml", logger);
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public static void reload(PlayerUtils playerUtils, Logger logger) {
|
||||
public static void reload(Logger logger) {
|
||||
logger.info("Reloading config");
|
||||
config = new Config(playerUtils, logger);
|
||||
config = new Config(logger);
|
||||
config.readConfig(Config.class, null);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,26 @@
|
|||
package com.alttd.playerutils.config;
|
||||
|
||||
import com.alttd.playerutils.PlayerUtils;
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class Messages extends AbstractConfig {
|
||||
static Messages config;
|
||||
private final Logger logger;
|
||||
|
||||
Messages(PlayerUtils playerUtils, Logger logger) {
|
||||
super(playerUtils, "messages.yml", logger);
|
||||
Messages(Logger logger) {
|
||||
super(
|
||||
new File(System.getProperty("user.home") + File.separator
|
||||
+ "share" + File.separator
|
||||
+ "configs" + File.separator
|
||||
+ "PlayerUtils"),
|
||||
"messages.yml", logger);
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public static void reload(PlayerUtils playerUtils, Logger logger) {
|
||||
config = new Messages(playerUtils, logger);
|
||||
public static void reload(Logger logger) {
|
||||
config = new Messages(logger);
|
||||
config.readConfig(Messages.class, null);
|
||||
}
|
||||
|
||||
|
|
@ -27,6 +32,7 @@ public class Messages extends AbstractConfig {
|
|||
public static String GLOW = "<green>Glow in a specified color: <gold>/pu glow <color></gold></green>";
|
||||
public static String XP_CHEQUE = "<green>Create an xp cheque: <gold>/pu xpcheque <amount></gold></green>";
|
||||
public static String XP_CALC = "<green>Calculate the amount of xp between levels: <gold>/pu xpcalc <from> <to></gold></green>";
|
||||
public static String RELOAD = "<green>Reload the configs for PlayerUtils: <gold>/pu reload</gold></green>";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
|
|
@ -35,6 +41,7 @@ public class Messages extends AbstractConfig {
|
|||
GLOW = config.getString(prefix, "glow", GLOW);
|
||||
XP_CHEQUE = config.getString(prefix, "xp-cheque", XP_CHEQUE);
|
||||
XP_CALC = config.getString(prefix, "xp-calc", XP_CALC);
|
||||
RELOAD = config.getString(prefix, "reload", RELOAD);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -97,4 +104,15 @@ public class Messages extends AbstractConfig {
|
|||
XP_NEEDED = config.getString(prefix, "xp-needed", XP_NEEDED);
|
||||
}
|
||||
}
|
||||
|
||||
public static class RELOAD {
|
||||
private static final String prefix = "pu-command.reload.";
|
||||
|
||||
public static String RELOADED = "<green>Reloaded configs</green>";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
RELOADED = config.getString(prefix, "reloaded", RELOADED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user