Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {

allprojects {
group = "com.dumbdogdiner"
version = "3.0.3"
version = "3.0.4a"

// java plugin is applied in subprojects
apply plugin: "jacoco"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*
* @since 2.0
*/
@Deprecated
public class BukkitCommandBuilder extends CommandBuilder<BukkitCommandBuilder> {

// Hmm...
Expand Down
91 changes: 89 additions & 2 deletions bukkit/src/test/resources/rulebook.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,93 @@
{
"pages": [
[
[
{
"text": "Dumb Dog Diner MC\\nSeason 4 Handbook",
"bold": true,
"italic": true,
"color": "dark_purple"
},
{
"text": "\\n\\n",
"color": "reset"
},
{
"text": "Table of Contents:",
"bold": true,
"italic": true,
"underlined": true,
"color": "dark_red"
},
{
"text": "\\n",
"color": "reset"
},
{
"text": "Page 2: ",
"color": "red"
},
{
"text": "Rules\\n",
"color": "reset"
},
{
"text": "Pg. 3: ",
"color": "red"
},
{
"text": "Gameplay\\n",
"color": "reset"
},
{
"text": "Pg. 5: ",
"color": "red"
},
{
"text": "Trading\\n",
"color": "reset"
},
{
"text": "Pg. 7: ",
"color": "red"
},
{
"text": "Commands\\n",
"color": "reset"
},
{
"text": "Pg. 9: ",
"color": "red"
},
{
"text": "Trading\\nCommands\\n",
"color": "reset"
},
{
"text": "Pg. 10: ",
"color": "red"
},
{
"text": "Extras\\n",
"color": "reset"
},
{
"text": "Pg. 11: ",
"color": "red"
},
{
"text": "Getting Help\\n",
"color": "reset"
},
{
"text": "Pg. 13: ",
"color": "red"
},
{
"text": "Credits",
"color": "reset"
}
],
{
"text": "Dumb Dog Diner MC\\nSurvival Handbook",
"bold": true,
Expand Down Expand Up @@ -444,14 +531,14 @@
],
"title": "\u0026ddddMC Survival Handbook v1.0",
"author": "Stixil",
"lore" : [
"lore": [
{
"text": "dddMC 2020",
"bold": true,
"color": "dark_purple"
},
{
"text" : "",
"text": "",
"color": "reset"
}
]
Expand Down
3 changes: 2 additions & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ dependencies {
// Font width data (see above)
dddResource "dumbdogdiner:mc-font-extractor:main:mojangles_width_data@json"

implementation "com.google.code.gson:gson:2.8.7"
// Expose newer gson
api "com.google.code.gson:gson:2.8.7"

// Dependencies available in both bukkit and bungee
compileOnly "net.md-5:bungeecord-chat:1.16-R0.5-SNAPSHOT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package com.dumbdogdiner.stickyapi.common.translation;

import java.io.File;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Map;
import java.util.TreeMap;
Expand Down Expand Up @@ -269,7 +270,7 @@ private void checkForLoadedLocale(@NotNull String name) throws IllegalArgumentEx
*
* @return {@link java.util.TreeMap}
*/
public TreeMap<String, String> newVariables() {
return new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
public static Map<String, String> newVariables() {
return new HashMap<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.dumbdogdiner.stickyapi.common.util.Debugger;
Expand Down Expand Up @@ -130,6 +131,10 @@ public void testTranslate() {

// Translate changes & to § for ChatColor codes
assertEquals("Msg>§cError! The player Notch has not joined before!", output);
Map<String, String> vars2 = localeProviderGroup1.newVariables();
vars2.put("player", "Rodwuff");
System.out.println(
localeProviderGroup1.translate("afk.afk-m", vars2));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ player-has-not-joined: "{prefix}&cError! The player {target} has not joined befo
must-be-player: "{prefix}&cYou must be a player to execute this command!"
not-online-player: "{prefix}&c Error! {player} is not online!"
invalid-group: "{prefix}&cError! Group {GROUP} is invalid!"
afk:
not-afk: "&7&o* {player} is no longer AFK!"
afk-m: "&7&o* {player} is now AFK!"
afk-kick: "&cYou have been AFK for {time|duration} and have been kicked!"

# The config supports new lines (\n), it can be used on any node
whois-message: "{prefix}&bWhois data for {target}\n{newline}&b{target_online|yesno:'&aOnline,&cOffline'} &bsince: &f{target_last_seen|expiry}\n{newline}&bIP: &f{target_ipaddress}\n{newline}&bFirst Login: &f{target_first_seen|expiry}\n{newline}&bLast Login: &f{target_last_seen|expiry}\n{newline}&bLast Server: &f{target_last_server}\n{newline}&bFly/Walk: &f{target_fly_speed}&b / &f{target_walk_speed}"
Expand Down Expand Up @@ -51,10 +55,8 @@ sell:
no-sales: "{prefix}&bThere have been no sales!"
paginator: "{prefix}&bpage &f{current}&b/&f{total}"

afk:
not-afk: "&7&o* {player} is no longer AFK!"
afk: "&7&o* {player} is now AFK!"
afk-kick: "&cYou have been AFK for {time|duration} and have been kicked!"



hat:
no-hat: "{prefix}&bYou do not have a hat!"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@ public interface Configuration {
* @return The requested string.
*/
public String getString(String path, String def);

/**
* Gets the given string from the path.
* @param path The path of the string to get
* @return The requested string, or null.
*/
public String getString(String path);

Double getDouble(String path);

double getDouble(String path, double def);

Integer getInt(String path);

int getInt(String path, int def);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import com.dumbdogdiner.stickyapi.common.config.FileConfiguration;

import org.apache.commons.lang.Validate;
import org.jetbrains.annotations.Nullable;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;

public class YamlProvider implements FileConfiguration {

private ConcurrentHashMap<String, Object> data;

private InputStream inputStream;
Expand Down Expand Up @@ -50,16 +55,88 @@ public void reload() {

@Override
public String getString(String path, String def) {
Object value = this.data.get(path);
return (value != null) ? value.toString() : def;
return getAs(path, def);
}

@Override
public String getString(String path) {
Object value = this.data.get(path);
Object value = get(path);
return (value != null) ? value.toString() : null;
}

@Override
public Double getDouble(String path) {
Object value = get(path);
return (value instanceof Double) ? (double) value : null;
}

@Override
public double getDouble(String path, double def) {
return Objects.requireNonNullElse(getDouble(path), def);
}

@Override
public Integer getInt(String path) {
Object value = get(path);
return (value instanceof Integer) ? (int) value : null;
}

@Override
public int getInt(String path, int def) {
return Objects.requireNonNullElse(getInt(path), def);
}

/**
* Gets a generic type from the configuration
* @param path The path of the object to get in the configuration
* @param def The default value
* @param <T> The type of the object to get
* @return The requested object, or the default value
*/
public <T> T getAs(String path, T def){
Object value = get(path);
try {
return value != null ? (T) value : def;
} catch (ClassCastException e) {
return def;
}
}

/**
* Generalized convinience version of {@link #get(String, Map)}
* @param path The path of the object
* @return The value at the key of the path
*/
private @Nullable Object get(String path){
return get(path, data);
}

/**
* Internal method to deal with recursive, nested map params
* @param path The path of the object
* @param map The map we are working with
* @return The value of that key at the path
*/
private @Nullable Object get(String path, Map<String, ?> map){
if(path == null)
return null;
// Split off the head of a path, if it exists
String [] splitPath = path.split("\\.", 2);
if(splitPath.length == 2 && map.containsKey(splitPath[0]) && map.get(splitPath[0]) instanceof Map){
return get(splitPath[1], (Map<String, ?>) map.get(splitPath[0]));
}

return map.containsKey(splitPath[0]) ? map.get(splitPath[0]) : null;
}

/**
* Gets a {@link Set<String>} of all of the paths that were loaded
* @return A set of all loaded paths
*/
public Set<String> getPaths(){
return new HashSet<>(Collections.list(data.keys()));
}

@Override
public boolean save(String path) {
FileWriter fileWriter;
Expand Down