1
0
Fork 0
mirror of https://github.com/xHyroM/lighteco.git synced 2024-11-21 14:31:09 +01:00

feat: sponge support [WIP]

This commit is contained in:
Jozef Steinhübl 2023-08-30 16:03:38 +02:00
parent 2163f1614e
commit 22df335df9
13 changed files with 214 additions and 38 deletions

View file

@ -12,6 +12,7 @@ public interface Platform {
enum Type { enum Type {
BUKKIT("Bukkit"), BUKKIT("Bukkit"),
SPONGE("Sponge"),
VELOCITY("Velocity"), VELOCITY("Velocity"),
BUNGEECORD("BungeeCord"); BUNGEECORD("BungeeCord");
@ -26,7 +27,7 @@ public interface Platform {
} }
public boolean isLocal() { public boolean isLocal() {
return this == BUKKIT; return this == BUKKIT || this == SPONGE;
} }
public boolean isProxy() { public boolean isProxy() {

View file

@ -35,9 +35,6 @@ tasks.shadowJar {
relocate("eu.okaeri.configs", "dev.xhyrom.lighteco.libraries.okaeri.configs") relocate("eu.okaeri.configs", "dev.xhyrom.lighteco.libraries.okaeri.configs")
relocate("eu.okaeri.validator", "dev.xhyrom.lighteco.libraries.okaeri.validator") relocate("eu.okaeri.validator", "dev.xhyrom.lighteco.libraries.okaeri.validator")
//relocate("net.kyori.adventure", "dev.xhyrom.lighteco.libraries.net.kyori.adventure")
//relocate("net.kyori.examination", "dev.xhyrom.lighteco.libraries.net.kyori.examination")
relocate("org.yaml.snakeyaml", "dev.xhyrom.lighteco.libraries.org.yaml.snakeyaml") relocate("org.yaml.snakeyaml", "dev.xhyrom.lighteco.libraries.org.yaml.snakeyaml")
relocate("org.mariadb.jdbc", "dev.xhyrom.lighteco.libraries.mariadb") relocate("org.mariadb.jdbc", "dev.xhyrom.lighteco.libraries.mariadb")

View file

@ -1,12 +1,13 @@
package dev.xhyrom.lighteco.bukkit; package dev.xhyrom.lighteco.bukkit;
import dev.jorel.commandapi.CommandAPI;
import dev.jorel.commandapi.CommandAPIBukkitConfig;
import dev.xhyrom.lighteco.bukkit.logger.BukkitLogger; import dev.xhyrom.lighteco.bukkit.logger.BukkitLogger;
import dev.xhyrom.lighteco.common.plugin.bootstrap.LightEcoBootstrap; import dev.xhyrom.lighteco.common.plugin.bootstrap.LightEcoBootstrap;
import dev.xhyrom.lighteco.common.plugin.bootstrap.LoaderBootstrap; import dev.xhyrom.lighteco.common.plugin.bootstrap.LoaderBootstrap;
import dev.xhyrom.lighteco.common.plugin.logger.PluginLogger; import dev.xhyrom.lighteco.common.plugin.logger.PluginLogger;
import dev.xhyrom.lighteco.common.plugin.scheduler.SchedulerAdapter; import dev.xhyrom.lighteco.common.plugin.scheduler.SchedulerAdapter;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Server;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -17,10 +18,10 @@ import java.util.UUID;
@Getter @Getter
public class BukkitLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstrap { public class BukkitLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstrap {
private final JavaPlugin loader;
@Getter
private final BukkitLightEcoPlugin plugin = new BukkitLightEcoPlugin(this); private final BukkitLightEcoPlugin plugin = new BukkitLightEcoPlugin(this);
@Getter
private final JavaPlugin loader;
@Getter @Getter
private final PluginLogger logger; private final PluginLogger logger;
@Getter @Getter
@ -28,7 +29,6 @@ public class BukkitLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr
public BukkitLightEcoBootstrap(JavaPlugin loader) { public BukkitLightEcoBootstrap(JavaPlugin loader) {
this.loader = loader; this.loader = loader;
this.logger = new BukkitLogger(loader.getLogger()); this.logger = new BukkitLogger(loader.getLogger());
this.scheduler = new BukkitSchedulerAdapter(this); this.scheduler = new BukkitSchedulerAdapter(this);
} }
@ -36,22 +36,23 @@ public class BukkitLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr
@Override @Override
public void onLoad() { public void onLoad() {
this.plugin.load(); this.plugin.load();
CommandAPI.onLoad(new CommandAPIBukkitConfig(this.loader)
.verboseOutput(this.getPlugin().getConfig().debug)
);
} }
@Override @Override
public void onEnable() { public void onEnable() {
CommandAPI.onEnable();
this.plugin.enable(); this.plugin.enable();
} }
@Override @Override
public void onDisable() { public void onDisable() {
CommandAPI.onDisable();
this.plugin.disable(); this.plugin.disable();
} }
public Server getServer() {
return this.loader.getServer();
}
@Override @Override
public Path getDataDirectory() { public Path getDataDirectory() {
return this.loader.getDataFolder().toPath(); return this.loader.getDataFolder().toPath();
@ -59,7 +60,7 @@ public class BukkitLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr
@Override @Override
public List<UUID> getOnlinePlayers() { public List<UUID> getOnlinePlayers() {
return getServer().getOnlinePlayers().stream() return this.loader.getServer().getOnlinePlayers().stream()
.map(Entity::getUniqueId) .map(Entity::getUniqueId)
.toList(); .toList();
} }

View file

@ -2,8 +2,6 @@ package dev.xhyrom.lighteco.bukkit;
import dev.jorel.commandapi.CommandAPI; import dev.jorel.commandapi.CommandAPI;
import dev.jorel.commandapi.CommandAPIBukkitConfig; import dev.jorel.commandapi.CommandAPIBukkitConfig;
import dev.xhyrom.lighteco.bukkit.hooks.PlaceholderAPIExpansion;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
// Used inside plugin.yml // Used inside plugin.yml

View file

@ -34,7 +34,7 @@ public class BukkitLightEcoPlugin extends AbstractLightEcoPlugin {
@Override @Override
protected void registerListeners() { protected void registerListeners() {
this.bootstrap.getServer().getPluginManager().registerEvents(new BukkitConnectionListener(this), this.bootstrap.getLoader()); this.bootstrap.getLoader().getServer().getPluginManager().registerEvents(new BukkitConnectionListener(this), this.bootstrap.getLoader());
} }
@Override @Override
@ -47,7 +47,7 @@ public class BukkitLightEcoPlugin extends AbstractLightEcoPlugin {
@Override @Override
protected void registerApiOnPlatform(LightEco api) { protected void registerApiOnPlatform(LightEco api) {
this.getBootstrap().getServer().getServicesManager().register(LightEco.class, api, this.getBootstrap().getLoader(), ServicePriority.Normal); this.getBootstrap().getLoader().getServer().getServicesManager().register(LightEco.class, api, this.getBootstrap().getLoader(), ServicePriority.Normal);
} }
@Override @Override

View file

@ -17,7 +17,7 @@ public class BukkitSchedulerAdapter implements SchedulerAdapter {
public BukkitSchedulerAdapter(BukkitLightEcoBootstrap bootstrap) { public BukkitSchedulerAdapter(BukkitLightEcoBootstrap bootstrap) {
this.bootstrap = bootstrap; this.bootstrap = bootstrap;
this.scheduler = bootstrap.getServer().getScheduler(); this.scheduler = bootstrap.getLoader().getServer().getScheduler();
this.async = runnable -> this.scheduler.runTaskAsynchronously(this.bootstrap.getLoader(), runnable); this.async = runnable -> this.scheduler.runTaskAsynchronously(this.bootstrap.getLoader(), runnable);
} }

View file

@ -6,7 +6,6 @@ import dev.xhyrom.lighteco.common.api.LightEcoApi;
import dev.xhyrom.lighteco.common.config.Config; import dev.xhyrom.lighteco.common.config.Config;
import dev.xhyrom.lighteco.common.dependencies.DependencyManager; import dev.xhyrom.lighteco.common.dependencies.DependencyManager;
import dev.xhyrom.lighteco.common.dependencies.DependencyManagerImpl; import dev.xhyrom.lighteco.common.dependencies.DependencyManagerImpl;
import dev.xhyrom.lighteco.common.model.user.User;
import dev.xhyrom.lighteco.common.storage.Storage; import dev.xhyrom.lighteco.common.storage.Storage;
import dev.xhyrom.lighteco.common.storage.StorageFactory; import dev.xhyrom.lighteco.common.storage.StorageFactory;
import dev.xhyrom.lighteco.common.task.UserSaveTask; import dev.xhyrom.lighteco.common.task.UserSaveTask;

42
sponge-8/.gitignore vendored Normal file
View file

@ -0,0 +1,42 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

View file

@ -1,19 +1,32 @@
plugins { plugins {
id("java") id("lighteco.platform-logic")
}
group = "dev.xhyrom"
version = "0.1.0"
repositories {
mavenCentral()
} }
dependencies { dependencies {
testImplementation(platform("org.junit:junit-bom:5.9.1")) implementation(project(":lighteco-common"))
testImplementation("org.junit.jupiter:junit-jupiter")
compileOnly("org.spongepowered:spongeapi:8.0.0")
//implementation("dev.jorel:commandapi-sponge-shade:9.1.0")
compileOnly("org.projectlombok:lombok:1.18.28")
annotationProcessor("org.projectlombok:lombok:1.18.28")
compileOnly("org.checkerframework:checker-qual:3.8.0")
compileOnly("org.jetbrains:annotations:20.1.0")
} }
tasks.test { tasks.shadowJar {
useJUnitPlatform() relocate("dev.jorel.commandapi", "dev.xhyrom.lighteco.libraries.commandapi")
// common
relocate("eu.okaeri.configs", "dev.xhyrom.lighteco.libraries.okaeri.configs")
relocate("eu.okaeri.validator", "dev.xhyrom.lighteco.libraries.okaeri.validator")
relocate("org.yaml.snakeyaml", "dev.xhyrom.lighteco.libraries.org.yaml.snakeyaml")
relocate("org.mariadb.jdbc", "dev.xhyrom.lighteco.libraries.mariadb")
relocate("com.mysql", "dev.xhyrom.lighteco.libraries.mysql")
relocate("org.postgresql", "dev.xhyrom.lighteco.libraries.postgresql")
relocate("com.zaxxer.hikari", "dev.xhyrom.lighteco.libraries.hikari")
} }

View file

@ -1,7 +0,0 @@
package dev.xhyrom;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}

View file

@ -0,0 +1,33 @@
package dev.xhyrom.lighteco.sponge;
import com.google.inject.Inject;
import dev.xhyrom.lighteco.common.plugin.bootstrap.LoaderBootstrap;
import org.apache.logging.log4j.Logger;
import org.spongepowered.plugin.builtin.jvm.Plugin;
@Plugin("lighteco-sponge")
public class SpongeLightEcoBootstrap implements LoaderBootstrap {
private final SpongeLightEcoPlugin plugin;
@Inject
private Logger logger;
public SpongeLightEcoBootstrap() {
this.plugin = new SpongeLightEcoPlugin(this);
}
@Override
public void onLoad() {
this.plugin.load();
}
@Override
public void onEnable() {
this.plugin.enable();
}
@Override
public void onDisable() {
this.plugin.disable();
}
}

View file

@ -0,0 +1,63 @@
package dev.xhyrom.lighteco.sponge;
import dev.xhyrom.lighteco.api.LightEco;
import dev.xhyrom.lighteco.api.manager.CommandManager;
import dev.xhyrom.lighteco.api.manager.ContextManager;
import dev.xhyrom.lighteco.api.platform.Platform;
import dev.xhyrom.lighteco.common.manager.currency.StandardCurrencyManager;
import dev.xhyrom.lighteco.common.manager.user.StandardUserManager;
import dev.xhyrom.lighteco.common.plugin.AbstractLightEcoPlugin;
import lombok.Getter;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.spongepowered.api.entity.living.player.Player;
public class SpongeLightEcoPlugin extends AbstractLightEcoPlugin {
@Getter
private final SpongeLightEcoBootstrap bootstrap;
@Getter
private StandardUserManager userManager;
@Getter
private StandardCurrencyManager currencyManager;
@Getter
private CommandManager commandManager;
@Getter
private ContextManager<Player> contextManager;
public SpongeLightEcoPlugin(SpongeLightEcoBootstrap bootstrap) {
this.bootstrap = bootstrap;
}
@Override
protected void registerListeners() {
//this.bootstrap.getServer().getPluginManager().registerEvents(new BukkitConnectionListener(this), this.bootstrap);
}
@Override
public void setupManagers() {
this.userManager = new StandardUserManager(this);
this.currencyManager = new StandardCurrencyManager(this);
//this.commandManager = new BukkitCommandManager(this);
//this.contextManager = new BukkitContextManager();
}
@Override
protected void registerApiOnPlatform(LightEco api) {
//this.getBootstrap().getServer().getServicesManager().register(LightEco.class, api, this.getBootstrap(), ServicePriority.Normal);
}
@Override
protected void registerPlatformHooks() {
}
@Override
protected void removePlatformHooks() {
}
@Override
public Platform.@NonNull Type getPlatformType() {
return Platform.Type.SPONGE;
}
}

View file

@ -0,0 +1,36 @@
{
"loader": {
"name": "java_plain",
"version": "1.0.0"
},
"license": "Apache-2.0",
"plugins": [
{
"id": "lighteco-sponge",
"name": "LightEco Sponge",
"description": "${description}",
"version": "${version}",
"entrypoint": "dev.xhyrom.lighteco.sponge.SpongeLightEcoBootstrap",
"links": {
"homepage": "https://modrinth.com/plugin/lighteco",
"source": "https://github.com/xHyroM/lighteco",
"issues": "https://github.com/xHyroM/lighteco/issues"
},
"contributors": [
{
"name": "xHyroM",
"description": "Developer",
"links": {
"homepage": "https://xhyrom.dev"
}
}
],
"dependencies": [
{
"id": "spongeapi",
"version": "8.0.0"
}
]
}
]
}