Skip to content
Permalink
Browse files

Add Shulker Box to inventory list, and updated terrible wiki generato…

…r to generate RST
  • Loading branch information...
me4502 committed Jun 20, 2019
1 parent 075c8d5 commit 4c8646a2c2648b4e2e64fdba8618cacc7d099864
@@ -3,12 +3,17 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Map;
import java.util.logging.Level;
import java.util.regex.Matcher;

import com.sk89q.craftbook.CraftBookMechanic;
import com.sk89q.craftbook.bukkit.CraftBookPlugin;
import com.sk89q.craftbook.util.RegexUtil;
import com.sk89q.craftbook.util.developer.ExternalUtilityBase;
import com.sk89q.util.yaml.YAMLProcessor;
import org.bukkit.Bukkit;

public class GenerateWikiConfigLists extends ExternalUtilityBase {

@@ -30,46 +35,85 @@ else if(fpath.contains("."))
file.delete();
file.createNewFile();
}
if (config.getKeys(path) == null) {
return;
}

PrintWriter pw = new PrintWriter(file, "UTF-8");
int lines = 0;

pw.println("== Configuration ==");
pw.println();
pw.println("{| class=\"wiki-table sortable\"");
pw.println("|-");
pw.println("! Configuration Node and Path");
pw.println("! Default Value");
pw.println("! Effect");
pw.print("Configuration\n");
pw.append("=============\n\n");

int nodeLength = "Node".length(), commentLength = "Comment".length(), defaultLength = "Default".length();

for(String key : config.getKeys(path)) {
if(config.getProperty(path == null ? key : path + "." + key) != null && !(config.getProperty(path == null ? key : path + "." + key) instanceof Map)) {
String node = (path == null ? key : path + "." + key);
if (nodeLength < node.length()) {
nodeLength = node.length();
}
String def = String.valueOf(config.getProperty(path == null ? key : path + "." + key));
if (defaultLength < def.length()) {
defaultLength = def.length();
}
String comment = config.getComment(path == null ? key : path + "." + key);
if(comment == null) {
comment = "";
}
if(!comment.trim().isEmpty()) comment = comment.trim().substring(2);
if (commentLength < comment.length()) {
commentLength = comment.length();
}
}
}

String border = createStringOfLength(nodeLength, '=') + ' ' + createStringOfLength(commentLength, '=') + ' ' + createStringOfLength(defaultLength, '=');

pw.println(border);
pw.print(padToLength("Node", nodeLength + 1));
pw.print(padToLength("Comment", commentLength + 1));
pw.println(padToLength("Default", defaultLength + 1));;
pw.println(border);

for(String key : config.getKeys(path)) {
if(config.getProperty(path == null ? key : path + "." + key) != null && !(config.getProperty(path == null ? key : path + "." + key) instanceof Map)) {
pw.println("|-");
pw.println("| " + (path == null ? key : path + "." + key));
pw.println("| " + String.valueOf(config.getProperty(path == null ? key : path + "." + key)));
String comment = config.getComment(path == null ? key : path + "." + key);
if(comment == null) {
System.out.println("[WARNING] Key " + path == null ? key : path + "." + key + " is missing a comment!");
missingComments++;
comment = "";
missingComments ++;
}
if(!comment.trim().isEmpty()) comment = comment.trim().substring(2);
pw.println("| " + comment);
lines++;

pw.print(padToLength((path == null ? key : path + "." + key), nodeLength + 1));
pw.print(padToLength(comment, commentLength + 1));
pw.println(padToLength(String.valueOf(config.getProperty(path == null ? key : path + "." + key)), defaultLength + 1));
} else
createConfigSectionFile(new File(folder, key + "/"), config, path == null ? key : path + "." + key);
}

pw.println("|}");
pw.println(border);

pw.close();

if(lines == 0)
file.delete();
folder.delete(); //Delete if empty.
}

static int missingComments = 0;

public static String createStringOfLength(int length, char character) {
StringBuilder ret = new StringBuilder();

for(int i = 0; i < length; i++)
ret.append(character);

return ret.toString();
}

public static String padToLength(String input, int length) {
StringBuilder builder = new StringBuilder(input);
while(builder.length() < length)
builder.append(' ');
return builder.toString();
}

@Override
public void generate(String[] args) {

@@ -79,6 +123,24 @@ public void generate(String[] args) {
missingComments = 0;
try {
createConfigSectionFile(configFolder, CraftBookPlugin.inst().getConfiguration().config, null);

CraftBookPlugin.availableMechanics.forEach((mech, aClass) -> {
try {
try {
if (aClass != null) {

CraftBookMechanic me = aClass.newInstance();
me.loadConfiguration(CraftBookPlugin.inst().getMechanismsConfig(), "mechanics." + mech + ".");
}
} catch (Throwable t) {
Bukkit.getLogger().log(Level.WARNING, "Failed to load mechanic: " + mech, t);
}

createConfigSectionFile(configFolder, CraftBookPlugin.inst().getMechanismsConfig(), "mechanics." + mech);
} catch (IOException e) {
e.printStackTrace();
}
});
} catch (IOException e) {
e.printStackTrace();
}
@@ -885,6 +885,10 @@ public BukkitConfiguration getConfiguration() {
return config;
}

public YAMLProcessor getMechanismsConfig() {
return this.mechanismsConfig;
}

/**
* This method is used to get the CraftBook {@link LanguageManager}.
*
@@ -285,6 +285,7 @@ public static boolean doesBlockHaveInventory(Block block) {
case LIME_SHULKER_BOX:
case BLACK_SHULKER_BOX:
case RED_SHULKER_BOX:
case SHULKER_BOX:
return true;
default:
return false;

0 comments on commit 4c8646a

Please sign in to comment.
You can’t perform that action at this time.