mirror of
https://github.com/YouHaveTrouble/NotJustNameplates.git
synced 2026-05-12 06:26:58 +00:00
config reload command
This commit is contained in:
@@ -17,18 +17,25 @@ public class NJNConfig {
|
||||
|
||||
private final HashMap<String, DisplayContent> displayContents = new HashMap<>();
|
||||
|
||||
public final String noPermissionMessage, configReloadedMessage;
|
||||
|
||||
protected NJNConfig(NotJustNameplates plugin) {
|
||||
this.plugin = plugin;
|
||||
plugin.saveDefaultConfig();
|
||||
plugin.reloadConfig();
|
||||
this.config = plugin.getConfig();
|
||||
reload();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
displayContents.clear();
|
||||
this.config = plugin.getConfig();
|
||||
|
||||
ConfigurationSection messagesSection = config.getConfigurationSection("messages");
|
||||
if (messagesSection == null) {
|
||||
messagesSection = config.createSection("messages");
|
||||
plugin.getLogger().severe("No messages section found in config! Correct your config and reload.");
|
||||
}
|
||||
|
||||
noPermissionMessage = messagesSection.getString("no-permission", "<red>You do not have permission to use this.");
|
||||
configReloadedMessage = messagesSection.getString("config-reloaded", "<aqua>NJN Config reloaded.");
|
||||
|
||||
|
||||
ConfigurationSection namePlatesSection = config.getConfigurationSection("nameplates");
|
||||
if (namePlatesSection == null) {
|
||||
plugin.getLogger().severe("No nameplates section found in config! Correct your config and reload.");
|
||||
@@ -44,6 +51,7 @@ public class NJNConfig {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public DisplayContent getDisplayContent(String name) {
|
||||
return displayContents.get(name);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.youhavetrouble.notjustnameplates;
|
||||
|
||||
import me.youhavetrouble.notjustnameplates.commands.MainCommand;
|
||||
import me.youhavetrouble.notjustnameplates.nameplates.TeamManagementListener;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@@ -11,14 +12,22 @@ public final class NotJustNameplates extends JavaPlugin {
|
||||
private static NJNConfig config;
|
||||
private static long time = Long.MIN_VALUE;
|
||||
|
||||
private TeamManagementListener teamManagementListener = null;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
config = new NJNConfig(this);
|
||||
|
||||
DefaultPermissions.registerPermission("notjustnameplates.seeown", "Allows a player to see their own nameplate", PermissionDefault.FALSE);
|
||||
DefaultPermissions.registerPermission("notjustnameplates.command", "Allows a player to use the /njn command", PermissionDefault.TRUE);
|
||||
|
||||
this.teamManagementListener = new TeamManagementListener(this);
|
||||
|
||||
getServer().getPluginManager().registerEvents(this.teamManagementListener, this);
|
||||
|
||||
new MainCommand(this);
|
||||
|
||||
getServer().getPluginManager().registerEvents(new TeamManagementListener(this), this);
|
||||
getServer().getScheduler().runTaskTimerAsynchronously(this, () -> {
|
||||
time++;
|
||||
if (config == null) return;
|
||||
@@ -31,6 +40,12 @@ public final class NotJustNameplates extends JavaPlugin {
|
||||
}, 1, 1);
|
||||
}
|
||||
|
||||
public void reloadPluginConfig() {
|
||||
config = new NJNConfig(this);
|
||||
teamManagementListener.reloadTeams();
|
||||
|
||||
}
|
||||
|
||||
public static NotJustNameplates getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package me.youhavetrouble.notjustnameplates.commands;
|
||||
|
||||
|
||||
import me.youhavetrouble.notjustnameplates.NotJustNameplates;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MainCommand extends Command {
|
||||
|
||||
public MainCommand(NotJustNameplates plugin) {
|
||||
super("njn");
|
||||
setPermission("notjustnameplates.command");
|
||||
plugin.getServer().getCommandMap().register("njn", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
|
||||
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(Component.text("NotJustNameplates " + NotJustNameplates.getInstance().getPluginMeta().getVersion()));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
if (!sender.hasPermission("notjustnameplates.command.reload")) {
|
||||
sender.sendMessage(Component.text("You do not have permission to use this command"));
|
||||
return true;
|
||||
}
|
||||
NotJustNameplates.getInstance().reloadPluginConfig();
|
||||
sender.sendMessage(Component.text("Reloaded config"));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
|
||||
List<String> completions = new ArrayList<>();
|
||||
if (args.length == 0) return completions;
|
||||
if (args.length == 1 && sender.hasPermission("notjustnameplates.command.reload")) {
|
||||
completions.add("reload");
|
||||
}
|
||||
return StringUtil.copyPartialMatches(args[args.length - 1], completions, new ArrayList<>());
|
||||
}
|
||||
}
|
||||
+12
@@ -59,6 +59,18 @@ public class TeamManagementListener implements Listener {
|
||||
nameplate.remove();
|
||||
}
|
||||
|
||||
public void reloadTeams() {
|
||||
this.players.values().forEach(Nameplate::remove);
|
||||
this.players.clear();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
DisplayContent displayContent = NotJustNameplates.getPluginConfig().getDisplayContent("default");
|
||||
players.put(player.getName(), new Nameplate(player.getUniqueId(), displayContent != null ? displayContent : new DisplayContent()));
|
||||
}
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
sendTeamMembers(player);
|
||||
}
|
||||
}
|
||||
|
||||
private void addPlayerToTeam(@NotNull Player player, @NotNull Player target) {
|
||||
CraftPlayer craftPlayer = (CraftPlayer) target;
|
||||
ClientboundSetPlayerTeamPacket teamCreatePacket = ClientboundSetPlayerTeamPacket
|
||||
|
||||
@@ -21,3 +21,7 @@ nameplates:
|
||||
# "fixed" - no rotation
|
||||
billboard: "horizontal"
|
||||
|
||||
messages:
|
||||
config-reloaded: "<aqua>NJN Config reloaded."
|
||||
no-permission: "<red>You do not have permission to use this."
|
||||
|
||||
|
||||
Reference in New Issue
Block a user