Skip to content
Permalink
Browse files

Fixed a few potential issues with Variables.

  • Loading branch information...
me4502 committed Sep 21, 2019
1 parent ace04c5 commit b27b536517cd5d1ca09eb8f12f12ffc809e10af5
@@ -138,13 +138,13 @@ public void list(CommandContext context, CommandSender sender) throws CommandExc
List<String> variablesLines = new ArrayList<>();

for (Entry<Tuple2<String, String>, String> entry : VariableManager.instance.getVariableStore().entrySet()) {
if (key != null && !entry.getKey().a.equals(key)) {
if (key != null && !entry.getKey().b.equals(key)) {
continue;
}

String keyName = entry.getKey().b;
String keyName = entry.getKey().a;
if (key == null) {
keyName = entry.getKey().a + '|' + keyName;
keyName = entry.getKey().b + '|' + keyName;
}

variablesLines.add(ChatColor.YELLOW + keyName + ChatColor.WHITE + ": " + ChatColor.GREEN + entry.getValue());
@@ -42,9 +42,9 @@ public void load() {
for(String key : config.getKeys("variables")) {

String[] keys = RegexUtil.PIPE_PATTERN.split(key, 2);
if(keys.length == 1)
keys = new String[]{"global",key};
else if (CraftBookPlugin.inst().getConfiguration().convertNamesToCBID) {
if(keys.length == 1) {
keys = new String[]{"global", key};
} else if (CraftBookPlugin.inst().getConfiguration().convertNamesToCBID) {
if(CraftBookPlugin.inst().getUUIDMappings().getUUID(keys[0]) != null) continue;
OfflinePlayer player = Bukkit.getOfflinePlayer(keys[0]);
if(player.hasPlayedBefore()) {
@@ -61,8 +61,10 @@ else if (CraftBookPlugin.inst().getConfiguration().convertNamesToCBID) {
}
}

if(RegexUtil.VARIABLE_KEY_PATTERN.matcher(keys[0]).find() && RegexUtil.VARIABLE_KEY_PATTERN.matcher(keys[1]).find() && RegexUtil.VARIABLE_VALUE_PATTERN.matcher(String.valueOf(config.getProperty("variables." + key))).find()) {
VariableManager.instance.setVariable(keys[1], keys[0], String.valueOf(config.getProperty("variables." + key)));
String value = String.valueOf(config.getProperty("variables." + key));

if(RegexUtil.VARIABLE_KEY_PATTERN.matcher(keys[1]).find() && RegexUtil.VARIABLE_VALUE_PATTERN.matcher(value).find()) {
VariableManager.instance.setVariable(keys[1], keys[0], value);
}
}

@@ -76,7 +78,7 @@ public void save() {

for(Entry<Tuple2<String, String>, String> var : VariableManager.instance.getVariableStore().entrySet()) {

if(RegexUtil.VARIABLE_KEY_PATTERN.matcher(var.getKey().a).find() && RegexUtil.VARIABLE_KEY_PATTERN.matcher(var.getKey().b).find() && RegexUtil.VARIABLE_VALUE_PATTERN.matcher(var.getValue()).find())
if(RegexUtil.VARIABLE_KEY_PATTERN.matcher(var.getKey().a).find() && RegexUtil.VARIABLE_VALUE_PATTERN.matcher(var.getValue()).find())
config.setProperty("variables." + var.getKey().b + '|' + var.getKey().a, var.getValue());
}
config.save();
@@ -81,8 +81,6 @@ public static String parseVariables(String line, CommandSender player) {
if(CraftBookPlugin.inst() == null || VariableManager.instance == null || VariableManager.instance.getVariableStore().isEmpty())
return line;

CraftBookPlugin.logDebugMessage("Attempting to parse variables. Input line: " + line, "variables.line-parsing");

for(String var : getPossibleVariables(line)) {

CraftBookPlugin.logDebugMessage("Possible variable: " + var + " detected!", "variables.line-parsing");
@@ -111,8 +109,9 @@ public static String parseVariables(String line, CommandSender player) {
CraftBookPlugin.logDebugMessage(var + " permissions granted!", "variables.line-parsing");

for(Entry<Tuple2<String, String>, String> bit : VariableManager.instance.getVariableStore().entrySet()) {
if(bit.getKey().b.equals(key) && bit.getKey().a.equals(value))
if(bit.getKey().b.equals(key) && bit.getKey().a.equals(value)) {
line = StringUtils.replace(line, "%" + var + "%", bit.getValue());
}
}
}

@@ -153,4 +153,4 @@ show-permission-messages: true
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: true
convert-names-to-cbids: false

0 comments on commit b27b536

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