Skip to content

Commit

Permalink
Add optional safety checks for addons
Browse files Browse the repository at this point in the history
  • Loading branch information
bensku committed Apr 24, 2016
1 parent a9401a0 commit 06646c0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ch.njol</groupId>
<artifactId>skript</artifactId>
<version>2.2-dev13b</version>
<version>2.2-dev13c</version>
<name>Skript</name>
<description>A plugin for the Minecraft server API Bukkit that allows to create scripts in natural language.</description>
<url>http://njol.ch/projects/skript/</url>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/ch/njol/skript/SkriptConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ public EventPriority convert(final String s) {
public final static Option<Boolean> keepConfigsLoaded = new Option<Boolean>("keep configs loaded", false)
.optional(true);

public final static Option<Boolean> addonSafetyChecks = new Option<Boolean>("addon safety checks", false)
.optional(true);

/**
* This should only be used in special cases
*/
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/ch/njol/skript/registrations/Classes.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
Expand All @@ -44,6 +45,7 @@

import ch.njol.skript.Skript;
import ch.njol.skript.SkriptAPIException;
import ch.njol.skript.SkriptConfig;
import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.classes.Converter;
import ch.njol.skript.classes.Converter.ConverterInfo;
Expand Down Expand Up @@ -126,6 +128,9 @@ public final static void onRegistrationsStop() {
private final static void sortClassInfos() {
assert classInfos == null;

if (!Skript.testing() && SkriptConfig.addonSafetyChecks.value())
removeNullElements();

// merge before, after & sub/supertypes in after
for (final ClassInfo<?> ci : tempClassInfos) {
final Set<String> before = ci.before();
Expand Down Expand Up @@ -215,6 +220,16 @@ private final static void sortClassInfos() {

}

@SuppressWarnings({"null", "unused"})
private final static void removeNullElements() {
Iterator<ClassInfo<?>> it = tempClassInfos.iterator();
while (it.hasNext()) {
ClassInfo<?> ci = it.next();
if (ci.getC() == null)
it.remove();
}
}

private final static void checkAllowClassInfoInteraction() {
if (Skript.isAcceptRegistrations())
throw new IllegalStateException("Cannot use classinfos until registration is over");
Expand Down

0 comments on commit 06646c0

Please sign in to comment.