-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made plugin multi-modular for spigot and paper support. Made command system far better.
- Loading branch information
Showing
82 changed files
with
2,702 additions
and
1,482 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>eu.mikart</groupId> | ||
<artifactId>AnimVanish</artifactId> | ||
<version>1.1.0</version> | ||
</parent> | ||
|
||
<groupId>eu.mikart.animvanish</groupId> | ||
<artifactId>animvanish-common</artifactId> | ||
<version>1.1.0</version> | ||
|
||
<properties> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>jitpack.io</id> | ||
<url>https://jitpack.io</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<!-- PagineDown - William278 --> | ||
<dependency> | ||
<groupId>net.william278</groupId> | ||
<artifactId>PagineDown</artifactId> | ||
<version>1.1</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<!-- DesertWell - William278 --> | ||
<dependency> | ||
<groupId>net.william278</groupId> | ||
<artifactId>DesertWell</artifactId> | ||
<version>2.0.4</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<!-- Adventure --> | ||
<dependency> | ||
<groupId>net.kyori</groupId> | ||
<artifactId>adventure-api</artifactId> | ||
<version>4.14.0</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<!-- Adventure Platform API --> | ||
<dependency> | ||
<groupId>net.kyori</groupId> | ||
<artifactId>adventure-platform-api</artifactId> | ||
<version>4.3.2</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<!-- ConfigLib - YAML --> | ||
<dependency> | ||
<groupId>de.exlll</groupId> | ||
<artifactId>configlib-yaml</artifactId> | ||
<version>4.5.0</version> | ||
</dependency> | ||
|
||
<!-- Guava --> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
<version>32.1.3-jre</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<!-- Adventure Text - MiniMessage --> | ||
<dependency> | ||
<groupId>net.kyori</groupId> | ||
<artifactId>adventure-text-minimessage</artifactId> | ||
<version>4.16.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>commons-lang</groupId> | ||
<artifactId>commons-lang</artifactId> | ||
<version>2.6</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
48 changes: 48 additions & 0 deletions
48
common/src/main/java/eu/mikart/animvanish/IAnimVanish.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package eu.mikart.animvanish; | ||
|
||
import eu.mikart.animvanish.config.ConfigProvider; | ||
import eu.mikart.animvanish.effects.IEffectManager; | ||
import eu.mikart.animvanish.hooks.Hook; | ||
import eu.mikart.animvanish.user.ConsoleUser; | ||
import eu.mikart.animvanish.util.Version; | ||
import net.kyori.adventure.audience.Audience; | ||
import net.kyori.adventure.platform.AudienceProvider; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.UUID; | ||
import java.util.logging.Logger; | ||
|
||
public interface IAnimVanish extends ConfigProvider { | ||
|
||
String getPluginVersion(); | ||
|
||
IEffectManager getEffectManager(); | ||
|
||
@NotNull | ||
AudienceProvider getAudiences(); | ||
|
||
@NotNull | ||
default Version getVersion() { | ||
return new Version(getPluginVersion()); | ||
} | ||
|
||
Hook getCurrentHook(); | ||
|
||
Logger getLogger(); | ||
|
||
@NotNull | ||
default Audience getAudience(@NotNull UUID user) { | ||
return getAudiences().player(user); | ||
} | ||
|
||
@NotNull | ||
default ConsoleUser getConsole() { | ||
return ConsoleUser.wrap(getAudiences().console()); | ||
} | ||
|
||
default void reload() { | ||
loadConfig(); | ||
} | ||
|
||
default void loadExtra() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
common/src/main/java/eu/mikart/animvanish/api/AnimVanishAPI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package eu.mikart.animvanish.api; | ||
|
||
import eu.mikart.animvanish.IAnimVanish; | ||
import eu.mikart.animvanish.effects.BareEffect; | ||
import eu.mikart.animvanish.hooks.Hook; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import net.kyori.adventure.text.Component; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Optional; | ||
|
||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class AnimVanishAPI { | ||
protected static AnimVanishAPI instance; | ||
protected final IAnimVanish plugin; | ||
|
||
|
||
/** | ||
* Register an effect to the plugin | ||
* @param effect the effect to register | ||
* @since 1.1.0 | ||
*/ | ||
public void registerEffect(BareEffect effect) { | ||
plugin.getEffectManager().registerEffect(effect); | ||
} | ||
|
||
/** | ||
* Unregister an effect from the plugin | ||
* | ||
* @param effect the effect to unregister | ||
* @since 1.1.0 | ||
*/ | ||
public void unregisterEffect(BareEffect effect) { | ||
plugin.getEffectManager().unregisterEffect(effect); | ||
} | ||
|
||
/** | ||
* Get the currentHook of the plugin. I have no idea why you would need this. But here it is. | ||
* @return the currentHook of the plugin | ||
* @since 1.1.0 | ||
*/ | ||
public Hook getCurrentHook() { | ||
return plugin.getCurrentHook(); | ||
} | ||
|
||
/** | ||
* Get a raw locale from the plugin locale file | ||
* | ||
* @param localeId the locale ID to get | ||
* @param replacements the replacements to make in the locale | ||
* @return the locale, with replacements made | ||
* @since 1.1.0 | ||
*/ | ||
public Optional<String> getRawLocale(@NotNull String localeId, @NotNull String... replacements) { | ||
return plugin.getLocales().getRawLocale(localeId, replacements); | ||
} | ||
|
||
/** | ||
* Get a locale from the plugin locale file | ||
* | ||
* @param localeId the locale ID to get | ||
* @param replacements the replacements to make in the locale | ||
* @return the locale as a formatted adventure {@link Component}, with replacements made | ||
* @since 1.1.0 | ||
*/ | ||
public Optional<Component> getLocale(@NotNull String localeId, @NotNull String... replacements) { | ||
return plugin.getLocales().getLocale(localeId, replacements); | ||
} | ||
|
||
/** | ||
* Get an instance of the AnimVanish API. | ||
* | ||
* @return instance of the AnimVanish API | ||
* @throws NotRegisteredException if the API has not yet been registered. | ||
* @since 1.1.0 | ||
*/ | ||
@NotNull | ||
public static AnimVanishAPI getInstance() throws NotRegisteredException { | ||
if (instance == null) { | ||
throw new NotRegisteredException(); | ||
} | ||
return instance; | ||
} | ||
|
||
/** | ||
* <b>(Internal use only)</b> - Unregister the API instance. | ||
* | ||
* @since 1.1.0 | ||
*/ | ||
@ApiStatus.Internal | ||
public static void unregister() { | ||
instance = null; | ||
} | ||
|
||
/** | ||
* An exception indicating the plugin has been accessed before it has been registered. | ||
* | ||
* @since 1.1.0 | ||
*/ | ||
public static final class NotRegisteredException extends IllegalStateException { | ||
|
||
private static final String MESSAGE = """ | ||
Could not access the AnimVanish API as it has not yet been registered. This could be because: | ||
1) AnimVanish has failed to enable successfully | ||
2) Your plugin isn't set to load after AnimVanish has | ||
(Check if it set as a (soft)depend in plugin.yml or to load: BEFORE in paper-plugin.yml?) | ||
3) You are attempting to access AnimVanish on plugin construction/before your plugin has enabled."""; | ||
|
||
NotRegisteredException() { | ||
super(MESSAGE); | ||
} | ||
|
||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
common/src/main/java/eu/mikart/animvanish/config/ConfigProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package eu.mikart.animvanish.config; | ||
|
||
import de.exlll.configlib.NameFormatters; | ||
import de.exlll.configlib.YamlConfigurationProperties; | ||
import de.exlll.configlib.YamlConfigurationStore; | ||
import de.exlll.configlib.YamlConfigurations; | ||
import eu.mikart.animvanish.IAnimVanish; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.logging.Level; | ||
|
||
/** | ||
* The configuration has been inspired by <a href="https://github.com/William278/HuskTowns">HuskTowns</a> | ||
* which is licensed under the Apache License 2.0. | ||
*/ | ||
public interface ConfigProvider { | ||
|
||
@NotNull | ||
YamlConfigurationProperties.Builder<?> YAML_CONFIGURATION_PROPERTIES = YamlConfigurationProperties.newBuilder() | ||
.charset(StandardCharsets.UTF_8) | ||
.setNameFormatter(NameFormatters.LOWER_UNDERSCORE); | ||
|
||
|
||
default void loadConfig() { | ||
loadSettings(); | ||
loadLocales(); | ||
} | ||
|
||
@NotNull | ||
Settings getSettings(); | ||
|
||
void setSettings(@NotNull Settings settings); | ||
|
||
default void loadSettings() { | ||
setSettings(YamlConfigurations.update( | ||
getConfigDirectory().resolve("config.yml"), | ||
Settings.class, | ||
YAML_CONFIGURATION_PROPERTIES.header(Settings.CONFIG_HEADER).build() | ||
)); | ||
} | ||
|
||
@NotNull | ||
Locales getLocales(); | ||
|
||
void setLocales(@NotNull Locales locales); | ||
|
||
/** | ||
* Load the locales from the config file | ||
* | ||
* @since 1.1.0 | ||
*/ | ||
default void loadLocales() { | ||
final YamlConfigurationStore<Locales> store = new YamlConfigurationStore<>( | ||
Locales.class, YAML_CONFIGURATION_PROPERTIES.header(Locales.CONFIG_HEADER).build() | ||
); | ||
// Read existing locales if present | ||
final Path path = getConfigDirectory().resolve(String.format("messages-%s.yml", getSettings().getLanguage())); | ||
if (Files.exists(path)) { | ||
setLocales(store.load(path)); | ||
return; | ||
} | ||
|
||
// Otherwise, save and read the default locales | ||
try (InputStream input = getResource(String.format("locales/%s.yml", getSettings().getLanguage()))) { | ||
final Locales locales = store.read(input); | ||
store.save(locales, path); | ||
setLocales(locales); | ||
} catch (Throwable e) { | ||
getPlugin().getLogger().log(Level.SEVERE, "An error occurred loading the locales (invalid lang code?)", e); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Get a plugin resource | ||
* | ||
* @param name The name of the resource | ||
* @return the resource, if found | ||
* @since 1.1.0 | ||
*/ | ||
InputStream getResource(@NotNull String name); | ||
|
||
/** | ||
* Get the plugin config directory | ||
* | ||
* @return the plugin config directory | ||
* @since 1.1.0 | ||
*/ | ||
@NotNull | ||
Path getConfigDirectory(); | ||
|
||
@NotNull | ||
IAnimVanish getPlugin(); | ||
|
||
} |
Oops, something went wrong.