Skip to content

Commit

Permalink
refactor: reload commands are no longer exclusive to dev mode
Browse files Browse the repository at this point in the history
add: Grandma's Knitting Needle pet item
  • Loading branch information
Fix3dll committed Dec 14, 2024
1 parent 7835a19 commit 1fe0797
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class SkyblockAddonsCommand extends CommandBase {
private static final String HEADER = "§7§m----------------§7[ §b§lSkyblockAddons §7]§7§m----------------";
private static final String FOOTER = "§7§m-----------------------------------------------------";
private static final String[] SUBCOMMANDS = {"help", "edit", "folder", "resetZealotCounter", "set", "slayer",
"version", "dev", "brand", "copyBlock", "copyEntity", "copySidebar", "copyTabList", "pd", "reload",
"reloadConfig", "reloadRes", "toggleActionBarLogging", "toggleSlayerTrackerLogging", "copyOpenGL",
"version", "reload", "reloadConfig", "reloadRes", "dev", "brand", "copyBlock", "copyEntity", "copySidebar",
"copyTabList", "pd", "toggleActionBarLogging", "toggleSlayerTrackerLogging", "copyOpenGL",
"toggleSkyBlockOreLogging"
};

Expand Down Expand Up @@ -70,39 +70,14 @@ public List<String> getCommandAliases() {
* the main usage string.
*/
public String getCommandUsage(ICommandSender sender) {
String usage =
HEADER + "\n" +
"§b● " + CommandSyntax.BASE + " §7-§r " + getMessage("commands.usage.sba.base.help") + "\n" +
"§b● " + CommandSyntax.HELP + " §7-§r " + getMessage("commands.usage.sba.help.help") + "\n" +
"§b● " + CommandSyntax.EDIT + " §7-§r " + getMessage("commands.usage.sba.edit.help") + "\n" +
"§b● " + CommandSyntax.SET + " §7-§r " + getMessage("commands.usage.sba.set.zealotCounter.help") + "\n" +
"§b● " + CommandSyntax.RESET_ZEALOT_COUNTER + " §7-§r " + getMessage("commands.usage.sba.resetZealotCounter.help") + "\n" +
"§b● " + CommandSyntax.FOLDER + " §7-§r " + getMessage("commands.usage.sba.folder.help") + "\n" +
"§b● " + CommandSyntax.SLAYER + " §7-§r " + getMessage("commands.usage.sba.slayer.help") + "\n" +
"§b● " + CommandSyntax.VERSION + " §7-§r " + getMessage("commands.usage.sba.version.help") + "\n" +
"§b● " + CommandSyntax.DEV + " §7-§r " + getMessage("commands.usage.sba.dev.help");

if (Feature.DEVELOPER_MODE.isEnabled()) {
usage = usage + "\n" +
"§b● " + CommandSyntax.BRAND + " §7- " + getDevPrefixFormatted() + getMessage("commands.usage.sba.brand.help") + "\n" +
"§b● " + CommandSyntax.COPY_BLOCK + " §7- " + getDevPrefixFormatted() + getMessage("commands.usage.sba.copyBlock.help") + "\n" +
"§b● " + CommandSyntax.COPY_ENTITY + " §7- " + getDevPrefixFormatted() + getMessage("commands.usage.sba.copyEntity.help") + "\n" +
"§b● " + CommandSyntax.COPY_SIDEBAR + " §7- " + getDevPrefixFormatted() + getMessage("commands.usage.sba.copySidebar.help") + "\n" +
"§b● " + CommandSyntax.COPY_TAB_LIST + " §7- " + getDevPrefixFormatted() + getMessage("commands.usage.sba.copyTabList.help") + "\n" +
"§b● " + CommandSyntax.COPY_OPENGL + " §7- " + getDevPrefixFormatted() + getMessage("commands.usage.sba.copyOpenGL.help") + "\n" +
"§b● " + CommandSyntax.PD + " §7- " + getDevPrefixFormatted() + getMessage("commands.usage.sba.printDeaths.help") + "\n" +
"§b● " + CommandSyntax.RELOAD + " §7- " + getDevPrefixFormatted() + getMessage("commands.usage.sba.reload.help") + "\n" +
"§b● " + CommandSyntax.RELOAD_CONFIG + " §7- " + getDevPrefixFormatted() + getMessage("commands.usage.sba.reloadConfig.help") + "\n" +
"§b● " + CommandSyntax.RELOAD_RES + " §7- " + getDevPrefixFormatted() + getMessage("commands.usage.sba.reloadRes.help") + "\n" +
"§b● " + CommandSyntax.TOGGLE_ACTION_BAR_LOGGING + " §7- " + getDevPrefixFormatted() + getMessage("commands.usage.sba.toggleActionBarLogging.help") + "\n" +
"§b● " + CommandSyntax.TOGGLE_SLAYER_TRACKER_LOGGING + " §7- " + getDevPrefixFormatted() + getMessage("commands.usage.sba.toggleSlayerTrackerLogging.help") + "\n" +
"§b● " + CommandSyntax.TOGGLE_SKYBLOCK_ORE_LOGGING + " §7- " + getDevPrefixFormatted() + getMessage("commands.usage.sba.toggleSkyBlockOreLogging.help")
;
StringBuilder builder = new StringBuilder(HEADER);
for (Commands command : Commands.values()) {
if (command.devMode && Feature.DEVELOPER_MODE.isDisabled()) continue;
builder.append("\n").append(command.createMenuDescriptionLine());
}
builder.append("\n").append(FOOTER);

usage = usage + "\n" + FOOTER;

return usage;
return builder.toString();
}

/**
Expand All @@ -121,7 +96,7 @@ public String getSubCommandUsage(String subCommand) {
}
}

return HEADER + "\n" + SubCommandUsage.valueOf(subCommand) + "\n" + FOOTER;
return HEADER + "\n" + Commands.valueOf(subCommand) + "\n" + FOOTER;
}

public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) {
Expand Down Expand Up @@ -303,6 +278,12 @@ public void processCommand(ICommandSender sender, String[] args) throws CommandE
getMessage("messages.copied"));
}
}
} else if (args[0].equalsIgnoreCase("reload")) {
DevUtils.reloadAll();
} else if (args[0].equalsIgnoreCase("reloadConfig")) {
DevUtils.reloadConfig();
} else if (args[0].equalsIgnoreCase("reloadRes")) {
DevUtils.reloadResources();
} else if (Feature.DEVELOPER_MODE.isEnabled()) {
if (args[0].equalsIgnoreCase("brand")) {
String serverBrand = DevUtils.getServerBrand();
Expand Down Expand Up @@ -361,12 +342,6 @@ public void processCommand(ICommandSender sender, String[] args) throws CommandE
main.getDungeonManager().getAlternateDeaths());
main.getUtils().sendMessage(EnumChatFormatting.WHITE + "Tab Deaths: " + EnumChatFormatting.GOLD +
main.getDungeonManager().getPlayerListInfoDeaths());
} else if (args[0].equalsIgnoreCase("reload")) {
DevUtils.reloadAll();
} else if (args[0].equalsIgnoreCase("reloadConfig")) {
DevUtils.reloadConfig();
} else if (args[0].equalsIgnoreCase("reloadRes")) {
DevUtils.reloadResources();
} else if (args[0].equalsIgnoreCase("toggleActionBarLogging")) {
DevUtils.setLoggingActionBarMessages(!DevUtils.isLoggingActionBarMessages());

Expand Down Expand Up @@ -414,14 +389,6 @@ public void processCommand(ICommandSender sender, String[] args) throws CommandE
}
}

/*
Returns the Dev prefix in brackets and with formatting codes.
This simplifies the string for localization to just "Dev".
*/
private String getDevPrefixFormatted() {
return "§e(" + getMessage("commands.usage.sba.dev.prefix") + ")§r ";
}

/*
Gets tab completion options listing all sub-commands.
Developer mode commands are not included if developer mode is disabled.
Expand All @@ -430,7 +397,7 @@ private List<String> getSubCommandTabCompletionOptions(String[] args) {
if (Feature.DEVELOPER_MODE.isEnabled()) {
return getListOfStringsMatchingLastWord(args, SUBCOMMANDS);
} else {
return getListOfStringsMatchingLastWord(args, Arrays.copyOf(SUBCOMMANDS, 7));
return getListOfStringsMatchingLastWord(args, Arrays.copyOf(SUBCOMMANDS, 10));
}
}

Expand Down Expand Up @@ -466,70 +433,46 @@ public String toString() {
}
}

// Syntax definitions for this command and its sub-commands
@Getter @AllArgsConstructor
private enum CommandSyntax {
BASE("/sba"),
HELP("/sba help [command]"),
EDIT("/sba edit"),
SET("/sba set <zealots|eyes|totalZealots §eor§b total> <number>"),
FOLDER("/sba folder"),
DEV("/sba dev"),
BRAND("/sba brand"),
COPY_ENTITY("/sba copyEntity [entityNames] [radius: integer]"),
COPY_SIDEBAR("/sba copySidebar [formatted: boolean]"),
COPY_TAB_LIST("/sba copyTabList"),
COPY_OPENGL("/sba copyOpenGL"),
TOGGLE_ACTION_BAR_LOGGING("/sba toggleActionBarLogging"),
SLAYER("/sba slayer <boss> <stat> <number>"),
COPY_BLOCK("/sba copyBlock"),
RELOAD("/sba reload"),
RELOAD_CONFIG("/sba reloadConfig"),
RELOAD_RES("/sba reloadRes"),
RESET_ZEALOT_COUNTER("/sba resetZealotCounter"),
PD("/sba pd"),
VERSION("/sba version"),
TOGGLE_SLAYER_TRACKER_LOGGING("/sba toggleSlayerTrackerLogging"),
TOGGLE_SKYBLOCK_ORE_LOGGING("/sba toggleSkyBlockOreLogging")
@AllArgsConstructor
private enum Commands {
BASE("/sba", "commands.usage.sba.base.help", null),
HELP("/sba help [command]", "commands.usage.sba.help.help", Collections.singletonList(CommandOption.COMMAND)),
EDIT("/sba edit", "commands.usage.sba.edit.help", null),
SET("/sba set <zealots|eyes|totalZealots §eor§b total> <number>", "commands.usage.sba.set.zealotCounter.detailedHelp.description", Arrays.asList(CommandOption.ZEALOTS, CommandOption.EYES, CommandOption.TOTAL_ZEALOTS)),
RESET_ZEALOT_COUNTER("/sba resetZealotCounter", "commands.usage.sba.resetZealotCounter.help", null),
FOLDER("/sba folder", "commands.usage.sba.folder.help", null),
SLAYER("/sba slayer <boss> <stat> <number>", "commands.usage.sba.slayer.detailedHelp.description", Arrays.asList(CommandOption.SLAYER_BOSS, CommandOption.SLAYER_STAT, CommandOption.SLAYER_NUMBER)),
VERSION("/sba version", "commands.usage.sba.version.help", null),
RELOAD("/sba reload", "commands.usage.sba.reload.help", null),
RELOAD_CONFIG("/sba reloadConfig", "commands.usage.sba.reloadConfig.help", null),
RELOAD_RES("/sba reloadRes", "commands.usage.sba.reloadRes.help", null),
DEV("/sba dev", "commands.usage.sba.dev.detailedHelp.description", null),
BRAND("/sba brand", "commands.usage.sba.brand.help", true,null),
COPY_ENTITY("/sba copyEntity [entityNames] [radius: integer]", "commands.usage.sba.copyEntity.detailedHelp.description", true, Arrays.asList(CommandOption.ENTITY_NAMES, CommandOption.RADIUS)),
COPY_SIDEBAR("/sba copySidebar [formatted: boolean]", "commands.usage.sba.copySidebar.detailedHelp.description", true, Collections.singletonList(CommandOption.FORMATTED)),
COPY_TAB_LIST("/sba copyTabList", "commands.usage.sba.copyTabList.detailedHelp.description", true, null),
COPY_OPENGL("/sba copyOpenGL", "commands.usage.sba.copyOpenGL.detailedHelp.description", true, null),
COPY_BLOCK("/sba copyBlock", "commands.usage.sba.copyBlock.help", true, null),
PD("/sba pd", "commands.usage.sba.printDeaths.help", true, null),
TOGGLE_ACTION_BAR_LOGGING("/sba toggleActionBarLogging", "commands.usage.sba.toggleActionBarLogging.help", true, null),
TOGGLE_SLAYER_TRACKER_LOGGING("/sba toggleSlayerTrackerLogging", "commands.usage.sba.toggleSlayerTrackerLogging.help", true, null),
TOGGLE_SKYBLOCK_ORE_LOGGING("/sba toggleSkyBlockOreLogging", "commands.usage.sba.toggleSkyBlockOreLogging.help", true, null),
;

private final String syntax;
private final String descriptionTranslationKey;
private final boolean devMode;
private final List<CommandOption> options;

@Override
public String toString() {
return syntax;
Commands(String syntax, String descriptionTranslationKey, List<CommandOption> options) {
this(syntax, descriptionTranslationKey, false, options);
}
}

// Usage strings for all the sub-commands of this command
@AllArgsConstructor
private enum SubCommandUsage {
HELP(CommandSyntax.HELP, "commands.usage.sba.help.help", Collections.singletonList(CommandOption.COMMAND)),
EDIT(CommandSyntax.EDIT, "commands.usage.sba.edit.help", null),
SET(CommandSyntax.SET, "commands.usage.sba.set.zealotCounter.detailedHelp.description", Arrays.asList(CommandOption.ZEALOTS, CommandOption.EYES, CommandOption.TOTAL_ZEALOTS)),
RESET_ZEALOT_COUNTER(CommandSyntax.RESET_ZEALOT_COUNTER, "commands.usage.sba.resetZealotCounter.help", null),
FOLDER(CommandSyntax.FOLDER, "commands.usage.sba.folder.help", null),
DEV(CommandSyntax.DEV, "commands.usage.sba.dev.detailedHelp.description", null),
BRAND(CommandSyntax.BRAND, "commands.usage.sba.brand.help", null),
COPY_ENTITY(CommandSyntax.COPY_ENTITY, "commands.usage.sba.copyEntity.detailedHelp.description", Arrays.asList(CommandOption.ENTITY_NAMES, CommandOption.RADIUS)),
COPY_SIDEBAR(CommandSyntax.COPY_SIDEBAR, "commands.usage.sba.copySidebar.detailedHelp.description", Collections.singletonList(CommandOption.FORMATTED)),
COPY_TAB_LIST(CommandSyntax.COPY_TAB_LIST, "commands.usage.sba.copyTabList.detailedHelp.description", null),
COPY_OPENGL(CommandSyntax.COPY_OPENGL, "commands.usage.sba.copyOpenGL.detailedHelp.description", null),
TOGGLE_ACTION_BAR_LOGGING(CommandSyntax.TOGGLE_ACTION_BAR_LOGGING, "commands.usage.sba.toggleActionBarLogging.help", null),
SLAYER(CommandSyntax.SLAYER, "commands.usage.sba.slayer.detailedHelp.description", Arrays.asList(CommandOption.SLAYER_BOSS, CommandOption.SLAYER_STAT, CommandOption.SLAYER_NUMBER)),
COPY_BLOCK(CommandSyntax.COPY_BLOCK, "commands.usage.sba.copyBlock.help", null),
RELOAD(CommandSyntax.RELOAD, "commands.usage.sba.reload.help", null),
RELOAD_CONFIG(CommandSyntax.RELOAD_CONFIG, "commands.usage.sba.reloadConfig.help", null),
RELOAD_RES(CommandSyntax.RELOAD_RES, "commands.usage.sba.reloadRes.help", null),
PD(CommandSyntax.PD, "commands.usage.sba.printDeaths.help", null),
VERSION(CommandSyntax.VERSION, "commands.usage.sba.version.help", null),
TOGGLE_SLAYER_TRACKER_LOGGING(CommandSyntax.TOGGLE_SLAYER_TRACKER_LOGGING, "commands.usage.sba.toggleSlayerTrackerLogging.help", null),
TOGGLE_SKYBLOCK_ORE_LOGGING(CommandSyntax.TOGGLE_SKYBLOCK_ORE_LOGGING, "commands.usage.sba.toggleSkyBlockOreLogging.help", null),
;

private final CommandSyntax syntax;
private final String descriptionTranslationKey;
private final List<CommandOption> options;
public String createMenuDescriptionLine() {
return "§b● " + this.syntax + " §7-§r "
+ (devMode ? "§e(" + getMessage("commands.usage.sba.dev.prefix") + ")§r " : "")
+ getMessage(this.descriptionTranslationKey);
}

/**
* <p>Returns a formatted usage string for the sub-command with the name of this Enum constant.</p>
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/codes/biscuit/skyblockaddons/utils/DevUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -570,20 +570,16 @@ public static void reloadAll() {
* This method reloads all of the mod's settings from the settings file.
*/
public static void reloadConfig() {
logger.info("Reloading settings...");
sendMessageOrLog("Reloading settings...");
main.getConfigValues().loadValues();
logger.info("Settings reloaded");
sendMessageOrLog("Settings reloaded.");
}

/**
* This method reloads all of the mod's resources from the corresponding files.
*/
public static void reloadResources() {
if (mc.thePlayer != null) {
main.getUtils().sendMessage(Translations.getMessage("messages.reloadingResources"));
} else {
logger.info(Translations.getMessage("messages.reloadingResources"));
}
sendMessageOrLog(Translations.getMessage("messages.reloadingResources"));
DataUtils.registerNewRemoteRequests();
DataUtils.readLocalAndFetchOnline();
main.getPersistentValuesManager().loadValues();
Expand All @@ -602,11 +598,7 @@ public static void reloadResources() {
SkyblockAddons.getInstance().getScheduler().scheduleAsyncTask(scheduledTask -> {
if (DataUtils.getExecutionServiceMetrics().getActiveConnectionCount() == 0) {
DataUtils.onSkyblockJoined();
if (mc.thePlayer != null) {
main.getUtils().sendMessage(Translations.getMessage("messages.resourcesReloaded"));
} else {
logger.info(Translations.getMessage("messages.resourcesReloaded"));
}
sendMessageOrLog(Translations.getMessage("messages.resourcesReloaded"));
scheduledTask.cancel();
}
}, 0, 2);
Expand Down Expand Up @@ -647,6 +639,14 @@ public static void setCopyMode(CopyMode copyMode) {
}
}

private static void sendMessageOrLog(String message) {
if (mc.thePlayer != null) {
main.getUtils().sendMessage(message);
} else {
logger.info(message);
}
}

public enum CopyMode {
BLOCK,
ENTITY,
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/petItems.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
"material": "gold_ingot",
"rarity": "UNCOMMON"
},
"GRANDMAS_KNITTING_NEEDLE": {
"displayName": "§9Grandma's Knitting Needle",
"enchanted": true,
"material": "stick",
"rarity": "RARE"
},
"GREEN_BANDANA": {
"displayName": "§5Green Bandana",
"material": "skull_item",
Expand Down

0 comments on commit 1fe0797

Please sign in to comment.