Skip to content

Commit

Permalink
Update to 1.3.1
Browse files Browse the repository at this point in the history
Fixed loaded yaml directory ids not working
  • Loading branch information
Sashie committed Jun 26, 2019
1 parent 77ed7d7 commit 7701df3
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 54 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
3 changes: 3 additions & 0 deletions src/me/sashie/skriptyaml/SkriptYaml.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions src/me/sashie/skriptyaml/skript/CondNodeHasList.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,31 @@ public class CondNodeHasList extends Condition {
}

private Expression<String> path;
private Expression<String> name;
private Expression<String> file;

@Override
public boolean check(final Event event) {
return path.check(event, new Checker<String>() {
@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());
}

@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<String>) exprs[0];
name = (Expression<String>) exprs[1];
file = (Expression<String>) exprs[1];
setNegated(matchedPattern == 1);
return true;
}
Expand Down
12 changes: 6 additions & 6 deletions src/me/sashie/skriptyaml/skript/CondNodeHasValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ public class CondNodeHasValue extends Condition {
}

private Expression<String> path;
private Expression<String> name;
private Expression<String> file;

@Override
public boolean check(final Event event) {
return path.check(event, new Checker<String>() {
@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;
}
Expand All @@ -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<String>) exprs[0];
name = (Expression<String>) exprs[1];
file = (Expression<String>) exprs[1];
setNegated(matchedPattern == 1);
return true;
}
Expand Down
14 changes: 7 additions & 7 deletions src/me/sashie/skriptyaml/skript/CondYamlFileExists.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ public class CondYamlFileExists extends Condition {
"[(1¦non[(-| )]relative)] y[a]ml file %string% does(n't| not) exist");
}

private Expression<String> name;
private Expression<String> file;
private int mark;

@Override
public boolean check(final Event event) {
return name.check(event, new Checker<String>() {
return file.check(event, new Checker<String>() {
@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;
Expand All @@ -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<String>) exprs[0];
file = (Expression<String>) exprs[0];
setNegated(matchedPattern == 1);
this.mark = parse.mark;
return true;
Expand Down
12 changes: 6 additions & 6 deletions src/me/sashie/skriptyaml/skript/CondYamlIsEmpty.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,29 @@ public class CondYamlIsEmpty extends Condition {
"[skript-]y[a]ml %string% is(n't| not) empty");
}

private Expression<String> name;
private Expression<String> file;

@Override
public boolean check(final Event event) {
return name.check(event, new Checker<String>() {
return file.check(event, new Checker<String>() {
@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<String>) exprs[0];
file = (Expression<String>) exprs[0];
setNegated(matchedPattern == 1);
return true;
}
Expand Down
10 changes: 5 additions & 5 deletions src/me/sashie/skriptyaml/skript/CondYamlIsLoaded.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ public class CondYamlIsLoaded extends Condition {
"y[a]ml[s] %strings% ((are|is) not|(is|are)n[']t) loaded");
}

private Expression<String> name;
private Expression<String> file;

@Override
public boolean check(final Event event) {
return name.check(event, new Checker<String>() {
return file.check(event, new Checker<String>() {
@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;
}
Expand All @@ -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<String>) exprs[0];
file = (Expression<String>) exprs[0];
setNegated(matchedPattern == 1);
return true;
}
Expand Down
12 changes: 6 additions & 6 deletions src/me/sashie/skriptyaml/skript/CondYamlPathExists.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ public class CondYamlPathExists extends Condition {
}

private Expression<String> path;
private Expression<String> name;
private Expression<String> file;

@Override
public boolean check(final Event event) {
return path.check(event, new Checker<String>() {
@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;
}
Expand All @@ -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<String>) exprs[0];
name = (Expression<String>) exprs[1];
file = (Expression<String>) exprs[1];
setNegated(matchedPattern == 1);
return true;
}
Expand Down
2 changes: 0 additions & 2 deletions src/me/sashie/skriptyaml/skript/EffDeleteYaml.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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();
Expand Down
5 changes: 2 additions & 3 deletions src/me/sashie/skriptyaml/skript/EffLoadYaml.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 3 additions & 6 deletions src/me/sashie/skriptyaml/skript/EffLoadYamlDirectory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/me/sashie/skriptyaml/skript/EffSaveYaml.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/me/sashie/skriptyaml/skript/EffUnloadYaml.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entry<String, YAMLProcessor>> it = SkriptYaml.YAML_STORE.entrySet().iterator(); it.hasNext();) {
String path = it.next().getValue().getParentPath();
Expand Down
3 changes: 1 addition & 2 deletions src/me/sashie/skriptyaml/skript/ExprAllYamlNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/me/sashie/skriptyaml/skript/ExprYaml.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public final static <T> T[] convertArray(Object[] original, Class<T> 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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/me/sashie/skriptyaml/skript/ExprYamlComments.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 7701df3

Please sign in to comment.