From 7d39335e5b181b84b4c30c2ded7cfa2178c976bc Mon Sep 17 00:00:00 2001 From: Matt <25674682+spazzylemons@users.noreply.github.com> Date: Thu, 10 Dec 2020 10:27:52 -0500 Subject: [PATCH 1/7] Add /rules to rewrite --- build.gradle | 1 + .../stickycommands/StickyCommands.java | 2 +- .../stickycommands/commands/RulesCommand.java | 131 ++++++++++++++++++ src/main/resources/rulebook.md | 97 +++++++++++++ 4 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java create mode 100644 src/main/resources/rulebook.md diff --git a/build.gradle b/build.gradle index 49080ff..7336c6e 100644 --- a/build.gradle +++ b/build.gradle @@ -67,6 +67,7 @@ dependencies { compileOnly "com.github.MilkBowl:VaultAPI:1.7" compileOnly "me.clip:placeholderapi:2.10.6" implementation "com.dumbdogdiner:stickyapi:2.0.0" + implementation 'com.atlassian.commonmark:commonmark:0.15.2' compileOnly 'net.luckperms:api:5.2' compileOnly 'com.dumbdogdiner.closedsource-package-mirror:stafffacilities:4.8.5' //compileOnly 'me.xtomyserrax:StaffFacilities' diff --git a/src/main/java/com/dumbdogdiner/stickycommands/StickyCommands.java b/src/main/java/com/dumbdogdiner/stickycommands/StickyCommands.java index 083a1ef..62a9dd8 100644 --- a/src/main/java/com/dumbdogdiner/stickycommands/StickyCommands.java +++ b/src/main/java/com/dumbdogdiner/stickycommands/StickyCommands.java @@ -222,7 +222,7 @@ boolean registerCommands() { commandList.add(new PowerToolCommand(this)); commandList.add(new PlayerTimeCommand(this)); commandList.add(new SmiteCommand(this)); - ; + RulesCommand.build(this); CommandUtil.registerCommands(getServer(), commandList); return true; diff --git a/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java b/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java new file mode 100644 index 0000000..a781505 --- /dev/null +++ b/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java @@ -0,0 +1,131 @@ +package com.dumbdogdiner.stickycommands.commands; + +import com.dumbdogdiner.stickyapi.bukkit.command.builder.CommandBuilder; +import com.dumbdogdiner.stickyapi.bukkit.item.generator.BookGenerator; +import com.dumbdogdiner.stickyapi.common.book.chat.JsonComponent; +import com.dumbdogdiner.stickyapi.common.book.commonmarkextensions.JsonComponentWriter; +import com.dumbdogdiner.stickyapi.common.book.commonmarkextensions.MCFormatExtension; +import com.dumbdogdiner.stickyapi.common.book.commonmarkextensions.MarkdownJsonRenderer; +import com.dumbdogdiner.stickyapi.common.command.ExitCode; +import com.dumbdogdiner.stickyapi.common.util.BookUtil; +import com.dumbdogdiner.stickycommands.StickyCommands; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; +import org.commonmark.node.Document; +import org.commonmark.parser.Parser; + +import java.io.*; +import java.util.Collections; +import java.util.List; + +public class RulesCommand { + public static final String PERMISSION = "apitestplugin.rules"; + + public static void build(Plugin owner) { + new CommandBuilder("rules") + .description("Get a copy of the the server's rules") + .permission(PERMISSION) + .alias("rulebook") + .requiresPlayer(true) + .onTabComplete((sender, s, arguments) -> Collections.emptyList()) + .onExecute((sender, arguments, vars) -> { + if (!sender.hasPermission(PERMISSION)) { + return ExitCode.EXIT_PERMISSION_DENIED; + } + + if (!(sender instanceof Player)) { + return ExitCode.EXIT_MUST_BE_PLAYER; + } + + try { + ((Player) sender).getInventory().addItem(generateDefault()); + } catch (IOException e) { + e.printStackTrace(); + return ExitCode.EXIT_ERROR; + } + + return ExitCode.EXIT_SUCCESS; + }) + .onError((exitCode, sender, arguments, vars) -> { + var provider = StickyCommands.getInstance().getLocaleProvider(); + switch (exitCode) { + case EXIT_PERMISSION_DENIED: + sender.sendMessage(provider.translate("no-permission", vars)); + break; + case EXIT_MUST_BE_PLAYER: + sender.sendMessage(provider.translate("must-be-player", vars)); + break; + case EXIT_ERROR: + sender.sendMessage(provider.translate("server-error", vars)); + break; + case EXIT_SUCCESS: + break; + default: + sender.sendMessage(ChatColor.RED + "Exited with " + exitCode); + } + }) + .register(owner); + } + + private static Reader getRulebookReader() { + StickyCommands plugin = StickyCommands.getInstance(); + try { + var dataFolder = plugin.getDataFolder(); + var rulebook = new File(dataFolder, "rulebook.md"); + if (!rulebook.exists()) { + if (!dataFolder.mkdirs() || !rulebook.createNewFile()) { + throw new IOException("Could not save default rulebook to data folder"); + } + try (var writer = new FileOutputStream(rulebook)) { + try (var defaultRulebook = plugin.getResource("rulebook.md")) { + if (defaultRulebook == null) throw new IllegalStateException("No rulebook in the resources!"); + byte[] bytes; + do { + bytes = defaultRulebook.readNBytes(2048); + writer.write(bytes); + } while (bytes.length > 0); + writer.write(defaultRulebook.read()); + } + } + return new FileReader(rulebook); + } + } catch (Exception e) { + e.printStackTrace(); + } + var resource = plugin.getResource("rulebook.md"); + if (resource == null) { + return new StringReader("The rulebook could not be loaded."); + } else { + return new InputStreamReader(resource); + } + } + + private static ItemStack generateDefault() throws IOException { + try (var reader = getRulebookReader()) { + return generate(reader, "§ddddMC Survival Handbook", "Stixil"); + } + } + + private static ItemStack generate(Reader reader, String title, String author) throws IOException { + var builder = Parser.builder(); + ((MCFormatExtension) MCFormatExtension.create()).extend(builder); + var cmparser = builder.build(); + var bookGenerator = new BookGenerator(Material.WRITTEN_BOOK); + var sections = BookUtil.splitDocumentByBreaks((Document) cmparser.parseReader(reader)); + sections.stream() + .map(section -> BookUtil.splitBookPages(renderDocument(section))) + .flatMap(List::stream) + .forEach(page -> bookGenerator.addPage(page.toJson())); + return bookGenerator.setTitle(title).setAuthor(author).toItemStack(1); + } + + private static JsonComponent renderDocument(Document document) { + var component = new JsonComponent(); + var writer = new JsonComponentWriter(component); + new MarkdownJsonRenderer(writer).render(document); + return component; + } +} diff --git a/src/main/resources/rulebook.md b/src/main/resources/rulebook.md new file mode 100644 index 0000000..dc56fdb --- /dev/null +++ b/src/main/resources/rulebook.md @@ -0,0 +1,97 @@ +# Dumb Dog Diner MC Survival Handbook + +## $red The Rules$ + +1. Absolutely no griefing, theft, or intentional distress! +2. No cheating/hacking allowed. Optifine and similar are okay. +3. No floating trees. +4. No fully-automatic redstone farms. +5. No harassment, bullying, or abuse. +6. No AFK fishing. + +--- + +## $dark_green Gameplay$ + +The world border for all worlds is 8,000 blocks from the center. Because of how +$dark_red Nether Portal$ travel works, you will not be able to light them past 1,000 blocks +from the center. You may build wherever you like! Try /rtp to help find a spot! + +This server uses a $red Death Chest$ system. Upon death, a campfire with your items +will spawn at your death location. It will last for 10 minutes before your items +drop on the ground! You can have up to 3 $red Death Chests$ at a time. + +--- + +## $dark_aqua Trading$ + +We use chest chops for player to trade good for $gold Coins$. Coins may be +earned through selling goods to other players, paying/receiving money for a +service, or by selling goods to the server itself. + +Chest shops can buy or sell items! To make a shop, place a chest and shift-click +with the item you want to sell or buy. Regular users may have up to 6 shops at a +time. + +--- + +## $red Commands$ + +Tab-complete is set up to only show commands you have access to. Here are some +useful ones: + +- $blue /help$ - Opens the help menu +- $blue /servers$ - Opens the server menu +- $blue /rules$ - Grants this book +- $blue /options$ - Opens the player options menu +- $blue /tpa$ - Sends a teleport request to another player +- $blue /rtp$ - Start a random teleport +- $blue /pw$ - Opens the playerwarps personal home menu +- $blue /helpme$ - Pings an online staff member for assistance + +--- + +## $dark_purple Trading Commands$ + +- $blue /bal$ - Check your balance +- $blue /pay$ - Pay another player +- $blue /sell$ - Sell the item in your hand to the server +- $blue /worth$ - Shows the item price when selling to the server +- $blue /value$ - Shows the average selling price for an item in player shops + +--- + +## $dark_aqua Extra Commands$ + +- $blue /donate, /vip$ - Gives link to the server Patreon page +- $blue /discord$ - Gives link to the server Discord +- $blue /twitter, /twitch$ - Gives social media links +- $blue /merch$ - Gives merch link +- $blue /afk$ - Set your status to AFK + +--- + +## $light_purple Getting Help$ + +If you ever need help getting your way around the server, please ask any staff! +**$blue /helpme$** + +Please join the Discord server to get technical help! **$blue /discord$** + +Please report any bugs, griefing, etc. that you come across or are a victim of. +A staff member will be happy to assist you. The help menu has shortcuts that +make getting help easy! **$blue /help$** + +--- + +## $gold Credits$ + +$dark_purple **dddMC**$ is fully funded through player donations. Please consider helping +support us on Patreon! $blue **/donate /patreon**$ + +Patrons will receive a VIP rank. More +ranks will be added in the future. + +We hope you enjoy your time playing on the server! + +\- Stixil, $dark_purple **dddMC 2020**$ From 97d0c6fbb13478c687ddeae85821569bd392e1a4 Mon Sep 17 00:00:00 2001 From: Matt <25674682+spazzylemons@users.noreply.github.com> Date: Thu, 10 Dec 2020 10:31:05 -0500 Subject: [PATCH 2/7] Fix permission --- .../com/dumbdogdiner/stickycommands/commands/RulesCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java b/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java index a781505..23d7b26 100644 --- a/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java +++ b/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java @@ -22,7 +22,7 @@ import java.util.List; public class RulesCommand { - public static final String PERMISSION = "apitestplugin.rules"; + public static final String PERMISSION = "stickycommands.rules"; public static void build(Plugin owner) { new CommandBuilder("rules") From 528c2ee69e76be47a8d533099503d8f11acdea80 Mon Sep 17 00:00:00 2001 From: Matt <25674682+spazzylemons@users.noreply.github.com> Date: Thu, 10 Dec 2020 10:46:04 -0500 Subject: [PATCH 3/7] Remove redundant checks in /rules --- .../stickycommands/commands/RulesCommand.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java b/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java index 23d7b26..b1092ba 100644 --- a/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java +++ b/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java @@ -32,14 +32,6 @@ public static void build(Plugin owner) { .requiresPlayer(true) .onTabComplete((sender, s, arguments) -> Collections.emptyList()) .onExecute((sender, arguments, vars) -> { - if (!sender.hasPermission(PERMISSION)) { - return ExitCode.EXIT_PERMISSION_DENIED; - } - - if (!(sender instanceof Player)) { - return ExitCode.EXIT_MUST_BE_PLAYER; - } - try { ((Player) sender).getInventory().addItem(generateDefault()); } catch (IOException e) { From 16d66f478984887be30e80a0a1d9e863c74e7e63 Mon Sep 17 00:00:00 2001 From: Matt <25674682+spazzylemons@users.noreply.github.com> Date: Thu, 10 Dec 2020 12:31:38 -0500 Subject: [PATCH 4/7] Fix saving rulebook.md resource --- .../stickycommands/commands/RulesCommand.java | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java b/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java index b1092ba..a253a4b 100644 --- a/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java +++ b/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java @@ -14,6 +14,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.commonmark.node.Document; import org.commonmark.parser.Parser; @@ -68,20 +69,7 @@ private static Reader getRulebookReader() { var dataFolder = plugin.getDataFolder(); var rulebook = new File(dataFolder, "rulebook.md"); if (!rulebook.exists()) { - if (!dataFolder.mkdirs() || !rulebook.createNewFile()) { - throw new IOException("Could not save default rulebook to data folder"); - } - try (var writer = new FileOutputStream(rulebook)) { - try (var defaultRulebook = plugin.getResource("rulebook.md")) { - if (defaultRulebook == null) throw new IllegalStateException("No rulebook in the resources!"); - byte[] bytes; - do { - bytes = defaultRulebook.readNBytes(2048); - writer.write(bytes); - } while (bytes.length > 0); - writer.write(defaultRulebook.read()); - } - } + plugin.saveResource("rulebook.md", true); return new FileReader(rulebook); } } catch (Exception e) { From e163bb3eaaa0485b104ea0d4149ccfc9ace6465b Mon Sep 17 00:00:00 2001 From: Matt <25674682+spazzylemons@users.noreply.github.com> Date: Thu, 10 Dec 2020 13:28:06 -0500 Subject: [PATCH 5/7] Add option in config for loading rulebook from a web server --- .../stickycommands/commands/RulesCommand.java | 14 +++++++++++--- src/main/resources/config.yml | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java b/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java index a253a4b..e849149 100644 --- a/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java +++ b/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java @@ -19,11 +19,14 @@ import org.commonmark.parser.Parser; import java.io.*; +import java.net.URL; import java.util.Collections; import java.util.List; public class RulesCommand { public static final String PERMISSION = "stickycommands.rules"; + public static final String RULEBOOK_LOCAL_FILENAME = "rulebook.md"; + public static final String RULEBOOK_URL_CONFIG_PATH = "rulebook-url"; public static void build(Plugin owner) { new CommandBuilder("rules") @@ -64,18 +67,23 @@ public static void build(Plugin owner) { } private static Reader getRulebookReader() { - StickyCommands plugin = StickyCommands.getInstance(); + var plugin = StickyCommands.getInstance(); try { + var configUrl = plugin.getConfig().getString(RULEBOOK_URL_CONFIG_PATH); + if (configUrl != null) { + var url = new URL(configUrl); + return new InputStreamReader(url.openStream()); + } var dataFolder = plugin.getDataFolder(); var rulebook = new File(dataFolder, "rulebook.md"); if (!rulebook.exists()) { - plugin.saveResource("rulebook.md", true); + plugin.saveResource(RULEBOOK_LOCAL_FILENAME, true); return new FileReader(rulebook); } } catch (Exception e) { e.printStackTrace(); } - var resource = plugin.getResource("rulebook.md"); + var resource = plugin.getResource(RULEBOOK_LOCAL_FILENAME); if (resource == null) { return new StringReader("The rulebook could not be loaded."); } else { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index cc1b24d..ce20038 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -17,6 +17,9 @@ debug: false #The name of the server StickyCommands is running on server: "lobby" +# If the rulebook is hosted online, put its URL here, otherwise, leave blank and rulebook.md in the config will be loaded. +rulebook-url: + database: host: localhost port: 3306 From 7f207c12625e36024ed2e7f2ea69da8eadf83285 Mon Sep 17 00:00:00 2001 From: Matt <25674682+spazzylemons@users.noreply.github.com> Date: Thu, 10 Dec 2020 13:37:47 -0500 Subject: [PATCH 6/7] Modify RulesCommand to extend StickyPluginCommand --- .../stickycommands/StickyCommands.java | 2 +- .../stickycommands/commands/RulesCommand.java | 76 +++++++++---------- 2 files changed, 36 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/dumbdogdiner/stickycommands/StickyCommands.java b/src/main/java/com/dumbdogdiner/stickycommands/StickyCommands.java index 62a9dd8..4256e42 100644 --- a/src/main/java/com/dumbdogdiner/stickycommands/StickyCommands.java +++ b/src/main/java/com/dumbdogdiner/stickycommands/StickyCommands.java @@ -222,7 +222,7 @@ boolean registerCommands() { commandList.add(new PowerToolCommand(this)); commandList.add(new PlayerTimeCommand(this)); commandList.add(new SmiteCommand(this)); - RulesCommand.build(this); + commandList.add(new RulesCommand(this)); CommandUtil.registerCommands(getServer(), commandList); return true; diff --git a/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java b/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java index e849149..db142e7 100644 --- a/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java +++ b/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java @@ -1,7 +1,9 @@ package com.dumbdogdiner.stickycommands.commands; -import com.dumbdogdiner.stickyapi.bukkit.command.builder.CommandBuilder; +import com.dumbdogdiner.stickyapi.bukkit.command.StickyPluginCommand; import com.dumbdogdiner.stickyapi.bukkit.item.generator.BookGenerator; +import com.dumbdogdiner.stickyapi.bukkit.plugin.StickyPlugin; +import com.dumbdogdiner.stickyapi.common.arguments.Arguments; import com.dumbdogdiner.stickyapi.common.book.chat.JsonComponent; import com.dumbdogdiner.stickyapi.common.book.commonmarkextensions.JsonComponentWriter; import com.dumbdogdiner.stickyapi.common.book.commonmarkextensions.MCFormatExtension; @@ -9,61 +11,36 @@ import com.dumbdogdiner.stickyapi.common.command.ExitCode; import com.dumbdogdiner.stickyapi.common.util.BookUtil; import com.dumbdogdiner.stickycommands.StickyCommands; -import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.command.CommandException; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.permissions.Permission; import org.commonmark.node.Document; import org.commonmark.parser.Parser; +import org.jetbrains.annotations.NotNull; import java.io.*; import java.net.URL; import java.util.Collections; import java.util.List; +import java.util.Map; -public class RulesCommand { +public class RulesCommand extends StickyPluginCommand { public static final String PERMISSION = "stickycommands.rules"; public static final String RULEBOOK_LOCAL_FILENAME = "rulebook.md"; public static final String RULEBOOK_URL_CONFIG_PATH = "rulebook-url"; - public static void build(Plugin owner) { - new CommandBuilder("rules") - .description("Get a copy of the the server's rules") - .permission(PERMISSION) - .alias("rulebook") - .requiresPlayer(true) - .onTabComplete((sender, s, arguments) -> Collections.emptyList()) - .onExecute((sender, arguments, vars) -> { - try { - ((Player) sender).getInventory().addItem(generateDefault()); - } catch (IOException e) { - e.printStackTrace(); - return ExitCode.EXIT_ERROR; - } - - return ExitCode.EXIT_SUCCESS; - }) - .onError((exitCode, sender, arguments, vars) -> { - var provider = StickyCommands.getInstance().getLocaleProvider(); - switch (exitCode) { - case EXIT_PERMISSION_DENIED: - sender.sendMessage(provider.translate("no-permission", vars)); - break; - case EXIT_MUST_BE_PLAYER: - sender.sendMessage(provider.translate("must-be-player", vars)); - break; - case EXIT_ERROR: - sender.sendMessage(provider.translate("server-error", vars)); - break; - case EXIT_SUCCESS: - break; - default: - sender.sendMessage(ChatColor.RED + "Exited with " + exitCode); - } - }) - .register(owner); + public RulesCommand(@NotNull StickyPlugin owner) { + super( + /* name: */ "rules", + /* aliases: */ Collections.singletonList("rulebook"), + /* owner: */ owner, + /* permission: */ new Permission(PERMISSION) + ); + // settings not settable in super call + requiresPlayer = true; } private static Reader getRulebookReader() { @@ -116,4 +93,21 @@ private static JsonComponent renderDocument(Document document) { new MarkdownJsonRenderer(writer).render(document); return component; } + + @Override + public ExitCode execute(@NotNull CommandSender commandSender, @NotNull String s, @NotNull Arguments arguments, @NotNull Map map) { + try { + ((Player) commandSender).getInventory().addItem(generateDefault()); + } catch (IOException e) { + e.printStackTrace(); + return ExitCode.EXIT_ERROR; + } + + return ExitCode.EXIT_SUCCESS; + } + + @Override + public @NotNull List tabComplete(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) throws IllegalArgumentException, CommandException { + return Collections.emptyList(); + } } From 337054d0494289c0ee3d147805c2b24240a45ea8 Mon Sep 17 00:00:00 2001 From: Matt <25674682+spazzylemons@users.noreply.github.com> Date: Thu, 10 Dec 2020 13:52:52 -0500 Subject: [PATCH 7/7] Add title and author of rulebook to config --- .../stickycommands/commands/RulesCommand.java | 13 ++++++++++++- src/main/resources/config.yml | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java b/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java index db142e7..488f4e2 100644 --- a/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java +++ b/src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java @@ -3,12 +3,14 @@ import com.dumbdogdiner.stickyapi.bukkit.command.StickyPluginCommand; import com.dumbdogdiner.stickyapi.bukkit.item.generator.BookGenerator; import com.dumbdogdiner.stickyapi.bukkit.plugin.StickyPlugin; +import com.dumbdogdiner.stickyapi.bukkit.util.ServerUtil; import com.dumbdogdiner.stickyapi.common.arguments.Arguments; import com.dumbdogdiner.stickyapi.common.book.chat.JsonComponent; import com.dumbdogdiner.stickyapi.common.book.commonmarkextensions.JsonComponentWriter; import com.dumbdogdiner.stickyapi.common.book.commonmarkextensions.MCFormatExtension; import com.dumbdogdiner.stickyapi.common.book.commonmarkextensions.MarkdownJsonRenderer; import com.dumbdogdiner.stickyapi.common.command.ExitCode; +import com.dumbdogdiner.stickyapi.common.translation.Translation; import com.dumbdogdiner.stickyapi.common.util.BookUtil; import com.dumbdogdiner.stickycommands.StickyCommands; import org.bukkit.Material; @@ -69,8 +71,17 @@ private static Reader getRulebookReader() { } private static ItemStack generateDefault() throws IOException { + var config = StickyCommands.getInstance().getConfig(); + var title = config.getString("rulebook-title"); + if (title == null) title = "&ddddMC Survival Handbook"; + var author = config.getString("rulebook-author"); + if (author == null) author = "Stixil"; try (var reader = getRulebookReader()) { - return generate(reader, "§ddddMC Survival Handbook", "Stixil"); + return generate( + reader, + Translation.translateColors("&", title), + Translation.translateColors("&", author) + ); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ce20038..6959560 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -19,6 +19,10 @@ server: "lobby" # If the rulebook is hosted online, put its URL here, otherwise, leave blank and rulebook.md in the config will be loaded. rulebook-url: +# The title of the rulebook +rulebook-title: "&dddMC Survival Handbook" +# The author of the rulebook +rulebook-author: Stixil database: host: localhost