diff --git a/plugin.yml b/plugin.yml index c96418e..73914ee 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,6 +2,6 @@ name: skript-yaml author: Sashie description: The proper way to do yaml in skript api-version: 1.13 -version: 1.3 +version: 1.3.1 main: me.sashie.skriptyaml.SkriptYaml depend: [Skript] \ No newline at end of file diff --git a/src/me/sashie/skriptyaml/SkriptYaml.java b/src/me/sashie/skriptyaml/SkriptYaml.java index d1d632f..6935c3f 100644 --- a/src/me/sashie/skriptyaml/SkriptYaml.java +++ b/src/me/sashie/skriptyaml/SkriptYaml.java @@ -67,6 +67,9 @@ public static boolean isTagRegistered(String tag) { * */ public static void registerTag(JavaPlugin plugin, String tag, Class c, RepresentedClass rc, ConstructedClass cc) { + String prefix = plugin.getName().toLowerCase() + "-"; + if (!tag.startsWith(prefix)) + tag = prefix + tag; if (!REGISTERED_TAGS.containsKey(tag)) { if (!representer.contains(c)) { if (SkriptYamlUtils.getType(rc.getClass()) == c) { diff --git a/src/me/sashie/skriptyaml/skript/CondNodeHasList.java b/src/me/sashie/skriptyaml/skript/CondNodeHasList.java index e32210d..87979cb 100644 --- a/src/me/sashie/skriptyaml/skript/CondNodeHasList.java +++ b/src/me/sashie/skriptyaml/skript/CondNodeHasList.java @@ -37,16 +37,16 @@ public class CondNodeHasList extends Condition { } private Expression path; - private Expression name; + private Expression file; @Override public boolean check(final Event event) { return path.check(event, new Checker() { @Override public boolean check(final String s) { - if (!SkriptYaml.YAML_STORE.containsKey(name.getSingle(event))) + if (!SkriptYaml.YAML_STORE.containsKey(file.getSingle(event))) return false; - Object o = SkriptYaml.YAML_STORE.get(name.getSingle(event)).getProperty(path.getSingle(event)); + Object o = SkriptYaml.YAML_STORE.get(file.getSingle(event)).getProperty(path.getSingle(event)); return o != null ? (o instanceof List) : false; } }, isNegated()); @@ -54,14 +54,14 @@ public boolean check(final String s) { @Override public String toString(final @Nullable Event event, final boolean debug) { - return "yaml path " + path.toString(event, debug) + " in " + name.toString(event, debug) + (isNegated() ? " is not a list " + " " : "is a list"); + return "yaml path " + path.toString(event, debug) + " in " + file.toString(event, debug) + (isNegated() ? " is not a list " + " " : "is a list"); } @SuppressWarnings({"unchecked"}) @Override public boolean init(final Expression[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { path = (Expression) exprs[0]; - name = (Expression) exprs[1]; + file = (Expression) exprs[1]; setNegated(matchedPattern == 1); return true; } diff --git a/src/me/sashie/skriptyaml/skript/CondNodeHasValue.java b/src/me/sashie/skriptyaml/skript/CondNodeHasValue.java index 590833f..6db3638 100644 --- a/src/me/sashie/skriptyaml/skript/CondNodeHasValue.java +++ b/src/me/sashie/skriptyaml/skript/CondNodeHasValue.java @@ -37,22 +37,22 @@ public class CondNodeHasValue extends Condition { } private Expression path; - private Expression name; + private Expression file; @Override public boolean check(final Event event) { return path.check(event, new Checker() { @Override public boolean check(final String s) { - if (!SkriptYaml.YAML_STORE.containsKey(name.getSingle(event))) + if (!SkriptYaml.YAML_STORE.containsKey(file.getSingle(event))) return false; if (path.isSingle()) - return (SkriptYaml.YAML_STORE.get(name.getSingle(event)).getProperty(path.getSingle(event)) != null); + return (SkriptYaml.YAML_STORE.get(file.getSingle(event)).getProperty(path.getSingle(event)) != null); else { String[] paths = (String[]) path.getAll(event); boolean check; for (String p : paths) { - check = (SkriptYaml.YAML_STORE.get(name.getSingle(event)).getProperty(p) != null); + check = (SkriptYaml.YAML_STORE.get(file.getSingle(event)).getProperty(p) != null); if (!check) { return false; } @@ -65,14 +65,14 @@ public boolean check(final String s) { @Override public String toString(final @Nullable Event event, final boolean debug) { - return "yaml path " + path.toString(event, debug) + " in " + name.toString(event, debug) + (isNegated() ? (path.isSingle() ? " does not have a value" : " do not have values") + " " : "has a value"); + return "yaml path " + path.toString(event, debug) + " in " + file.toString(event, debug) + (isNegated() ? (path.isSingle() ? " does not have a value" : " do not have values") + " " : "has a value"); } @SuppressWarnings({"unchecked"}) @Override public boolean init(final Expression[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { path = (Expression) exprs[0]; - name = (Expression) exprs[1]; + file = (Expression) exprs[1]; setNegated(matchedPattern == 1); return true; } diff --git a/src/me/sashie/skriptyaml/skript/CondYamlFileExists.java b/src/me/sashie/skriptyaml/skript/CondYamlFileExists.java index 9586cf4..f390ed0 100644 --- a/src/me/sashie/skriptyaml/skript/CondYamlFileExists.java +++ b/src/me/sashie/skriptyaml/skript/CondYamlFileExists.java @@ -35,21 +35,21 @@ public class CondYamlFileExists extends Condition { "[(1¦non[(-| )]relative)] y[a]ml file %string% does(n't| not) exist"); } - private Expression name; + private Expression file; private int mark; @Override public boolean check(final Event event) { - return name.check(event, new Checker() { + return file.check(event, new Checker() { @Override public boolean check(final String s) { - final String file = StringUtil.checkSeparator(name.getSingle(event)); + final String f = StringUtil.checkSeparator(file.getSingle(event)); File yamlFile = null; if (mark == 1) { - yamlFile = new File(StringUtil.checkRoot(file)); + yamlFile = new File(StringUtil.checkRoot(f)); } else { String server = new File("").getAbsoluteFile().getAbsolutePath(); - yamlFile = new File(server + File.separator + file); + yamlFile = new File(server + File.separator + f); } if (yamlFile.exists()) return true; @@ -60,13 +60,13 @@ public boolean check(final String s) { @Override public String toString(final @Nullable Event e, final boolean debug) { - return "yaml file " + name.toString(e, debug) + (isNegated() ? " does not exist" : " exists"); + return "yaml file " + file.toString(e, debug) + (isNegated() ? " does not exist" : " exists"); } @SuppressWarnings({"unchecked"}) @Override public boolean init(final Expression[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parse) { - name = (Expression) exprs[0]; + file = (Expression) exprs[0]; setNegated(matchedPattern == 1); this.mark = parse.mark; return true; diff --git a/src/me/sashie/skriptyaml/skript/CondYamlIsEmpty.java b/src/me/sashie/skriptyaml/skript/CondYamlIsEmpty.java index 75a1c07..22c72c4 100644 --- a/src/me/sashie/skriptyaml/skript/CondYamlIsEmpty.java +++ b/src/me/sashie/skriptyaml/skript/CondYamlIsEmpty.java @@ -32,29 +32,29 @@ public class CondYamlIsEmpty extends Condition { "[skript-]y[a]ml %string% is(n't| not) empty"); } - private Expression name; + private Expression file; @Override public boolean check(final Event event) { - return name.check(event, new Checker() { + return file.check(event, new Checker() { @Override public boolean check(final String s) { - if (!SkriptYaml.YAML_STORE.containsKey(name.getSingle(event))) + if (!SkriptYaml.YAML_STORE.containsKey(file.getSingle(event))) return false; - return (SkriptYaml.YAML_STORE.get(name.getSingle(event)).getAllKeys().isEmpty()); + return (SkriptYaml.YAML_STORE.get(file.getSingle(event)).getAllKeys().isEmpty()); } }, isNegated()); } @Override public String toString(final @Nullable Event event, final boolean debug) { - return "yaml " + name.toString(event, debug) + (isNegated() ? " is empty" : "isn't empty"); + return "yaml " + file.toString(event, debug) + (isNegated() ? " is empty" : "isn't empty"); } @SuppressWarnings({"unchecked"}) @Override public boolean init(final Expression[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { - name = (Expression) exprs[0]; + file = (Expression) exprs[0]; setNegated(matchedPattern == 1); return true; } diff --git a/src/me/sashie/skriptyaml/skript/CondYamlIsLoaded.java b/src/me/sashie/skriptyaml/skript/CondYamlIsLoaded.java index a8d6bed..cf5eb4d 100644 --- a/src/me/sashie/skriptyaml/skript/CondYamlIsLoaded.java +++ b/src/me/sashie/skriptyaml/skript/CondYamlIsLoaded.java @@ -32,14 +32,14 @@ public class CondYamlIsLoaded extends Condition { "y[a]ml[s] %strings% ((are|is) not|(is|are)n[']t) loaded"); } - private Expression name; + private Expression file; @Override public boolean check(final Event event) { - return name.check(event, new Checker() { + return file.check(event, new Checker() { @Override public boolean check(final String s) { - if (!SkriptYaml.YAML_STORE.containsKey(name.getSingle(event))) + if (!SkriptYaml.YAML_STORE.containsKey(file.getSingle(event))) return false; return true; } @@ -48,13 +48,13 @@ public boolean check(final String s) { @Override public String toString(final @Nullable Event e, final boolean debug) { - return "yaml " + name.toString(e, debug) + (name.isSingle() ? " is " : " are ") + (isNegated() ? "not loaded" : "loaded"); + return "yaml " + file.toString(e, debug) + (file.isSingle() ? " is " : " are ") + (isNegated() ? "not loaded" : "loaded"); } @SuppressWarnings({"unchecked"}) @Override public boolean init(final Expression[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { - name = (Expression) exprs[0]; + file = (Expression) exprs[0]; setNegated(matchedPattern == 1); return true; } diff --git a/src/me/sashie/skriptyaml/skript/CondYamlPathExists.java b/src/me/sashie/skriptyaml/skript/CondYamlPathExists.java index 2cae952..3c0da48 100644 --- a/src/me/sashie/skriptyaml/skript/CondYamlPathExists.java +++ b/src/me/sashie/skriptyaml/skript/CondYamlPathExists.java @@ -40,21 +40,21 @@ public class CondYamlPathExists extends Condition { } private Expression path; - private Expression name; + private Expression file; @Override public boolean check(final Event event) { return path.check(event, new Checker() { @Override public boolean check(final String s) { - if (!SkriptYaml.YAML_STORE.containsKey(name.getSingle(event))) + if (!SkriptYaml.YAML_STORE.containsKey(file.getSingle(event))) return false; if (path.isSingle()) - return SkriptYaml.YAML_STORE.get(name.getSingle(event)).getAllKeys().contains(path.getSingle(event)); + return SkriptYaml.YAML_STORE.get(file.getSingle(event)).getAllKeys().contains(path.getSingle(event)); else { boolean check; for (String p : path.getAll(event)) { - check = SkriptYaml.YAML_STORE.get(name.getSingle(event)).getAllKeys().contains(p); + check = SkriptYaml.YAML_STORE.get(file.getSingle(event)).getAllKeys().contains(p); if (!check) { return false; } @@ -67,14 +67,14 @@ public boolean check(final String s) { @Override public String toString(final @Nullable Event event, final boolean debug) { - return "yaml path " + path.toString(event, debug) + " in " + name.toString(event, debug) + (isNegated() ? (path.isSingle() ? " does" : " do") + " not exist" : "exist"); + return "yaml path " + path.toString(event, debug) + " in " + file.toString(event, debug) + (isNegated() ? (path.isSingle() ? " does" : " do") + " not exist" : "exist"); } @SuppressWarnings({"unchecked"}) @Override public boolean init(final Expression[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) { path = (Expression) exprs[0]; - name = (Expression) exprs[1]; + file = (Expression) exprs[1]; setNegated(matchedPattern == 1); return true; } diff --git a/src/me/sashie/skriptyaml/skript/EffDeleteYaml.java b/src/me/sashie/skriptyaml/skript/EffDeleteYaml.java index 5ae1921..7f9103f 100644 --- a/src/me/sashie/skriptyaml/skript/EffDeleteYaml.java +++ b/src/me/sashie/skriptyaml/skript/EffDeleteYaml.java @@ -14,7 +14,6 @@ import ch.njol.skript.lang.SkriptParser; import ch.njol.util.Kleenean; import me.sashie.skriptyaml.SkriptYaml; -import me.sashie.skriptyaml.utils.StringUtil; @Name("Delete YAML") @Description("Deletes a YAML file and removes it from memory.") @@ -33,7 +32,6 @@ public class EffDeleteYaml extends Effect { @Override protected void execute(@Nullable Event event) { for (String name : this.file.getAll(event)) { - name = StringUtil.checkSeparator(name); if (!SkriptYaml.YAML_STORE.containsKey(name)) continue; SkriptYaml.YAML_STORE.get(name).getFile().delete(); diff --git a/src/me/sashie/skriptyaml/skript/EffLoadYaml.java b/src/me/sashie/skriptyaml/skript/EffLoadYaml.java index b0f6674..17d946c 100644 --- a/src/me/sashie/skriptyaml/skript/EffLoadYaml.java +++ b/src/me/sashie/skriptyaml/skript/EffLoadYaml.java @@ -67,13 +67,12 @@ protected void execute(@Nullable Event event) { } private void load(String name, Event event) { - name = StringUtil.checkSeparator(name); File yamlFile = null; String server = new File("").getAbsoluteFile().getAbsolutePath() + File.separator; if (mark == 1) { - yamlFile = new File(StringUtil.checkRoot(name)); + yamlFile = new File(StringUtil.checkRoot(StringUtil.checkSeparator(name))); } else { - yamlFile = new File(server + name); + yamlFile = new File(server + StringUtil.checkSeparator(name)); } try { diff --git a/src/me/sashie/skriptyaml/skript/EffLoadYamlDirectory.java b/src/me/sashie/skriptyaml/skript/EffLoadYamlDirectory.java index 4240bff..db15e7b 100644 --- a/src/me/sashie/skriptyaml/skript/EffLoadYamlDirectory.java +++ b/src/me/sashie/skriptyaml/skript/EffLoadYamlDirectory.java @@ -49,20 +49,17 @@ public class EffLoadYamlDirectory extends Effect { @Override protected void execute(@Nullable Event event) { for (String name : this.directories.getAll(event)) { - name = StringUtil.checkSeparator(name); - for (File yamlFile : SkriptYamlUtils.directoryFilter(name, mark == 1, "Load")) { + for (File yamlFile : SkriptYamlUtils.directoryFilter(StringUtil.checkSeparator(name), mark == 1, "Load")) { YAMLProcessor yaml = new YAMLProcessor(yamlFile, false, YAMLFormat.EXTENDED); try { yaml.load(); } catch (IOException e) { e.printStackTrace(); } finally { - String n = null; if (matchedPattern == 1) - n = StringUtil.stripExtention(yamlFile.getName()); + SkriptYaml.YAML_STORE.put(StringUtil.stripExtention(yamlFile.getName()), yaml); else - n = name + yamlFile.getName(); - SkriptYaml.YAML_STORE.put(n, yaml); + SkriptYaml.YAML_STORE.put(StringUtil.checkLastSeparator(name) + yamlFile.getName(), yaml); } } } diff --git a/src/me/sashie/skriptyaml/skript/EffSaveYaml.java b/src/me/sashie/skriptyaml/skript/EffSaveYaml.java index 5cbe98e..ce23b52 100644 --- a/src/me/sashie/skriptyaml/skript/EffSaveYaml.java +++ b/src/me/sashie/skriptyaml/skript/EffSaveYaml.java @@ -14,7 +14,6 @@ import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; import me.sashie.skriptyaml.SkriptYaml; -import me.sashie.skriptyaml.utils.StringUtil; import me.sashie.skriptyaml.utils.yaml.YAMLProcessor; @Name("Save YAML") @@ -40,7 +39,6 @@ public class EffSaveYaml extends Effect { @Override protected void execute(@Nullable Event event) { for (String name : this.file.getAll(event)) { - name = StringUtil.checkSeparator(name); if (!SkriptYaml.YAML_STORE.containsKey(name)) continue; YAMLProcessor yaml = SkriptYaml.YAML_STORE.get(name); diff --git a/src/me/sashie/skriptyaml/skript/EffUnloadYaml.java b/src/me/sashie/skriptyaml/skript/EffUnloadYaml.java index fe7972e..00e3ec9 100644 --- a/src/me/sashie/skriptyaml/skript/EffUnloadYaml.java +++ b/src/me/sashie/skriptyaml/skript/EffUnloadYaml.java @@ -44,7 +44,6 @@ protected void execute(@Nullable Event event) { if (mark == 1) server = new File("").getAbsoluteFile().getAbsolutePath() + File.separator; for (String name : this.file.getAll(event)) { - name = StringUtil.checkSeparator(name); if (mark == 1) { for (Iterator> it = SkriptYaml.YAML_STORE.entrySet().iterator(); it.hasNext();) { String path = it.next().getValue().getParentPath(); diff --git a/src/me/sashie/skriptyaml/skript/ExprAllYamlNodes.java b/src/me/sashie/skriptyaml/skript/ExprAllYamlNodes.java index a1d06c7..936a887 100644 --- a/src/me/sashie/skriptyaml/skript/ExprAllYamlNodes.java +++ b/src/me/sashie/skriptyaml/skript/ExprAllYamlNodes.java @@ -18,7 +18,6 @@ import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.util.Kleenean; import me.sashie.skriptyaml.SkriptYaml; -import me.sashie.skriptyaml.utils.StringUtil; import me.sashie.skriptyaml.utils.yaml.YAMLProcessor; @Name("All YAML Nodes") @@ -59,7 +58,7 @@ public String toString(@Nullable Event event, boolean b) { @Nullable protected String[] get(Event event) { - final String name = StringUtil.checkSeparator(this.file.getSingle(event)); + final String name = this.file.getSingle(event); if (!SkriptYaml.YAML_STORE.containsKey(name)) { //SkriptYaml.warn("No yaml file by the name '" + name + "' has been loaded"); diff --git a/src/me/sashie/skriptyaml/skript/ExprYaml.java b/src/me/sashie/skriptyaml/skript/ExprYaml.java index 5a28b43..4817c39 100644 --- a/src/me/sashie/skriptyaml/skript/ExprYaml.java +++ b/src/me/sashie/skriptyaml/skript/ExprYaml.java @@ -239,7 +239,7 @@ public final static T[] convertArray(Object[] original, Class to) throws @Override public void change(Event event, Object[] delta, Changer.ChangeMode mode) { - final String name = StringUtil.checkSeparator(this.file.getSingle(event)); + final String name = this.file.getSingle(event); final String path = this.node.getSingle(event); if (!SkriptYaml.YAML_STORE.containsKey(name)) { diff --git a/src/me/sashie/skriptyaml/skript/ExprYamlComments.java b/src/me/sashie/skriptyaml/skript/ExprYamlComments.java index 0f23c4e..1f3a355 100644 --- a/src/me/sashie/skriptyaml/skript/ExprYamlComments.java +++ b/src/me/sashie/skriptyaml/skript/ExprYamlComments.java @@ -78,7 +78,7 @@ public String toString(@Nullable Event event, boolean b) { @Override @Nullable protected Object[] get(Event event) { - final String name = StringUtil.checkSeparator(this.file.getSingle(event)); + final String name = this.file.getSingle(event); final String path = this.paths.getSingle(event); if (!SkriptYaml.YAML_STORE.containsKey(name)) {