-
Notifications
You must be signed in to change notification settings - Fork 2
Add /rules to rewrite #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
spazzylemons
wants to merge
7
commits into
SolteraGG:rewrite
Choose a base branch
from
spazzylemons:rewrite
base: rewrite
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7d39335
Add /rules to rewrite
spazzylemons 97d0c6f
Fix permission
spazzylemons 528c2ee
Remove redundant checks in /rules
spazzylemons 16d66f4
Fix saving rulebook.md resource
spazzylemons e163bb3
Add option in config for loading rulebook from a web server
spazzylemons 7f207c1
Modify RulesCommand to extend StickyPluginCommand
spazzylemons 337054d
Add title and author of rulebook to config
spazzylemons File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
src/main/java/com/dumbdogdiner/stickycommands/commands/RulesCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 = "stickycommands.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; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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**$ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.