Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
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)) {
Comment thread
jcxldn marked this conversation as resolved.
Outdated
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;
}
}
97 changes: 97 additions & 0 deletions src/main/resources/rulebook.md
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**$