Skip to content

Commit f5fadd0

Browse files
committed
Add soft exceptions option... (#120)
1 parent 728b69f commit f5fadd0

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

src/main/java/ch/njol/skript/Skript.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,9 +1195,9 @@ public final static EmptyStacktraceException exception(@Nullable Throwable cause
11951195
logEx(info);
11961196
logEx();
11971197
logEx("If you're developing an add-on for Skript this likely means that you have done something wrong.");
1198-
logEx("If you're a server admin however please go to http://dev.bukkit.org/server-mods/skript/tickets/");
1198+
logEx("If you're a server admin however please go to https://github.com/bensku/Skript/issues/");
11991199
logEx("and check whether this error has already been reported.");
1200-
logEx("If not please create a new ticket with a meaningful title, copy & paste this whole error into it,");
1200+
logEx("If not please create a new ticket with a meaningful title, copy & paste this whole error into it (or use paste service),");
12011201
logEx("and describe what you did before it happened and/or what you think caused the error.");
12021202
logEx("If you think that it's a trigger that's causing the error please post the trigger as well.");
12031203
logEx("By following this guide fixing the error should be easy and done fast.");

src/main/java/ch/njol/skript/SkriptConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ public EventPriority convert(final String s) {
167167
public final static Option<Boolean> addonSafetyChecks = new Option<Boolean>("addon safety checks", false)
168168
.optional(true);
169169

170+
public final static Option<Boolean> apiSoftExceptions = new Option<Boolean>("soft api exceptions", false);
171+
170172
/**
171173
* This should only be used in special cases
172174
*/

src/main/java/ch/njol/skript/registrations/Classes.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,23 @@ private Classes() {}
8585
* @param info info about the class to register
8686
*/
8787
public static <T> void registerClass(final ClassInfo<T> info) {
88-
Skript.checkAcceptRegistrations();
89-
if (classInfosByCodeName.containsKey(info.getCodeName()))
90-
throw new IllegalArgumentException("Can't register " + info.getC().getName() + " with the code name " + info.getCodeName() + " because that name is already used by " + classInfosByCodeName.get(info.getCodeName()));
91-
if (exactClassInfos.containsKey(info.getC()))
92-
throw new IllegalArgumentException("Can't register the class info " + info.getCodeName() + " because the class " + info.getC().getName() + " is already registered");
93-
if (info.getCodeName().length() > DatabaseStorage.MAX_CLASS_CODENAME_LENGTH)
94-
throw new IllegalArgumentException("The codename '" + info.getCodeName() + "' is too long to be saved in a database, the maximum length allowed is " + DatabaseStorage.MAX_CLASS_CODENAME_LENGTH);
95-
exactClassInfos.put(info.getC(), info);
96-
classInfosByCodeName.put(info.getCodeName(), info);
97-
tempClassInfos.add(info);
88+
try {
89+
Skript.checkAcceptRegistrations();
90+
if (classInfosByCodeName.containsKey(info.getCodeName()))
91+
throw new IllegalArgumentException("Can't register " + info.getC().getName() + " with the code name " + info.getCodeName() + " because that name is already used by " + classInfosByCodeName.get(info.getCodeName()));
92+
if (exactClassInfos.containsKey(info.getC()))
93+
throw new IllegalArgumentException("Can't register the class info " + info.getCodeName() + " because the class " + info.getC().getName() + " is already registered");
94+
if (info.getCodeName().length() > DatabaseStorage.MAX_CLASS_CODENAME_LENGTH)
95+
throw new IllegalArgumentException("The codename '" + info.getCodeName() + "' is too long to be saved in a database, the maximum length allowed is " + DatabaseStorage.MAX_CLASS_CODENAME_LENGTH);
96+
exactClassInfos.put(info.getC(), info);
97+
classInfosByCodeName.put(info.getCodeName(), info);
98+
tempClassInfos.add(info);
99+
} catch (RuntimeException e) {
100+
if (SkriptConfig.apiSoftExceptions.value())
101+
Skript.warning("Ignored an exception due to user configuration: " + e.getMessage());
102+
else
103+
throw e;
104+
}
98105
}
99106

100107
public final static void onRegistrationsStop() {

src/main/resources/config.sk

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,14 @@ disable variable conflict warnings: false
151151
# whenever you create new scripts with new variables.
152152

153153
disable variable will not be saved warnings: false
154-
#Disables the "... i.e contents cannot be saved ..." warning when reloading and something in your scripts sets a variable(non local) to a value that is not serializable.
155-
#By Mirre.
154+
# Disables the "... i.e contents cannot be saved ..." warning when reloading and something in your scripts sets a variable(non local) to a value that is not serializable.
155+
# By Mirre.
156+
157+
soft api exceptions: false
158+
# Allows Skript to ignore certain actions which would normally result in thrown exceptions.
159+
# If everything works correctly, you should keep this option disabled. It might cause problems in some cases.
160+
# However, if Skript or addons of it are not working correctly, this might help.
161+
# You may also get told to enable this by Skript or addon developers - then do so.
156162

157163
# ==== Variables ====
158164

0 commit comments

Comments
 (0)