Skip to content

Commit

Permalink
Fix commands to work in 1.21.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Travja committed Jan 26, 2025
1 parent f02f8b1 commit 0ca358c
Show file tree
Hide file tree
Showing 16 changed files with 312 additions and 675 deletions.
27 changes: 11 additions & 16 deletions codex-plugin/src/main/java/studio/magemonkey/codex/CodexEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand Down Expand Up @@ -110,9 +109,8 @@ public class CodexEngine extends CodexPlugin<CodexEngine> implements Listener {
@Getter
private boolean scoreboardsEnabled;

private UnstuckCommand unstuck;
private CycleTask cTask;
private UpdateTask uTask;
private CycleTask cTask;
private UpdateTask uTask;

public CodexEngine() {
setInstance();
Expand Down Expand Up @@ -156,8 +154,6 @@ public static CodexEngine get() {
}

final boolean loadCore() {
unstuck = new UnstuckCommand();

ConfigurationSerialization.registerClass(ItemBuilder.class);
ConfigurationSerialization.registerClass(EnchantmentStorageBuilder.class, "Codex_EnchantmentStorageMeta");
ConfigurationSerialization.registerClass(FireworkEffectBuilder.class, "Codex_FireworkEffectMeta");
Expand Down Expand Up @@ -219,9 +215,15 @@ final boolean loadCore() {
}

protected void registerEvents() {
if (chatEnabled) {
getCommandManager().registerCommand(new ChatCommander<>(this));
new ChatListener(this);
}
setupScoreboards();


getPluginManager().registerEvents(this, this);
getPluginManager().registerEvents(new ArmorListener(), this);
getPluginManager().registerEvents(unstuck, this);
getPluginManager().registerEvents(new BoatListener(), this);
getPluginManager().registerEvents(new InteractListener(cfg().getJYML()), this);
getPluginManager().registerEvents(new JoinListener(this, cfg().getJYML()), this);
Expand Down Expand Up @@ -296,19 +298,13 @@ public void setConfig() {
boolean debug = cfg().getJYML().getBoolean("debug", false);
Debugger.setDebug(debug);

if (chatEnabled) {
new ChatCommander(this);
new ChatListener(this);
}
setupScoreboards();

this.lang = new CoreLang(this);
this.lang.setup();
}

private void setupScoreboards() {
if (scoreboardsEnabled) {
new ScoreboardCommander(this);
getCommandManager().registerCommand(new ScoreboardCommander<>(this));
new BoardListener(this);
cTask = new CycleTask(this);
uTask = new UpdateTask(this);
Expand All @@ -332,8 +328,7 @@ public void registerHooks() {

@Override
public void registerCommands(@NotNull IGeneralCommand<CodexEngine> mainCommand) {
PluginCommand unstuckCommand = getCommand("stuck");
if (unstuckCommand != null) unstuckCommand.setExecutor(unstuck);
getCommandManager().registerCommand(new UnstuckCommand<>(this));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
Expand All @@ -15,6 +13,8 @@
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
import studio.magemonkey.codex.CodexEngine;
import studio.magemonkey.codex.CodexPlugin;
import studio.magemonkey.codex.commands.api.IGeneralCommand;
import studio.magemonkey.codex.config.legacy.LegacyConfigManager;
import studio.magemonkey.codex.util.messages.MessageData;

Expand All @@ -28,7 +28,7 @@
cooldown: 30
warmup: 5
*/
public class UnstuckCommand implements CommandExecutor, Listener {
public class UnstuckCommand<P extends CodexPlugin<P>> extends IGeneralCommand<P> implements Listener {
private final Map<UUID, LinkedList<Location>> locs = new HashMap<>();
private final Map<UUID, Location> warmingUp = new HashMap<>();
private final Map<UUID, Long> cooldown = new HashMap<>();
Expand All @@ -37,7 +37,10 @@ public class UnstuckCommand implements CommandExecutor, Listener {
private final FileConfiguration config;
private final File destFile;

public UnstuckCommand() {
public UnstuckCommand(@NotNull P plugin) {
super(plugin, List.of("unstuck"), "codex.stuck");
plugin.getPluginManager().registerEvents(this, plugin);

destFile = new File(CodexEngine.get().getDataFolder(), "unstuck.log");
config = LegacyConfigManager.loadConfigFile(destFile, null);
}
Expand Down Expand Up @@ -65,15 +68,30 @@ private void purge() {
}
}

@Override
public boolean playersOnly() {
return true;
}

@Override
public boolean onCommand(@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
@NotNull String[] args) {
@NotNull
public String usage() {
return "/unstuck";
}

@Override
@NotNull
public String description() {
return "Get stuck in a hole? Teleport out";
}

@Override
public void perform(@NotNull CommandSender sender,
@NotNull String label,
@NotNull String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You have to be a player to use that command!");
return true;
return;
}

Player player = (Player) sender;
Expand All @@ -86,13 +104,13 @@ public boolean onCommand(@NotNull CommandSender sender,
CodexEngine.get()
.getMessageUtil()
.sendMessage("general.commands.unstuck.err.cooldown", sender, new MessageData("time", seconds));
return true;
return;
} else cooldown.remove(id);
}

if (warmingUp.containsKey(id)) {
CodexEngine.get().getMessageUtil().sendMessage("general.commands.unstuck.err.warmingUp", sender);
return true;
return;
}

warmingUp.put(id, player.getLocation().getBlock().getLocation());
Expand Down Expand Up @@ -128,7 +146,7 @@ public void run() {

tasks.put(id, task);

return true;
return;
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,46 +26,60 @@
*/
package studio.magemonkey.codex.mccore.chat;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import studio.magemonkey.codex.mccore.commands.CommandHandler;
import org.jetbrains.annotations.NotNull;
import studio.magemonkey.codex.CodexPlugin;
import studio.magemonkey.codex.commands.api.IGeneralCommand;

import java.util.List;

/**
* Controls commands for the chat API
*/
public class ChatCommander extends CommandHandler {

public class ChatCommander<P extends CodexPlugin<P>> extends IGeneralCommand<P> {
/**
* Constructor
*
* @param plugin plugin reference
*/
public ChatCommander(Plugin plugin) {
super(plugin, "Chat", "chat");
public ChatCommander(P plugin) {
super(plugin, List.of("chat"));

registerSubCommands();
}

/**
* Registers the sub-commands
*/
protected void registerSubCommands() {
this.addSubCommand(new ListCommand<>(plugin));
this.addSubCommand(new NameCommand<>(plugin));
this.addSubCommand(new PrefixCommand<>(plugin));
this.addSubCommand(new ResetCommand<>(plugin));
}

@Override
protected void registerCommands() {
registerCommand("list", new ListCommand());
registerCommand("name", new NameCommand());
registerCommand("prefix", new PrefixCommand());
registerCommand("reset", new ResetCommand());
@NotNull
public String usage() {
return "/%cmd% list - Displays unlocked prefixes\n" +
"/%cmd% name <name> - Sets your chat name\n" +
"/%cmd% prefix <prefix> - Sets your chat prefix\n" +
"/%cmd% reset - Resets your chat name and prefix";
}

@Override
@NotNull
public String description() {
return "Chat commands";
}

@Override
public boolean playersOnly() {
return true;
}

/**
* Displays the usage for chat commands
*
* @param sender sender of the command
*/
@Override
public void displayUsage(CommandSender sender) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.DARK_RED + "Chat commands are for players only!");
} else super.displayUsage(sender);
protected void perform(@NotNull CommandSender sender, @NotNull String label, @NotNull String[] args) {
printUsage(sender);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,67 +28,59 @@

import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import studio.magemonkey.codex.mccore.commands.CommandHandler;
import studio.magemonkey.codex.mccore.commands.ICommand;
import studio.magemonkey.codex.mccore.commands.SenderType;
import org.jetbrains.annotations.NotNull;
import studio.magemonkey.codex.CodexPlugin;
import studio.magemonkey.codex.commands.api.ISubCommand;

import java.util.List;

/**
* Displays a list of unlocked prefixes
*/
class ListCommand implements ICommand {
class ListCommand<P extends CodexPlugin<P>> extends ISubCommand<P> {
ListCommand(P plugin) {
super(plugin, List.of("list"), ChatNodes.LIST.getNode());
}

/**
* Executes the command
*
* @param handler command handler
* @param plugin plugin reference
* @param sender sender of the command
* @param label command label
* @param args command arguments
*/
@Override
public void execute(CommandHandler handler, Plugin plugin, CommandSender sender, String[] args) {
public void perform(@NotNull CommandSender sender, @NotNull String label, @NotNull String[] args) {
ChatData data = Chat.getPlayerData(sender.getName());
if (data != null) {
String message = ChatColor.DARK_GREEN + "Unlocked prefixes: ";
if (data.unlockedPrefixes.size() > 0) {
StringBuilder message = new StringBuilder(ChatColor.DARK_GREEN + "Unlocked prefixes: ");
if (!data.unlockedPrefixes.isEmpty()) {
for (Prefix prefix : data.unlockedPrefixes) {
message += prefix.text + ChatColor.GRAY + ", ";
message.append(prefix.text).append(ChatColor.GRAY).append(", ");
}
message = message.substring(0, message.length() - 2);
message = new StringBuilder(message.substring(0, message.length() - 2));
}
sender.sendMessage(message);
} else handler.displayUsage(sender);
}

/**
* @return permission needed for this command
*/
public String getPermissionNode() {
return ChatNodes.LIST.getNode();
sender.sendMessage(message.toString());
} else printUsage(sender);
}

/**
* @return args string
* @return description
*/
@Override
public String getArgsString() {
return "";
@NotNull
public String description() {
return "Displays unlocked prefixes";
}

/**
* @return description
*/
@NotNull
@Override
public String getDescription() {
return "Displays unlocked prefixes";
public String usage() {
return "";
}

/**
* Sender required for the command
*/
@Override
public SenderType getSenderType() {
return SenderType.PLAYER_ONLY;
public boolean playersOnly() {
return true;
}
}
Loading

0 comments on commit 0ca358c

Please sign in to comment.