initial commit
This commit is contained in:
61
plugin-utils/build.gradle.kts
Normal file
61
plugin-utils/build.gradle.kts
Normal file
@@ -0,0 +1,61 @@
|
||||
plugins {
|
||||
id("java-library")
|
||||
id("maven-publish")
|
||||
}
|
||||
|
||||
group = "io.github.axolotsh"
|
||||
version = "1.0-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
|
||||
maven {
|
||||
name = "axolotsh-repository"
|
||||
url = uri("https://maven.axolotsh.org/snapshots")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("io.github.axolotsh:localizationlib-abstraction:1.0-SNAPSHOT")
|
||||
|
||||
compileOnly("org.projectlombok:lombok:1.18.46")
|
||||
annotationProcessor("org.projectlombok:lombok:1.18.46")
|
||||
|
||||
implementation("com.google.inject:guice:7.0.0")
|
||||
|
||||
compileOnly("dev.jorel:commandapi-paper-core:11.2.0")
|
||||
|
||||
compileOnly("io.papermc.paper:paper-api:26.1.2.build.+")
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion = JavaLanguageVersion.of(25)
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("mavenJava") {
|
||||
from(components["java"])
|
||||
|
||||
groupId = project.group.toString()
|
||||
artifactId = project.name
|
||||
version = project.version.toString()
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
name = "Reposilite"
|
||||
|
||||
val releasesUrl = "https://maven.axolotsh.org/releases"
|
||||
val snapshotsUrl = "https://maven.axolotsh.org/snapshots"
|
||||
url = uri(if (version.toString().endsWith("SNAPSHOT")) snapshotsUrl else releasesUrl)
|
||||
|
||||
credentials {
|
||||
username = providers.gradleProperty("reposiliteUser").orNull ?: "admin"
|
||||
password = providers.gradleProperty("reposilitePassword").orNull ?: "password"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package io.github.axolotsh.pluginutils;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import io.github.axolotsh.pluginutils.entities.ICommand;
|
||||
|
||||
public abstract class BaseJavaPlugin extends JavaPlugin {
|
||||
@Inject
|
||||
protected JavaPlugin javaPlugin;
|
||||
|
||||
@Inject
|
||||
protected Server server;
|
||||
|
||||
@Inject
|
||||
protected PluginManager pluginManager;
|
||||
|
||||
@Inject
|
||||
protected BukkitScheduler scheduler;
|
||||
|
||||
@Inject
|
||||
protected FileConfiguration fileConfiguration;
|
||||
|
||||
@Inject
|
||||
protected Set<Listener> listeners;
|
||||
|
||||
@Inject
|
||||
protected Set<ICommand> commands;
|
||||
|
||||
@Inject
|
||||
protected Logger logger;
|
||||
|
||||
protected Injector createInjector(JavaPluginModule module) {
|
||||
var injector = Guice.createInjector(module);
|
||||
|
||||
injector.injectMembers(this);
|
||||
|
||||
return injector;
|
||||
}
|
||||
|
||||
protected void registerListeners() {
|
||||
for (var listener : listeners) {
|
||||
pluginManager.registerEvents(listener, this);
|
||||
logger.trace("Event listener '{}' registered.", listener.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
protected void registerCommands() {
|
||||
for (var command : commands) {
|
||||
var commandClassName = command.getClass().getName();
|
||||
|
||||
var permissions = command.permissions();
|
||||
for (var permission : permissions) {
|
||||
pluginManager.addPermission(permission);
|
||||
logger.trace("Command '{}' permission '{}' registered.", commandClassName, permission.getName());
|
||||
}
|
||||
|
||||
command.command().register(this);
|
||||
logger.trace("Command '{}' registered.", commandClassName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package io.github.axolotsh.pluginutils;
|
||||
|
||||
import io.github.axolotsh.localizationlib.abstraction.ILocalizationService;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
||||
public class ComponentUtils {
|
||||
private static final MiniMessage mm = MiniMessage.miniMessage();
|
||||
|
||||
public static Component component(ILocalizationService service, String key) {
|
||||
return mm.deserialize(service.translate(key));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package io.github.axolotsh.pluginutils;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
public abstract class JavaPluginModule extends PluginModule {
|
||||
protected final JavaPlugin javaPlugin;
|
||||
|
||||
protected JavaPluginModule(JavaPlugin javaPlugin) {
|
||||
this.javaPlugin = javaPlugin;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected JavaPlugin provideJavaPlugin() {
|
||||
return javaPlugin;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Server provideServer(JavaPlugin plugin) {
|
||||
return plugin.getServer();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected PluginManager providePluginManager(Server server) {
|
||||
return server.getPluginManager();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected BukkitScheduler provideScheduler(Server server) {
|
||||
return server.getScheduler();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected FileConfiguration provideFileConfiguration(JavaPlugin plugin) {
|
||||
return plugin.getConfig();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Logger provideLogger(JavaPlugin plugin) {
|
||||
return plugin.getSLF4JLogger();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package io.github.axolotsh.pluginutils;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public abstract class PluginConfiguration {
|
||||
protected final JavaPlugin plugin;
|
||||
protected final FileConfiguration configuration;
|
||||
|
||||
protected PluginConfiguration(JavaPlugin plugin, FileConfiguration configuration) {
|
||||
this.plugin = plugin;
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
protected String get(String key, String fallback) {
|
||||
return getString(key, fallback);
|
||||
}
|
||||
|
||||
protected String getString(String key, String fallback) {
|
||||
if (configuration.contains(key))
|
||||
return configuration.getString(key);
|
||||
return fallback;
|
||||
}
|
||||
|
||||
protected int get(String key, int fallback) {
|
||||
return getInt(key, fallback);
|
||||
}
|
||||
|
||||
protected int getInt(String key, int fallback) {
|
||||
if (configuration.contains(key))
|
||||
return configuration.getInt(key);
|
||||
return fallback;
|
||||
}
|
||||
|
||||
protected boolean get(String key, boolean fallback) {
|
||||
return getBoolean(key, fallback);
|
||||
}
|
||||
|
||||
protected boolean getBoolean(String key, boolean fallback) {
|
||||
if (configuration.contains(key))
|
||||
return configuration.getBoolean(key);
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package io.github.axolotsh.pluginutils;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.multibindings.Multibinder;
|
||||
|
||||
import io.github.axolotsh.pluginutils.entities.ICommand;
|
||||
|
||||
public abstract class PluginModule extends AbstractModule {
|
||||
protected Multibinder<Listener> createListenersMultibinder() {
|
||||
return Multibinder.newSetBinder(binder(), Listener.class);
|
||||
}
|
||||
|
||||
protected Multibinder<ICommand> createCommandsMultibinder() {
|
||||
return Multibinder.newSetBinder(binder(), ICommand.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package io.github.axolotsh.pluginutils;
|
||||
|
||||
public class PluginUtils {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package io.github.axolotsh.pluginutils.entities;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.bukkit.permissions.Permission;
|
||||
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
|
||||
public interface ICommand {
|
||||
public Collection<Permission> permissions();
|
||||
|
||||
public CommandAPICommand command();
|
||||
}
|
||||
Reference in New Issue
Block a user