mirror of
https://github.com/rockyhawk64/CommandPanels.git
synced 2025-11-18 07:14:17 +01:00
custom commands tweaks for next release
This commit is contained in:
parent
5412425b42
commit
3ece7ae9a7
@ -10,7 +10,7 @@ config:
|
||||
panel-blocks: true
|
||||
hotbar-items: true
|
||||
custom-commands: true
|
||||
auto-register-commands: false
|
||||
auto-register-commands: true
|
||||
auto-update-panels: false
|
||||
stop-sound: true
|
||||
disabled-world-message: true
|
||||
|
||||
@ -125,6 +125,7 @@ public class Context {
|
||||
configHandler = new ConfigHandler(this);
|
||||
econ = null;
|
||||
|
||||
openCommands = new OpenCommands(this);
|
||||
reloader = new ReloadCommand(this);
|
||||
commands = new CommandRunner(this);
|
||||
|
||||
@ -136,7 +137,6 @@ public class Context {
|
||||
potion_1_8 = new Potion_1_8();
|
||||
potion_1_20_4 = new Potion_1_20_4();
|
||||
|
||||
openCommands = new OpenCommands(this);
|
||||
openPanels = new SessionHandler(this);
|
||||
hotbar = new HotbarItemLoader(this);
|
||||
nbt = new NBTManager(this);
|
||||
|
||||
@ -53,6 +53,11 @@ public class ReloadCommand implements CommandExecutor {
|
||||
// reloadHotbarSlots
|
||||
ctx.hotbar.reloadHotbarSlots();
|
||||
|
||||
// register custom commands (does not run on plugin load as PriorityHandler will do that)
|
||||
if (ctx.configHandler.isTrue("config.auto-register-commands")) {
|
||||
ctx.openCommands.registerCommands();
|
||||
}
|
||||
|
||||
// send success message
|
||||
sender.sendMessage(ctx.text.colour(ctx.tag + ctx.configHandler.config.getString("config.format.reload")));
|
||||
});
|
||||
@ -71,11 +76,6 @@ public class ReloadCommand implements CommandExecutor {
|
||||
//load panel files from panels folder
|
||||
fileNamesFromDirectory(new File(ctx.plugin.getDataFolder() + File.separator + "panels"));
|
||||
ctx.tag = ctx.text.colour(ctx.configHandler.config.getString("config.format.tag")) + " ";
|
||||
|
||||
Bukkit.getScheduler().runTask(ctx.plugin, () -> {
|
||||
// register custom commands
|
||||
ctx.openCommands.registerCommands();
|
||||
});
|
||||
}
|
||||
|
||||
//look through all files in all folders
|
||||
|
||||
@ -2,24 +2,13 @@ package me.rockyhawk.commandpanels.commands.opencommands;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import me.rockyhawk.commandpanels.Context;
|
||||
import me.rockyhawk.commandpanels.api.Panel;
|
||||
import me.rockyhawk.commandpanels.manager.session.PanelPosition;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -42,6 +31,9 @@ public class OpenCommands {
|
||||
|
||||
public OpenCommands(Context pl) {
|
||||
this.ctx = pl;
|
||||
if(ctx.version.isAtLeast("1.13")){
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new PriorityHandler(this), ctx.plugin);
|
||||
}
|
||||
}
|
||||
|
||||
private void unloadCommands() {
|
||||
@ -70,12 +62,18 @@ public class OpenCommands {
|
||||
String commandName = panelCommands.remove(0);
|
||||
Command command = new BaseCommandPanel(ctx, panel, commandName, panelCommands);
|
||||
|
||||
// Forcefully replace command if it was known from another plugin
|
||||
Command existing = knownCommands.remove(commandName);
|
||||
if (existing != null) {
|
||||
command.unregister(commandMap);
|
||||
}
|
||||
|
||||
commandMap.register(command.getName(), "commandpanels", command);
|
||||
commands.put(command.getName(), command);
|
||||
});
|
||||
}
|
||||
|
||||
private CommandMap getCommandMap() {
|
||||
protected CommandMap getCommandMap() {
|
||||
try {
|
||||
final Class<? extends Server> serverClass = Bukkit.getServer().getClass();
|
||||
final Field commandMapField = serverClass.getDeclaredField("commandMap");
|
||||
@ -88,7 +86,11 @@ public class OpenCommands {
|
||||
|
||||
|
||||
public void registerCommands(){
|
||||
if (ctx.version.isBelow("1.13")) return;
|
||||
unloadCommands();
|
||||
if (!ctx.configHandler.isTrue("config.auto-register-commands")) {
|
||||
return;
|
||||
}
|
||||
loadCommands();
|
||||
Bukkit.getOnlinePlayers().forEach(Player::updateCommands);
|
||||
}
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
package me.rockyhawk.commandpanels.commands.opencommands;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.ServerLoadEvent;
|
||||
|
||||
public class PriorityHandler implements Listener {
|
||||
private OpenCommands openCommands;
|
||||
|
||||
public PriorityHandler(OpenCommands ext) {
|
||||
openCommands = ext;
|
||||
}
|
||||
|
||||
// This listener will register commands after the server loads so that it can properly override other plugins
|
||||
|
||||
@EventHandler
|
||||
public void onServerLoad(ServerLoadEvent e) {
|
||||
openCommands.registerCommands();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user