Skip to content

Commit

Permalink
Merge branch 'dev/feature' into dev/blockstates
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAbsolutionism authored Nov 30, 2024
2 parents 22d2cc3 + 541dc12 commit dd318f0
Show file tree
Hide file tree
Showing 41 changed files with 1,798 additions and 312 deletions.
166 changes: 82 additions & 84 deletions src/main/java/ch/njol/skript/ScriptLoader.java

Large diffs are not rendered by default.

38 changes: 12 additions & 26 deletions src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
import org.skriptlang.skript.bukkit.SkriptMetrics;
import org.skriptlang.skript.bukkit.breeding.BreedingModule;
import org.skriptlang.skript.bukkit.displays.DisplayModule;
import org.skriptlang.skript.bukkit.input.InputModule;
import org.skriptlang.skript.lang.comparator.Comparator;
import org.skriptlang.skript.lang.comparator.Comparators;
import org.skriptlang.skript.lang.converter.Converter;
Expand Down Expand Up @@ -131,6 +132,7 @@
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicLong;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
Expand Down Expand Up @@ -261,17 +263,6 @@ public static ServerPlatform getServerPlatform() {
}
}

/**
* Returns true if the underlying installed Java/JVM is 32-bit, false otherwise.
* Note that this depends on a internal system property and these can always be overridden by user using -D JVM options,
* more specifically, this method will return false on non OracleJDK/OpenJDK based JVMs, that don't include bit information in java.vm.name system property.
* @return Whether the installed Java/JVM is 32-bit or not.
*/
private static boolean using32BitJava() {
// Property returned should either be "Java HotSpot(TM) 32-Bit Server VM" or "OpenJDK 32-Bit Server VM" if 32-bit and using OracleJDK/OpenJDK
return System.getProperty("java.vm.name").contains("32");
}

