Class Skript
- All Implemented Interfaces:
io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner,net.kyori.adventure.key.Namespaced,org.bukkit.command.CommandExecutor,org.bukkit.command.TabCompleter,org.bukkit.command.TabExecutor,org.bukkit.event.Listener,org.bukkit.plugin.Plugin
Use this class to extend this plugin's functionality by adding more conditions, effects, expressions, etc.
If your plugin.yml contains 'depend: [Skript]' then your plugin will not start at all if Skript is not present. Add 'softdepend: [Skript]' to your plugin.yml if you want your plugin to work even if Skript isn't present, but want to make sure that Skript gets loaded before your plugin.
If you use 'softdepend' you can test whether Skript is loaded with 'Bukkit.getPluginManager().getPlugin("Skript") != null'
Once you made sure that Skript is loaded you can use Skript.getInstance() whenever you need a reference to the plugin, but you likely won't need it since all API
methods are static.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleA small value, useful for comparing doubles or floats.static final doubleA value a bit larger than 1static final Messagestatic final Messagestatic final Messagestatic final Messagestatic final intThe maximum ID a block can have in Minecraft.static final intThe maximum data value of Minecraft, i.e.static final Stringstatic final Thread.UncaughtExceptionHandler -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidadminBroadcast(String message) static voidstatic voidstatic booleanclassExists(String className) Tests whether a given class exists in the classpath.static voidcloseOnDisable(Closeable closeable) Registers a Closeable that should be closed when this plugin is disabled.static booleandebug()static voidstatic voidSends a debug message with formatted objects ifdebug()returns true.static voiddisableHookRegistration(Class<? extends ch.njol.skript.hooks.Hook<?>>... hooks) Disables the registration for the given hook classes.static booleandispatchCommand(org.bukkit.command.CommandSender sender, String command) Dispatches a command with calling command eventsstatic voidstatic voiderror(String error, ErrorQuality quality) Use this inSyntaxElement.init(Expression[], int, Kleenean, ch.njol.skript.lang.SkriptParser.ParseResult)(and other methods that are called during the parsing) to log errors with a specificErrorQuality.static voidSends an error message with formatted objects.static voidstatic EmptyStacktraceExceptionexception(@Nullable Throwable cause, @Nullable TriggerItem item, String... info) static EmptyStacktraceExceptionexception(@Nullable Throwable cause, @Nullable Thread thread, @Nullable TriggerItem item, String... info) Used if something happens that shouldn't happenstatic EmptyStacktraceExceptionstatic EmptyStacktraceExceptionstatic EmptyStacktraceExceptionUsed if something happens that shouldn't happenstatic ExperimentRegistrystatic booleanfieldExists(Class<?> c, String fieldName) Tests whether a field exists in the given class.static @Nullable SkriptAddonstatic @Nullable SkriptAddongetAddon(org.bukkit.plugin.java.JavaPlugin plugin) static SkriptAddonstatic @Unmodifiable Collection<SkriptAddon> static @Unmodifiable Collection<SyntaxElementInfo<? extends Condition>> static @Unmodifiable Collection<SyntaxElementInfo<? extends Effect>> static @Unmodifiable Collection<SkriptEventInfo<?>> static Iterator<ExpressionInfo<?, ?>> static Iterator<ExpressionInfo<?, ?>> getExpressions(Class<?>... returnTypes) static Skriptstatic @Nullable org.bstats.bukkit.Metricsstatic Versionstatic Stringstatic RuntimeErrorManagerstatic @Unmodifiable Collection<SyntaxElementInfo<? extends Section>> static ServerPlatformstatic Stringstatic @Unmodifiable Collection<SyntaxElementInfo<? extends Statement>> static @Unmodifiable List<StructureInfo<? extends Structure>> static SyntaxOrigingetSyntaxOrigin(Class<?> source) Attempts to create a SyntaxOrigin from a provided class.@Nullable SkriptUpdaterGets the updater instance currently used by Skript.static Versionstatic Stringstatic voidstatic voidstatic Skriptinstance()static booleanstatic booleanstatic booleanisHookEnabled(Class<? extends ch.njol.skript.hooks.Hook<?>> hook) Checks whether a hook has been enabled.static booleanstatic booleanisRunningMinecraft(int major, int minor) static booleanisRunningMinecraft(int major, int minor, int revision) static booleanstatic booleanstatic booleanlogHigh()static booleanstatic booleanstatic voidMark that an exception has occurred at some point during runtime.static voidSimilar toinfo(CommandSender, String)but no [Skript] prefix is added.static booleanmethodExists(Class<?> c, String methodName, Class<?>... parameterTypes) Tests whether a method exists in the given class.static booleanmethodExists(Class<?> c, String methodName, Class<?>[] parameterTypes, Class<?> returnType) Tests whether a method exists in the given class, and whether the return type matches the expected one.static ThreadCreates a new Thread and sets its UncaughtExceptionHandler.voidvoidonEnable()voidonPluginDisable(org.bukkit.event.server.PluginDisableEvent event) static voidstatic voidstatic SkriptAddonregisterAddon(org.bukkit.plugin.java.JavaPlugin plugin) Registers an addon to Skript.static <E extends Condition>
voidregisterCondition(Class<E> conditionClass, Condition.ConditionType type, String... patterns) Registers aCondition.static <E extends Condition>
voidregisterCondition(Class<E> conditionClass, String... patterns) Registers aCondition.static <E extends Effect>
voidregisterEffect(Class<E> effectClass, String... patterns) Registers anEffect.static <E extends SkriptEvent>
SkriptEventInfo<E> registerEvent(String name, Class<E> eventClass, Class<? extends org.bukkit.event.Event>[] events, String... patterns) Registers an event.static <E extends SkriptEvent>
SkriptEventInfo<E> registerEvent(String name, Class<E> c, Class<? extends org.bukkit.event.Event> event, String... patterns) Registers an event.static <E extends Expression<T>,T>
voidregisterExpression(Class<E> expressionClass, Class<T> returnType, ExpressionType type, String... patterns) Registers an expression.static <E extends Section>
voidregisterSection(Class<E> sectionClass, String... patterns) Registers aSection.static <E extends Structure>
voidregisterSimpleStructure(Class<E> structureClass, String... patterns) static <E extends Structure>
voidregisterStructure(Class<E> structureClass, String... patterns) static <E extends Structure>
voidregisterStructure(Class<E> structureClass, EntryValidator entryValidator, String... patterns) static <E extends Structure>
voidregisterStructure(Class<E> structureClass, EntryValidator entryValidator, DefaultSyntaxInfos.Structure.NodeType nodeType, String... patterns) static booleantesting()static StringtoString(double n) static voidCheck minecraft version and assign it to minecraftVersion field This method is created to update MC version before onEnable methodstatic voidMethods inherited from class org.bukkit.plugin.java.JavaPlugin
getClassLoader, getCommand, getConfig, getDataFolder, getDefaultBiomeProvider, getDefaultWorldGenerator, getDescription, getFile, getLifecycleManager, getLogger, getPlugin, getPluginLoader, getPluginMeta, getProvidingPlugin, getResource, getServer, getTextResource, init, init, isEnabled, isNaggable, onCommand, onLoad, onTabComplete, registerCommand, registerCommand, registerCommand, registerCommand, reloadConfig, saveConfig, saveDefaultConfig, saveResource, setEnabled, setNaggable, toStringMethods inherited from class org.bukkit.plugin.PluginBase
equals, getName, hashCode, namespaceMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.bukkit.plugin.Plugin
getComponentLogger, getDataPath, getLog4JLogger, getSLF4JLogger
-
Field Details
-
m_invalid_reload
-
m_finished_loading
-
m_no_errors
-
m_no_scripts
-
SCRIPTSFOLDER
- See Also:
-
EPSILON
public static final double EPSILONA small value, useful for comparing doubles or floats.E.g. to test whether two floating-point numbers are equal:
Math.abs(a - b) < Skript.EPSILON
or whether a location is within a specific radius of another location:location.distanceSquared(center) - radius * radius < Skript.EPSILON
- See Also:
-
EPSILON_MULT
public static final double EPSILON_MULTA value a bit larger than 1- See Also:
-
MAXBLOCKID
public static final int MAXBLOCKIDThe maximum ID a block can have in Minecraft.- See Also:
-
MAXDATAVALUE
public static final int MAXDATAVALUEThe maximum data value of Minecraft, i.e. Short.MAX_VALUE - Short.MIN_VALUE.- See Also:
-
UEH
-
-
Constructor Details
-
Skript
- Throws:
IllegalStateException
-
-
Method Details
-
getInstance
-
instance
-
updateMinecraftVersion
public static void updateMinecraftVersion()Check minecraft version and assign it to minecraftVersion field This method is created to update MC version before onEnable method -
getVersion
-
getWarningMessage
-
getRestartMessage
-
getServerPlatform
-
isHookEnabled
Checks whether a hook has been enabled.- Parameters:
hook- The hook to check.- Returns:
- Whether the hook is enabled.
- See Also:
-
isFinishedLoadingHooks
public static boolean isFinishedLoadingHooks()- Returns:
- whether hooks have been loaded,
and if
disableHookRegistration(Class[])won't error because of this.
-
disableHookRegistration
@SafeVarargs public static void disableHookRegistration(Class<? extends ch.njol.skript.hooks.Hook<?>>... hooks) Disables the registration for the given hook classes. If Skript has been enabled, this method will throw an API exception. It should be used in something likeJavaPlugin.onLoad().- Parameters:
hooks- The hooks to disable the registration of.- See Also:
-
experiments
- Returns:
- The manager for experimental, optional features.
-
getScriptsFolder
- Returns:
- The folder containing all Scripts.
-
getRuntimeErrorManager
-
onEnable
public void onEnable()- Specified by:
onEnablein interfaceorg.bukkit.plugin.Plugin- Overrides:
onEnablein classorg.bukkit.plugin.java.JavaPlugin
-
getMinecraftVersion
-
isRunningCraftBukkit
public static boolean isRunningCraftBukkit()- Returns:
- Whether this server is running CraftBukkit
-
isRunningMinecraft
public static boolean isRunningMinecraft(int major, int minor) - Returns:
- Whether this server is running Minecraft major.minor or higher
-
isRunningMinecraft
public static boolean isRunningMinecraft(int major, int minor, int revision) -
isRunningMinecraft
-
classExists
Tests whether a given class exists in the classpath.- Parameters:
className- Thecanonical nameof the class- Returns:
- Whether the given class exists.
-
methodExists
Tests whether a method exists in the given class.- Parameters:
c- The classmethodName- The name of the methodparameterTypes- The parameter types of the method- Returns:
- Whether the given method exists.
-
methodExists
public static boolean methodExists(Class<?> c, String methodName, Class<?>[] parameterTypes, Class<?> returnType) Tests whether a method exists in the given class, and whether the return type matches the expected one.Note that this method doesn't work properly if multiple methods with the same name and parameters exist but have different return types.
- Parameters:
c- The classmethodName- The name of the methodparameterTypes- The parameter types of the methodreturnType- The expected return type- Returns:
- Whether the given method exists.
-
fieldExists
Tests whether a field exists in the given class.- Parameters:
c- The classfieldName- The name of the field- Returns:
- Whether the given field exists.
-
getMetrics
@Nullable public static @Nullable org.bstats.bukkit.Metrics getMetrics() -
closeOnDisable
Registers a Closeable that should be closed when this plugin is disabled.All registered Closeables will be closed after all scripts have been stopped.
- Parameters:
closeable-
-
onPluginDisable
public void onPluginDisable(org.bukkit.event.server.PluginDisableEvent event) -
onDisable
public void onDisable()- Specified by:
onDisablein interfaceorg.bukkit.plugin.Plugin- Overrides:
onDisablein classorg.bukkit.plugin.java.JavaPlugin
-
outdatedError
public static void outdatedError() -
outdatedError
-
toString
-
newThread
Creates a new Thread and sets its UncaughtExceptionHandler. The Thread is not started automatically. -
isAcceptRegistrations
public static boolean isAcceptRegistrations() -
checkAcceptRegistrations
public static void checkAcceptRegistrations() -
registerAddon
Registers an addon to Skript. This is currently not required for addons to work, but the returnedSkriptAddonprovides useful methods for registering syntax elements and adding new strings to Skript's localization system (e.g. the required "types.[type]" strings for registered classes).- Parameters:
plugin- The plugin
-
getAddon
-
getAddon
-
getAddons
-
getAddonInstance
- Returns:
- A
SkriptAddonrepresenting Skript.
-
getSyntaxOrigin
Attempts to create a SyntaxOrigin from a provided class. -
registerCondition
public static <E extends Condition> void registerCondition(Class<E> conditionClass, String... patterns) throws IllegalArgumentException Registers aCondition.- Parameters:
conditionClass- The condition's classpatterns- Skript patterns to match this condition- Throws:
IllegalArgumentException
-
registerCondition
public static <E extends Condition> void registerCondition(Class<E> conditionClass, Condition.ConditionType type, String... patterns) throws IllegalArgumentException Registers aCondition.- Parameters:
conditionClass- The condition's classtype- The type of condition which affects its priority in the parsing searchpatterns- Skript patterns to match this condition- Throws:
IllegalArgumentException
-
registerEffect
public static <E extends Effect> void registerEffect(Class<E> effectClass, String... patterns) throws IllegalArgumentException Registers anEffect.- Parameters:
effectClass- The effect's classpatterns- Skript patterns to match this effect- Throws:
IllegalArgumentException
-
registerSection
public static <E extends Section> void registerSection(Class<E> sectionClass, String... patterns) throws IllegalArgumentException Registers aSection.- Parameters:
sectionClass- The section's classpatterns- Skript patterns to match this section- Throws:
IllegalArgumentException- See Also:
-
getStatements
-
getConditions
-
getEffects
-
getSections
-
registerExpression
public static <E extends Expression<T>,T> void registerExpression(Class<E> expressionClass, Class<T> returnType, ExpressionType type, String... patterns) throws IllegalArgumentException Registers an expression.- Parameters:
expressionClass- The expression's classreturnType- The superclass of all values returned by the expressiontype- The expression'stype. This is used to determine in which order to try to parse expressions.patterns- Skript patterns that match this expression- Throws:
IllegalArgumentException- if returnType is not a normal class
-
getExpressions
-
getExpressions
-
registerEvent
public static <E extends SkriptEvent> SkriptEventInfo<E> registerEvent(String name, Class<E> c, Class<? extends org.bukkit.event.Event> event, String... patterns) Registers an event.- Parameters:
name- Capitalised name of the event without leading "On" which is added automatically (Start the name with an asterisk to prevent this). Used for error messages and the documentation.c- The event's classevent- The Bukkit event this event applies topatterns- Skript patterns to match this event- Returns:
- A SkriptEventInfo representing the registered event. Used to generate Skript's documentation.
-
registerEvent
public static <E extends SkriptEvent> SkriptEventInfo<E> registerEvent(String name, Class<E> eventClass, Class<? extends org.bukkit.event.Event>[] events, String... patterns) Registers an event.- Parameters:
name- The name of the event, used for error messageseventClass- The event's classevents- The Bukkit events this event applies topatterns- Skript patterns to match this event- Returns:
- A SkriptEventInfo representing the registered event. Used to generate Skript's documentation.
-
registerStructure
-
registerSimpleStructure
-
registerStructure
public static <E extends Structure> void registerStructure(Class<E> structureClass, EntryValidator entryValidator, String... patterns) -
registerStructure
public static <E extends Structure> void registerStructure(Class<E> structureClass, EntryValidator entryValidator, DefaultSyntaxInfos.Structure.NodeType nodeType, String... patterns) -
getEvents
-
getStructures
-
dispatchCommand
Dispatches a command with calling command events- Parameters:
sender-command-- Returns:
- Whether the command was run
-
logNormal
public static boolean logNormal() -
logHigh
public static boolean logHigh() -
logVeryHigh
public static boolean logVeryHigh() -
debug
public static boolean debug() -
testing
public static boolean testing() -
log
-
debug
-
debug
Sends a debug message with formatted objects ifdebug()returns true.- Parameters:
message- The message to sendobjects- The objects to format the message with- See Also:
-
info
- See Also:
-
warning
- See Also:
-
error
- See Also:
-
error
Sends an error message with formatted objects.- Parameters:
message- The message to sendobjects- The objects to format the message with- See Also:
-
error
Use this inSyntaxElement.init(Expression[], int, Kleenean, ch.njol.skript.lang.SkriptParser.ParseResult)(and other methods that are called during the parsing) to log errors with a specificErrorQuality.- Parameters:
error-quality-
-
exception
Used if something happens that shouldn't happen- Parameters:
info- Description of the error and additional information- Returns:
- an EmptyStacktraceException to throw if code execution should terminate.
-
exception
public static EmptyStacktraceException exception(@Nullable @Nullable Throwable cause, String... info) -
exception
public static EmptyStacktraceException exception(@Nullable @Nullable Throwable cause, @Nullable @Nullable Thread thread, String... info) -
exception
public static EmptyStacktraceException exception(@Nullable @Nullable Throwable cause, @Nullable @Nullable TriggerItem item, String... info) -
markErrored
public static void markErrored()Mark that an exception has occurred at some point during runtime. Only used for Skript's testing system. -
exception
public static EmptyStacktraceException exception(@Nullable @Nullable Throwable cause, @Nullable @Nullable Thread thread, @Nullable @Nullable TriggerItem item, String... info) Used if something happens that shouldn't happen- Parameters:
cause- exception that shouldn't occurinfo- Description of the error and additional information- Returns:
- an EmptyStacktraceException to throw if code execution should terminate.
-
getSkriptPrefix
-
info
-
broadcast
- Parameters:
message-permission-- See Also:
-
adminBroadcast
-
message
Similar toinfo(CommandSender, String)but no [Skript] prefix is added.- Parameters:
sender-info-
-
error
-
getUpdater
Gets the updater instance currently used by Skript.- Returns:
- SkriptUpdater instance.
-