Package ch.njol.skript
Class SkriptAddon
java.lang.Object
ch.njol.skript.SkriptAddon
- All Implemented Interfaces:
SkriptAddon
,ViewProvider<SkriptAddon>
Utility class for Skript addons. Use
Skript.registerAddon(JavaPlugin)
to create a SkriptAddon instance for your plugin.-
Field Summary
-
Method Summary
Modifier and TypeMethodDescription@Nullable File
getFile()
The first invocation of this method uses reflection to invoke the protected methodJavaPlugin.getFile()
to get the plugin's jar file.@Nullable String
getName()
boolean
hasRegistry
(Class<? extends Registry<?>> registryClass) Determines whether a registry has been stored underregistryClass
.loadClasses
(String basePackage, String... subPackages) Loads classes of the plugin by package.name()
<R extends Registry<?>>
RObtains the registry stored underregistryClass
.<R extends Registry<?>>
RSearches for a registry stored underregistryClass
.void
removeRegistry
(Class<? extends Registry<?>> registryClass) Removes the registry stored underregistryClass
.setLanguageFileDirectory
(String directory) Makes Skript load language files from the specified directory, e.g.Class
<?> source()
<R extends Registry<?>>
voidstoreRegistry
(Class<R> registryClass, R registry) Stores a registry underregistryClass
.final String
toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.skriptlang.skript.addon.SkriptAddon
loadModules, unmodifiableView
-
Field Details
-
plugin
public final org.bukkit.plugin.java.JavaPlugin plugin -
version
-
-
Method Details
-
toString
-
getName
-
loadClasses
Loads classes of the plugin by package. Useful for registering many syntax elements like Skript does it.- Parameters:
basePackage
- The base package to add to all sub packages, e.g. "ch.njol.skript".subPackages
- Which subpackages of the base package should be loaded, e.g. "expressions", "conditions", "effects". Subpackages of these packages will be loaded as well. Use an empty array to load all subpackages of the base package.- Returns:
- This SkriptAddon
- Throws:
IOException
- If some error occurred attempting to read the plugin's jar file.
-
setLanguageFileDirectory
Makes Skript load language files from the specified directory, e.g. "lang" or "skript lang" if you have a lang folder yourself. Localised files will be read from the plugin's jar and the plugin's data folder, but the default English file is only taken from the jar and must exist!- Parameters:
directory
- Directory name- Returns:
- This SkriptAddon
-
getLanguageFileDirectory
-
getFile
The first invocation of this method uses reflection to invoke the protected methodJavaPlugin.getFile()
to get the plugin's jar file. The file is then cached and returned upon subsequent calls to this method to reduce usage of reflection. Only nullable if there was an exception thrown.- Returns:
- The jar file of the plugin.
-
source
- Specified by:
source
in interfaceSkriptAddon
- Returns:
- A class from the application that registered this addon. Typically, this is the main class or the specific class in which registration occurred.
-
name
- Specified by:
name
in interfaceSkriptAddon
- Returns:
- The name of this addon.
-
storeRegistry
Description copied from interface:SkriptAddon
Stores a registry underregistryClass
. If a registry is already stored underregistryClass
, it will be replaced.- Specified by:
storeRegistry
in interfaceSkriptAddon
- Type Parameters:
R
- The type of registry.- Parameters:
registryClass
- The class (key) to storeregistry
under.registry
- The registry to store.
-
removeRegistry
Description copied from interface:SkriptAddon
Removes the registry stored underregistryClass
. It is safe to call this method even if a registry is not stored underregistryClass
.- Specified by:
removeRegistry
in interfaceSkriptAddon
- Parameters:
registryClass
- The class (key) that the registry to remove is under.
-
hasRegistry
Description copied from interface:SkriptAddon
Determines whether a registry has been stored underregistryClass
.- Specified by:
hasRegistry
in interfaceSkriptAddon
- Parameters:
registryClass
- The class (key) to search for a registry under.- Returns:
- Whether a registry is stored under
registryClass
.
-
registry
Description copied from interface:SkriptAddon
Obtains the registry stored underregistryClass
. This method will never return null, meaning it may be necessary to callSkriptAddon.hasRegistry(Class)
if you are not sure whether the registry you need exists.- Specified by:
registry
in interfaceSkriptAddon
- Type Parameters:
R
- The type of registry.- Parameters:
registryClass
- The class (key) that the registry is stored under.- Returns:
- The registry stored under
registryClass
.
-
registry
@Experimental public <R extends Registry<?>> R registry(Class<R> registryClass, Supplier<R> putIfAbsent) Description copied from interface:SkriptAddon
Searches for a registry stored underregistryClass
. If the search fails,putIfAbsent
will be used to get, store, and return a registry of the requested type.- Specified by:
registry
in interfaceSkriptAddon
- Type Parameters:
R
- The type of registry.- Parameters:
registryClass
- The class (key) to search for a registry under.putIfAbsent
- A supplier to use for creating an instance of the desired type of registry if one is not already stored underregistryClass
.- Returns:
- The registry stored under
registryClass
or created fromputIfAbsent
.
-
syntaxRegistry
- Specified by:
syntaxRegistry
in interfaceSkriptAddon
- Returns:
- A syntax registry for this addon's syntax.
-
localizer
- Specified by:
localizer
in interfaceSkriptAddon
- Returns:
- A localizer for this addon's localizations.
-