/**
* Checks if server software and Minecraft version are supported.
* Prints errors or warnings to console if something is wrong.
Expand Down Expand Up @@ -502,6 +493,8 @@ public void onEnable() {
// ... but also before platform check, because there is a config option to ignore some errors
SkriptConfig.load();

CompletableFuture<Boolean> aliases = Aliases.loadAsync();

// Now override the verbosity if test mode is enabled
if (TestMode.VERBOSITY != null)
SkriptLogger.setVerbosity(Verbosity.valueOf(TestMode.VERBOSITY));
Expand All @@ -514,20 +507,6 @@ public void onEnable() {
updater.updateCheck(console);
}

try {
Aliases.load(); // Loaded before anything that might use them
} catch (StackOverflowError e) {
if (using32BitJava()) {
Skript.error("");
Skript.error("There was a StackOverflowError that occured while loading aliases.");
Skript.error("As you are currently using 32-bit Java, please update to 64-bit Java to resolve the error.");
Skript.error("Please report this issue to our GitHub only if updating to 64-bit Java does not fix the issue.");
Skript.error("");
} else {
throw e; // Uh oh, this shouldn't happen. Re-throw the error.
}
}

// If loading can continue (platform ok), check for potentially thrown error
if (classLoadError != null) {
exception(classLoadError);
Expand Down Expand Up @@ -555,8 +534,9 @@ public void onEnable() {
"conditions", "effects", "events", "expressions", "entity", "sections", "structures");
getAddonInstance().loadClasses("org.skriptlang.skript.bukkit", "misc");
// todo: become proper module once registry api is merged
DisplayModule.load();
BreedingModule.load();
DisplayModule.load();
InputModule.load();
} catch (final Exception e) {
exception(e, "Could not load required .class files: " + e.getLocalizedMessage());
setEnabled(false);
Expand Down Expand Up @@ -603,6 +583,12 @@ public void run() {
}
finishedLoadingHooks = true;

try {
aliases.get(); // wait for aliases to load
} catch (InterruptedException | ExecutionException e) {
exception(e, "Could not load aliases concurrently");
}

if (TestMode.ENABLED) {
info("Preparing Skript for testing...");
tainted = true;
Expand Down
21 changes: 10 additions & 11 deletions src/main/java/ch/njol/skript/SkriptCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
reloading(sender, "config, aliases and scripts", logHandler);
SkriptConfig.load();
Aliases.clear();
Aliases.load();

ScriptLoader.unloadScripts(ScriptLoader.getLoadedScripts());
ScriptLoader.loadScripts(Skript.getInstance().getScriptsFolder(), OpenCloseable.combine(logHandler, timingLogHandler))
.thenAccept(info -> {
if (info.files == 0)
Skript.warning(Skript.m_no_scripts.toString());
reloaded(sender, logHandler, timingLogHandler, "config, aliases and scripts");
});
Aliases.loadAsync().thenRun(() -> {
ScriptLoader.unloadScripts(ScriptLoader.getLoadedScripts());
ScriptLoader.loadScripts(Skript.getInstance().getScriptsFolder(), OpenCloseable.combine(logHandler, timingLogHandler))
.thenAccept(info -> {
if (info.files == 0)
Skript.warning(Skript.m_no_scripts.toString());
reloaded(sender, logHandler, timingLogHandler, "config, aliases and scripts");
});
});
} else if (args[1].equalsIgnoreCase("scripts")) {
reloading(sender, "scripts", logHandler);

Expand All @@ -185,8 +185,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
} else if (args[1].equalsIgnoreCase("aliases")) {
reloading(sender, "aliases", logHandler);
Aliases.clear();
Aliases.load();
reloaded(sender, logHandler, timingLogHandler, "aliases");
Aliases.loadAsync().thenRun(() -> reloaded(sender, logHandler, timingLogHandler, "aliases"));
} else { // Reloading an individual Script or folder
File scriptFile = getScriptFromArgs(sender, args);
if (scriptFile == null)
Expand Down
66 changes: 51 additions & 15 deletions src/main/java/ch/njol/skript/aliases/Aliases.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,29 @@
import ch.njol.skript.config.SectionNode;
import ch.njol.skript.entity.EntityData;
import ch.njol.skript.lang.parser.ParserInstance;
import ch.njol.skript.localization.ArgsMessage;
import ch.njol.skript.localization.Language;
import ch.njol.skript.localization.Message;
import ch.njol.skript.localization.Noun;
import ch.njol.skript.localization.RegexMessage;
import ch.njol.skript.localization.*;
import ch.njol.skript.log.BlockingLogHandler;
import ch.njol.skript.util.EnchantmentType;
import ch.njol.skript.util.Utils;
import ch.njol.skript.util.Version;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.script.Script;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.*;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.script.Script;

public abstract class Aliases {
static final boolean USING_ITEM_COMPONENTS = Skript.isRunningMinecraft(1, 20, 5);
Expand Down Expand Up @@ -371,7 +366,10 @@ public static void clear() {
/**
* Loads aliases from Skript's standard locations.
* Exceptions will be logged, but not thrown.
*
* @deprecated Freezes server on call. Use {@link #loadAsync()} instead.
*/
@Deprecated
public static void load() {
try {
long start = System.currentTimeMillis();
Expand All @@ -382,6 +380,44 @@ public static void load() {
}
}

/**
* Loads aliases from Skript's standard locations asynchronously.
* Exceptions will be logged, but not thrown.
*
* @return A future that completes when the aliases are loaded.
* The returned value is true if the loading was successful, false otherwise.
*/
public static CompletableFuture<Boolean> loadAsync() {
return CompletableFuture.supplyAsync(() -> {
try {
long start = System.currentTimeMillis();
loadInternal();
Skript.info("Loaded " + provider.getAliasCount() + " aliases in " + (System.currentTimeMillis() - start) + "ms");
return true;
} catch (StackOverflowError e) {
/*
* Returns true if the underlying installed Java/JVM is 32-bit, false otherwise.
* Note that this depends on a internal system property and these can always be overridden by user using -D JVM options,
* more specifically, this method will return false on non OracleJDK/OpenJDK based JVMs, that don't include bit information in java.vm.name system property
*/
if (System.getProperty("java.vm.name").contains("32")) {
Skript.error("");
Skript.error("There was a StackOverflowError that occurred while loading aliases.");
Skript.error("As you are currently using 32-bit Java, please update to 64-bit Java to resolve the error.");
Skript.error("Please report this issue to our GitHub only if updating to 64-bit Java does not fix the issue.");
Skript.error("");
} else {
Skript.exception(e);
Bukkit.getPluginManager().disablePlugin(Skript.getInstance());
}
return false;
} catch (IOException e) {
Skript.exception(e);
return false;
}
});
}

/**
* Temporarily create an alias for materials which do not have aliases yet.
*/
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/ch/njol/skript/effects/EffContinue.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,19 @@ public class EffContinue extends Effect {

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
level = matchedPattern == 0 ? 1 : Integer.parseInt(parseResult.regexes.get(0).group());
if (level < 1)
return false;

ParserInstance parser = getParser();
int loops = parser.getCurrentSections(LoopSection.class).size();
if (loops == 0) {
Skript.error("The 'continue' effect may only be used in loops");
return false;
}

// Section.getSections counts from the innermost section, so we need to invert the level
int levels = level == -1 ? 1 : loops - level + 1;
level = matchedPattern == 0 ? loops : Integer.parseInt(parseResult.regexes.get(0).group());
if (level < 1)
return false;

// ParserInstance#getSections counts from the innermost section, so we need to invert the level
int levels = loops - level + 1;
if (levels <= 0) {
Skript.error("Can't continue the " + StringUtils.fancyOrderNumber(level) + " loop as there " +
(loops == 1 ? "is only 1 loop" : "are only " + loops + " loops") + " present");
Expand Down
50 changes: 21 additions & 29 deletions src/main/java/ch/njol/skript/entity/EntityData.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,6 @@
*/
package ch.njol.skript.entity;

import java.io.NotSerializableException;
import java.io.StreamCorruptedException;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.RegionAccessor;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;

import ch.njol.skript.Skript;
import ch.njol.skript.SkriptAPIException;
import ch.njol.skript.bukkitutil.EntityUtils;
Expand All @@ -67,6 +44,27 @@
import ch.njol.util.coll.iterator.SingleItemIterator;
import ch.njol.yggdrasil.Fields;
import ch.njol.yggdrasil.YggdrasilSerializable.YggdrasilExtendedSerializable;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.RegionAccessor;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;

import java.io.NotSerializableException;
import java.io.StreamCorruptedException;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;

@SuppressWarnings("rawtypes")
public abstract class EntityData<E extends Entity> implements SyntaxElement, YggdrasilExtendedSerializable {// TODO extended horse support, zombie villagers // REMIND unit
Expand Down Expand Up @@ -105,8 +103,6 @@ public abstract class EntityData<E extends Entity> implements SyntaxElement, Ygg
// must be here to be initialised before 'new SimpleLiteral' is called in the register block below
private final static List<EntityDataInfo<EntityData<?>>> infos = new ArrayList<>();

private static final Pattern REGEX_PATTERN = Pattern.compile("[a-zA-Z -]+");

private static final List<EntityData> ALL_ENTITY_DATAS = new ArrayList<>();

public static Serializer<EntityData> serializer = new Serializer<EntityData>() {
Expand Down Expand Up @@ -435,8 +431,6 @@ public static EntityDataInfo<?> getInfo(final String codeName) {
@SuppressWarnings("null")
@Nullable
public static EntityData<?> parse(String s) {
if (!REGEX_PATTERN.matcher(s).matches())
return null;
Iterator<EntityDataInfo<EntityData<?>>> it = infos.iterator();
return SkriptParser.parseStatic(Noun.stripIndefiniteArticle(s), it, null);
}
Expand All @@ -449,8 +443,6 @@ public static EntityData<?> parse(String s) {
*/
@Nullable
public static EntityData<?> parseWithoutIndefiniteArticle(String s) {
if (!REGEX_PATTERN.matcher(s).matches())
return null;
Iterator<EntityDataInfo<EntityData<?>>> it = infos.iterator();
return SkriptParser.parseStatic(s, it, null);
}
Expand Down
Loading

0 comments on commit dd318f0

Please sign in to comment.