Skip to content

Commit

Permalink
Fix merge issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Moderocky committed Dec 22, 2024
1 parent ac4e1e1 commit 2f469bd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 92 deletions.
1 change: 1 addition & 0 deletions src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.UnknownNullability;
import org.junit.After;
Expand Down
58 changes: 10 additions & 48 deletions src/main/java/ch/njol/skript/classes/data/SkriptClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,6 @@ public String toVariableNameString(VisualEffect e) {
.name("Config")
.description("A configuration (or code) loaded by Skript, such as the config.sk or aliases.",
"Configs can be reloaded or navigated to find options.")
.usage("")
.examples("the skript config")
.since("INSERT VERSION")
.parser(new Parser<Config>() {
Expand Down Expand Up @@ -713,19 +712,15 @@ public String toVariableNameString(Config config) {
.name("Node")
.description("A node (entry) from a script config file.",
"This may have navigable children.")
.usage("")
.examples("the current script")
.since("INSERT VERSION")
.changer(new Changer<Node>() {
@Override
public @Nullable Class<?> @Nullable [] acceptChange(ChangeMode mode) {
switch (mode) {
case RESET:
case DELETE:
return new Class[0];
default:
return null;
}
return switch (mode) {
case RESET, DELETE -> new Class[0];
default -> null;
};
}

@Override
Expand All @@ -749,44 +744,12 @@ public boolean canParse(ParseContext context) {

@Override
public String toString(Node node, int flags) {
return this.toVariableNameString(node);
}

@Override
public String toVariableNameString(Node node) {
return node.getPath();
}

}));

Classes.registerClass(new ClassInfo<>(Node.class, "node")
.user("nodes?")
.name("Node")
.description("A node (entry) from a script config file.",
"This may have navigable children.")
.usage("")
.examples("the current script")
.since("INSERT VERSION")
.parser(new Parser<Node>() {

@Override
public boolean canParse(ParseContext context) {
return false;
}

@Override
public @Nullable Node parse(String name, ParseContext context) {
return null;
}

@Override
public String toString(Node node, int flags) {
return this.toVariableNameString(node);
}

@Override
public String toVariableNameString(Node node) {
return node.getPath();
return this.toString(node, 0);
}

}));
Expand All @@ -796,7 +759,6 @@ public String toVariableNameString(Node node) {
.name("Script")
.description("A script loaded by Skript.",
"Disabled scripts will report as being empty since their content has not been loaded.")
.usage("")
.examples("the current script")
.since("INSERT VERSION")
.parser(new Parser<Script>() {
Expand Down Expand Up @@ -826,16 +788,16 @@ public Script parse(final String name, final ParseContext context) {

@Override
public String toString(final Script script, final int flags) {
return this.toVariableNameString(script);
}

@Override
public String toVariableNameString(final Script script) {
@Nullable File file = script.getConfig().getFile();
if (file == null)
return script.getConfig().getFileName();
return path.relativize(file.toPath().toAbsolutePath()).toString();
}

@Override
public String toVariableNameString(final Script script) {
return this.toString(script, 0);
}
}));
}

Expand Down
29 changes: 18 additions & 11 deletions src/main/java/ch/njol/skript/expressions/ExprConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,22 @@
"This can be reloaded, or navigated to retrieve options."
})
@Examples({
"set {_config} to the skript config",
"set {_node} to the node \"number accuracy\" of {_config}",
"set {_value} to the number value of {_node}",

"register config \"my cool config\"",
"on load:",
"\tset {_config} to the config named \"my cool config\"",
"\tset {_node} to node \"welcome message\" of {_config}",
"\tbroadcast the text value of {_node}"
"""
set {_node} to node "language" in the skript config
if text value of {_node} is "french":
broadcast "Bonjour!"
""",
"""
set {_config} to the skript config
set {_node} to the node "number accuracy" of {_config}
set {_value} to the number value of {_node}""",
"""
register config "my cool config"
on load:
set {_config} to the config named "my cool config"
set {_node} to node "welcome message" of {_config}
broadcast the text value of {_node}"""
})
@Since("INSERT VERSION")
public class ExprConfig extends SimpleExpression<Config> {
Expand All @@ -53,7 +60,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
return false;
if (matchedPattern == 0) {
this.config = SkriptConfig.getConfig();
if (config == null) { // todo is this ok?
if (config == null) {
Skript.warning("The main config is unavailable here!");
return false;
}
Expand All @@ -63,7 +70,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
String string = name.getSingle();
Script script = this.getParser().getCurrentScript();
if (!Skript.userConfigs().isRegistered(script, string)) {
Skript.warning("You register a config '" + string + "' in order to access it.");
Skript.warning("You must register a config '" + string + "' in order to access it.");
return false;
}
this.config = Skript.userConfigs().getConfig(script, string);
Expand Down
33 changes: 0 additions & 33 deletions src/main/java/org/skriptlang/skript/lang/script/Script.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,37 +192,4 @@ public boolean valid() {
return false;
}

/**
* Marks this script reference as invalid.
* Typically invoked during unloading (when its data is discarded).
*/
@Override
public void invalidate() {
this.config.invalidate();
}

/**
* This is a reference to a script (having been loaded); if the script is reloaded,
* disabled, moved or changed in some way then this object will no longer be a valid
* reference to it.
* <br/>
* If a script reference is not valid, it is not safe to assume that the data in
* this object is an accurate reflection of the program (e.g. the data could have cleared
* during unloading, the user might have edited the file and reloaded it, etc.) and
* it is recommended to obtain a new reference to the script from {@link ch.njol.skript.ScriptLoader}.
*
* @return Whether this script object is a valid reflection of a script
*/
@Override
public boolean valid() {
if (config.valid()) {
@Nullable File file = config.getFile();
return file == null || file.exists();
// If this is file-linked and that file was moved/deleted (e.g. this was disabled)
// then we should not assume this is a safe reference to use, unless it was
// immediately obtained.
}
return false;
}

}

0 comments on commit 2f469bd

Please sign in to comment.