Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.

Commit 27c474d

Browse files
author
Mustafa ÖNCEL
committed
Use aliases on the JAR, more changes and the v2.2.16-beta2
- Don't create aliases-english.sk and aliases-german.sk by default, use ones in the JAR to keep updated - Added colored loaded script message based on load times, you can enable with a system property, not tested though - Added a new NonReflectiveAddon interface for speeding up the getFile method. Only a very very small enhancement. - Added assertions for closeOnEnable and disable, also fixed the version error and added load times of aliases, language files etc. in debug verbosity. Signed-off-by: Mustafa ÖNCEL <support@lifemcserver.com>
1 parent 53d9557 commit 27c474d

9 files changed

Lines changed: 289 additions & 89 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
*
3+
* This file is part of Skript.
4+
*
5+
* Skript is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* Skript is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with Skript. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
*
19+
* Copyright 2011-2019 Peter Güttinger and contributors
20+
*
21+
*/
22+
23+
package ch.njol.skript;
24+
25+
import java.io.File;
26+
27+
/**
28+
* Represents a non-reflective {@link SkriptAddon}.
29+
* <p>
30+
* Add-ons implementing this interface has
31+
* public get file method. So Skript does not
32+
* use reflection to call the get file method.
33+
* <p>
34+
* The result of the get file method is cached anyway,
35+
* but this can speed up the first call.
36+
* <p>
37+
* The binary compatibility of this interface is
38+
* not guaranteed, and it does not exist in other skript forks.
39+
* <p>
40+
* I made it specially for my add-ons and the vanilla Skript,
41+
* so implementing this in a global add-on is probably a bad idea.
42+
*
43+
* @since 2.2.16
44+
*/
45+
public interface NonReflectiveAddon {
46+
/**
47+
* This method is originally protected in Bukkit's {@link org.bukkit.plugin.java.JavaPlugin} class,
48+
* But plugins implementing this interface has public get file methods.
49+
*
50+
* @return The plugin's JAR file if this is a plugin. You should check if it is a plugin before doing so,
51+
* because everyone can implement this interface.
52+
* @since 2.2.16
53+
*/
54+
/*public */File getFile();
55+
}

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@
4141
import ch.njol.skript.registrations.Classes;
4242
import ch.njol.skript.registrations.Converters;
4343
import ch.njol.skript.util.Date;
44-
import ch.njol.skript.util.ExceptionUtils;
45-
import ch.njol.skript.util.ScriptOptions;
46-
import ch.njol.skript.util.Version;
44+
import ch.njol.skript.util.*;
4745
import ch.njol.skript.variables.Variables;
4846
import ch.njol.util.Kleenean;
4947
import ch.njol.util.NonNullPair;
@@ -52,18 +50,23 @@
5250
import org.bukkit.Bukkit;
5351
import org.bukkit.event.Event;
5452
import org.eclipse.jdt.annotation.Nullable;
53+
import org.fusesource.jansi.Ansi;
5554

5655
import java.io.File;
5756
import java.io.FileFilter;
5857
import java.io.IOException;
5958
import java.util.*;
59+
import java.util.concurrent.TimeUnit;
6060
import java.util.function.Supplier;
6161
import java.util.regex.Matcher;
6262

6363
/**
6464
* @author Peter Güttinger
6565
*/
6666
public final class ScriptLoader {
67+
public static final boolean COLOR_BASED_ON_LOAD_TIMES = System.getProperty("skript.colorBasedOnLoadTimes") != null
68+
&& Boolean.parseBoolean("skript.colorBasedOnLoadTimes");
69+
6770
public static final List<TriggerSection> currentSections = new ArrayList<>();
6871

6972
public static final List<Loop> currentLoops = new ArrayList<>();
@@ -502,7 +505,7 @@ public static final ScriptInfo loadScript(final File f) {
502505
}
503506
hasConfiguraton = true;
504507
node.convertToEntries(0);
505-
final List<String> duplicateCheckList = new ArrayList<>();
508+
final ArrayList<String> duplicateCheckList = new ArrayList<>();
506509
for (final Node n : node) {
507510
if (!(n instanceof EntryNode)) {
508511
Skript.error("invalid line in the configuration");
@@ -654,7 +657,21 @@ public static final ScriptInfo loadScript(final File f) {
654657
}
655658

656659
if (Skript.logHigh() && startDate != null) {
657-
Skript.info("Loaded " + numTriggers + " trigger" + (numTriggers == 1 ? "" : "s") + ", " + numCommands + " command" + (numCommands == 1 ? "" : "s") + " and " + numFunctions + " function" + (numFunctions == 1 ? "" : "s") + " from '" + config.getFileName() + "' " + (Skript.logVeryHigh() ? "with source version " + scriptVersion + " " : "") + "in " + startDate.difference(new Date()));
660+
String prefix = "";
661+
String suffix = "";
662+
663+
final Timespan difference = startDate.difference(new Date());
664+
final long differenceInSeconds = TimeUnit.MILLISECONDS.toSeconds(difference.getMilliSeconds());
665+
666+
if (Skript.hasJLineSupport() && Skript.hasJansi() && COLOR_BASED_ON_LOAD_TIMES) {
667+
suffix += Ansi.ansi().a(Ansi.Attribute.RESET).reset().toString();
668+
if (differenceInSeconds > 5L) // Script take longer than 5 seconds to load
669+
prefix += Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).bold().toString();
670+
else if (differenceInSeconds > 3L) // Script take longer than 3 seconds to load
671+
prefix += Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).bold().toString();
672+
}
673+
674+
Skript.info(prefix + "Loaded " + numTriggers + " trigger" + (numTriggers == 1 ? "" : "s") + ", " + numCommands + " command" + (numCommands == 1 ? "" : "s") + " and " + numFunctions + " function" + (numFunctions == 1 ? "" : "s") + " from '" + config.getFileName() + "' " + (Skript.logVeryHigh() ? "with source version " + scriptVersion + " " : "") + "in " + difference + suffix);
658675
}
659676

660677
currentScript = null;

0 commit comments

Comments
 (0)