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

Commit

Permalink
Use aliases on the JAR, more changes and the v2.2.16-beta2
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
Mustafa ÖNCEL committed May 30, 2019
1 parent 53d9557 commit 27c474d
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 89 deletions.
55 changes: 55 additions & 0 deletions src/main/java/ch/njol/skript/NonReflectiveAddon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
*
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <https://www.gnu.org/licenses/>.
*
*
* Copyright 2011-2019 Peter Güttinger and contributors
*
*/

package ch.njol.skript;

import java.io.File;

/**
* Represents a non-reflective {@link SkriptAddon}.
* <p>
* Add-ons implementing this interface has
* public get file method. So Skript does not
* use reflection to call the get file method.
* <p>
* The result of the get file method is cached anyway,
* but this can speed up the first call.
* <p>
* The binary compatibility of this interface is
* not guaranteed, and it does not exist in other skript forks.
* <p>
* I made it specially for my add-ons and the vanilla Skript,
* so implementing this in a global add-on is probably a bad idea.
*
* @since 2.2.16
*/
public interface NonReflectiveAddon {
/**
* This method is originally protected in Bukkit's {@link org.bukkit.plugin.java.JavaPlugin} class,
* But plugins implementing this interface has public get file methods.
*
* @return The plugin's JAR file if this is a plugin. You should check if it is a plugin before doing so,
* because everyone can implement this interface.
* @since 2.2.16
*/
/*public */File getFile();
}
27 changes: 22 additions & 5 deletions src/main/java/ch/njol/skript/ScriptLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@
import ch.njol.skript.registrations.Classes;
import ch.njol.skript.registrations.Converters;
import ch.njol.skript.util.Date;
import ch.njol.skript.util.ExceptionUtils;
import ch.njol.skript.util.ScriptOptions;
import ch.njol.skript.util.Version;
import ch.njol.skript.util.*;
import ch.njol.skript.variables.Variables;
import ch.njol.util.Kleenean;
import ch.njol.util.NonNullPair;
Expand All @@ -52,18 +50,23 @@
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;
import org.fusesource.jansi.Ansi;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import java.util.regex.Matcher;

/**
* @author Peter Güttinger
*/
public final class ScriptLoader {
public static final boolean COLOR_BASED_ON_LOAD_TIMES = System.getProperty("skript.colorBasedOnLoadTimes") != null
&& Boolean.parseBoolean("skript.colorBasedOnLoadTimes");

public static final List<TriggerSection> currentSections = new ArrayList<>();

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

if (Skript.logHigh() && startDate != null) {
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()));
String prefix = "";
String suffix = "";

final Timespan difference = startDate.difference(new Date());
final long differenceInSeconds = TimeUnit.MILLISECONDS.toSeconds(difference.getMilliSeconds());

if (Skript.hasJLineSupport() && Skript.hasJansi() && COLOR_BASED_ON_LOAD_TIMES) {
suffix += Ansi.ansi().a(Ansi.Attribute.RESET).reset().toString();
if (differenceInSeconds > 5L) // Script take longer than 5 seconds to load
prefix += Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).bold().toString();
else if (differenceInSeconds > 3L) // Script take longer than 3 seconds to load
prefix += Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).bold().toString();
}

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);
}

currentScript = null;
Expand Down
Loading

0 comments on commit 27c474d

Please sign in to comment.