Skip to content

Commit

Permalink
Cleanup the config
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Aug 4, 2020
1 parent 1907d0e commit 19556b9
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 132 deletions.
Expand Up @@ -50,7 +50,7 @@ public static void main(String[] args) {

ConfigurationGenerator.generateDefaultConfiguration();
MechanicTypesGenerator.generateMechanicTypes();
CommandDocumentationGenerator.generateCommandDocumentation();
// CommandDocumentationGenerator.generateCommandDocumentation();
// MechanicConfigurationGenerator.generateMechanicConfiguration();
}
}
Expand Up @@ -16,10 +16,10 @@

package com.sk89q.craftbook;

import com.google.common.collect.Lists;
import com.sk89q.craftbook.bukkit.CraftBookPlugin;
import com.sk89q.util.yaml.YAMLFormat;
import com.sk89q.util.yaml.YAMLProcessor;
import org.apache.commons.lang.StringUtils;
import org.bukkit.entity.Player;

import java.io.File;
Expand Down Expand Up @@ -47,7 +47,7 @@ public void close() {

private void checkForLanguages() {

for (String language : CraftBook.getInstance().getPlatform().getConfiguration().languages) {
for (String language : Lists.newArrayList("en_US")) {
language = language.trim();
File f = new File(CraftBookPlugin.inst().getDataFolder(), language + ".yml");
if(!f.exists())
Expand Down Expand Up @@ -81,19 +81,11 @@ public String getString(String message, String language) {

//message = ChatColor.stripColor(message);
if(language == null || !languageMap.containsKey(language.toLowerCase()))
language = CraftBook.getInstance().getPlatform().getConfiguration().language;
language = "en_US";
YAMLProcessor languageData = languageMap.get(language.toLowerCase());
String def = defaultMessages.get(message);
if(languageData == null) {
if(!CraftBook.getInstance().getPlatform().getConfiguration().languageScanText || def != null) {
return def == null ? message : def;
} else {
String trans = message;
for(Entry<String, String> tran : defaultMessages.entrySet()) {
trans = StringUtils.replace(trans, tran.getKey(), tran.getValue());
}
return trans;
}
return def == null ? message : def;
} else {
String translated;
if(def == null || languageData.getString(message) != null)
Expand All @@ -102,20 +94,10 @@ public String getString(String message, String language) {
translated = languageData.getString(message, def);
}

if(!CraftBook.getInstance().getPlatform().getConfiguration().languageScanText || translated != null) {
if(translated != null)
return translated;
else
return def == null ? message : def;
} else {
String trans = message;
for(String tran : languageData.getMap().keySet()) {
String trand = defaultMessages.get(tran) != null ? languageData.getString(tran, defaultMessages.get(tran)) : languageData.getString(tran);
if(tran == null || trand == null) continue;
trans = StringUtils.replace(trans, tran, trand);
}
return trans;
}
if(translated != null)
return translated;
else
return def == null ? message : def;
}
}

Expand Down
Expand Up @@ -42,7 +42,7 @@ public void load() {
e.printStackTrace();
}

if(config.getNode("enabled-mechanics") != null) {
if(config.getList("enabled-mechanics") != null) {
try {
Files.move(
CraftBook.getInstance().getPlatform().getConfigDir().resolve("config.yml"),
Expand Down Expand Up @@ -109,15 +109,6 @@ public void load() {
config.setComment("sign-click-timeout", "Make sure a player can only press signs so often.");
signClickTimeout = config.getInt("sign-click-timeout", 10);

config.setComment("language", "The default language for CraftBook. Note: This language needs to be in the 'languages' field for this to work.");
language = config.getString("language", "en_US");

config.setComment("languages", "A list of languages supported by craftbook, if a user requests a language not listed... They will see default.");
languages = config.getStringList("languages", Collections.singletonList("en_US"));

config.setComment("scan-text-for-localization", "If enabled, CraftBook will scan messages sent to players for localizable text, instead of just checking if the entire message is localizable.");
languageScanText = config.getBoolean("scan-text-for-localization", false);

config.setComment("debug-mode", "Enable a mode that will print extra debug information to the console.");
debugMode = config.getBoolean("debug-mode", false);

Expand All @@ -133,9 +124,6 @@ public void load() {
config.setComment("persistent-storage-type", "PersistentStorage stores data that can be accessed across server restart. Method of PersistentStorage storage (Note: DUMMY is practically off, and may cause issues). Can currently be any of the following: YAML, DUMMY, SQLite");
persistentStorageType = config.getString("persistent-storage-type", "YAML");

config.setComment("convert-names-to-cbids", "Causes mechanics to attempt to convert names to use CBIDs. This can and should be disabled after you believe your servers transition to UUIDs v Names is complete.");
convertNamesToCBID = config.getBoolean("convert-names-to-cbids", false);

config.save();
}

Expand Down
Expand Up @@ -30,16 +30,11 @@
import com.sk89q.craftbook.util.events.SelfTriggerPingEvent;
import com.sk89q.craftbook.util.events.SignClickEvent;
import com.sk89q.craftbook.util.events.SourcedBlockRedstoneEvent;
import com.sk89q.craftbook.util.profile.Profile;
import com.sk89q.craftbook.util.profile.resolver.HttpRepositoryService;
import com.sk89q.craftbook.util.profile.resolver.ProfileService;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
Expand Down Expand Up @@ -179,25 +174,6 @@ private static boolean isValidArea(ChangedSign sign) {

String namespace = sign.getLine(0).trim();

if(CraftBook.getInstance().getPlatform().getConfiguration().convertNamesToCBID
&& namespace.startsWith("~") && CraftBookPlugin.inst().getUUIDMappings().getUUID(namespace.replace("~", "")) == null) {
OfflinePlayer player = Bukkit.getOfflinePlayer(namespace.replace("~", ""));
if(player.hasPlayedBefore()) {
String originalNamespace = namespace;

try {
ProfileService resolver = HttpRepositoryService.forMinecraft();
Profile profile = resolver.findByName("player.getName()"); // May be null

namespace = '~' + CraftBookPlugin.inst().getUUIDMappings().getCBID(profile.getUniqueId());
CopyManager.renameNamespace(CraftBookPlugin.inst().getDataFolder(), originalNamespace, namespace);
sign.setLine(0, namespace);
} catch (Exception e) {
e.printStackTrace();
}
}
}

return isValidArea(namespace, sign.getLine(2).trim().toLowerCase(Locale.ENGLISH), sign.getLine(3).trim().toLowerCase(Locale.ENGLISH));
}

Expand Down
Expand Up @@ -32,16 +32,10 @@

package com.sk89q.craftbook.mechanics.ic.gates.world.miscellaneous;

import java.util.UUID;

import com.sk89q.craftbook.CraftBook;
import com.sk89q.craftbook.CraftBookPlayer;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;

import com.sk89q.craftbook.ChangedSign;
import com.sk89q.craftbook.bukkit.CraftBookPlugin;
import com.sk89q.craftbook.mechanics.ic.AbstractICFactory;
import com.sk89q.craftbook.mechanics.ic.AbstractSelfTriggeredIC;
import com.sk89q.craftbook.mechanics.ic.ChipState;
Expand All @@ -50,9 +44,6 @@
import com.sk89q.craftbook.mechanics.ic.ICFactory;
import com.sk89q.craftbook.mechanics.ic.ICMechanic;
import com.sk89q.craftbook.mechanics.ic.ICVerificationException;
import com.sk89q.craftbook.util.profile.Profile;
import com.sk89q.craftbook.util.profile.resolver.HttpRepositoryService;
import com.sk89q.craftbook.util.profile.resolver.ProfileService;
import com.sk89q.util.yaml.YAMLProcessor;

public class WirelessReceiver extends AbstractSelfTriggeredIC {
Expand All @@ -69,23 +60,6 @@ public void load() {

band = getSign().getLine(2);
if (!getLine(3).trim().isEmpty()) {
if(CraftBook.getInstance().getPlatform().getConfiguration().convertNamesToCBID && CraftBookPlugin.inst().getUUIDMappings().getUUID(getLine(3)) == null) {
String line3 = getLine(3);
OfflinePlayer player = Bukkit.getOfflinePlayer(getLine(3));
if(player.hasPlayedBefore()) {
try {
ProfileService resolver = HttpRepositoryService.forMinecraft();
Profile profile = resolver.findByName(player.getName()); // May be null

UUID uuid = profile.getUniqueId();
band = CraftBookPlugin.inst().getUUIDMappings().getCBID(uuid);
getSign().setLine(3, line3);
getSign().update(false);
} catch (Exception e) {
e.printStackTrace();
}
}
}
band = band + getSign().getLine(3);
}
}
Expand Down
Expand Up @@ -38,12 +38,8 @@
import java.io.IOException;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.UUID;

import com.sk89q.craftbook.CraftBook;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;

Expand All @@ -61,9 +57,6 @@
import com.sk89q.craftbook.mechanics.ic.ICVerificationException;
import com.sk89q.craftbook.mechanics.ic.PersistentDataIC;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.craftbook.util.profile.Profile;
import com.sk89q.craftbook.util.profile.resolver.HttpRepositoryService;
import com.sk89q.craftbook.util.profile.resolver.ProfileService;
import com.sk89q.util.yaml.YAMLProcessor;

public class WirelessTransmitter extends AbstractIC {
Expand All @@ -82,23 +75,6 @@ public void load() {

band = getSign().getLine(2);
if (!getLine(3).trim().isEmpty()) {
if(CraftBook.getInstance().getPlatform().getConfiguration().convertNamesToCBID && CraftBookPlugin.inst().getUUIDMappings().getUUID(getLine(3)) == null) {
String line3 = getLine(3);
OfflinePlayer player = Bukkit.getOfflinePlayer(getLine(3));
if(player.hasPlayedBefore()) {
try {
ProfileService resolver = HttpRepositoryService.forMinecraft();
Profile profile = resolver.findByName(player.getName()); // May be null

UUID uuid = profile.getUniqueId();
band = CraftBookPlugin.inst().getUUIDMappings().getCBID(uuid);
getSign().setLine(3, line3);
getSign().update(false);
} catch (Exception e) {
e.printStackTrace();
}
}
}
band = band + getSign().getLine(3);
}
}
Expand Down
13 changes: 0 additions & 13 deletions craftbook-bukkit/src/main/resources/defaults/config.yml
Expand Up @@ -120,16 +120,6 @@ pedantic-block-checks: false
# Make sure a player can only press signs so often.
sign-click-timeout: 10

# The default language for CraftBook. Note: This language needs to be in the 'languages' field for this to work.
language: en_US

# A list of languages supported by craftbook, if a user requests a language not listed... They will see default.
languages:
- en_US

# If enabled, CraftBook will scan messages sent to players for localizable text, instead of just checking if the entire message is localizable.
scan-text-for-localization: false

# Enable a mode that will print extra debug information to the console.
debug-mode: false

Expand All @@ -144,6 +134,3 @@ show-permission-messages: true

# PersistentStorage stores data that can be accessed across server restart. Method of PersistentStorage storage (Note: DUMMY is practically off, and may cause issues). Can currently be any of the following: YAML, DUMMY, SQLite
persistent-storage-type: YAML

# Causes mechanics to attempt to convert names to use CBIDs. This can and should be disabled after you believe your servers transition to UUIDs v Names is complete.
convert-names-to-cbids: false
Expand Up @@ -38,11 +38,6 @@ public abstract class YamlConfiguration {
public boolean pedanticBlockChecks;
public boolean showPermissionMessages;
public long signClickTimeout;
public boolean convertNamesToCBID;

public String language;
public List<String> languages;
public boolean languageScanText;

public boolean debugMode;
public boolean debugLogToFile;
Expand Down

0 comments on commit 19556b9

Please sign in to comment.