diff --git a/api/.gitignore b/api/.gitignore new file mode 100644 index 0000000..b63da45 --- /dev/null +++ b/api/.gitignore @@ -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 \ No newline at end of file diff --git a/api/build.gradle.kts b/api/build.gradle.kts new file mode 100644 index 0000000..5c0dfcb --- /dev/null +++ b/api/build.gradle.kts @@ -0,0 +1,11 @@ +plugins { + id("lighteco.shadow-logic") +} + +dependencies { + 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") +} \ No newline at end of file diff --git a/api/src/main/java/dev/xhyrom/lighteco/api/LightEco.java b/api/src/main/java/dev/xhyrom/lighteco/api/LightEco.java new file mode 100644 index 0000000..b0b4172 --- /dev/null +++ b/api/src/main/java/dev/xhyrom/lighteco/api/LightEco.java @@ -0,0 +1,20 @@ +package dev.xhyrom.lighteco.api; + +import dev.xhyrom.lighteco.api.managers.UserManager; +import dev.xhyrom.lighteco.api.platform.Platform; +import dev.xhyrom.lighteco.api.platform.PlayerAdapter; +import org.checkerframework.checker.nullness.qual.NonNull; + +public interface LightEco { + /** + * Gets the {@link Platform}, which represents the current platform the + * plugin is running on. + * + * @return the platform + */ + @NonNull Platform getPlatform(); + + @NonNull UserManager getUserManager(); + + @NonNull PlayerAdapter getPlayerAdapter(@NonNull Class playerClass); +} diff --git a/api/src/main/java/dev/xhyrom/lighteco/api/LightEcoProvider.java b/api/src/main/java/dev/xhyrom/lighteco/api/LightEcoProvider.java new file mode 100644 index 0000000..c5bdfee --- /dev/null +++ b/api/src/main/java/dev/xhyrom/lighteco/api/LightEcoProvider.java @@ -0,0 +1,35 @@ +package dev.xhyrom.lighteco.api; + +import lombok.experimental.UtilityClass; +import org.checkerframework.checker.nullness.qual.NonNull; + +import static org.jetbrains.annotations.ApiStatus.Internal; + +@UtilityClass +public final class LightEcoProvider { + private static LightEco instance; + + public static @NonNull LightEco get() { + LightEco instance = LightEcoProvider.instance; + if (instance == null) { + throw new NotLoadedException(); + }; + + return instance; + } + + @Internal + public static void set(LightEco instance) { + if (LightEcoProvider.instance != null) { + throw new IllegalStateException("LightEco is already loaded!"); + }; + + LightEcoProvider.instance = instance; + } + + private static final class NotLoadedException extends IllegalStateException { + private NotLoadedException() { + super("LightEco is not loaded yet!"); + } + } +} diff --git a/api/src/main/java/dev/xhyrom/lighteco/api/managers/ContextManager.java b/api/src/main/java/dev/xhyrom/lighteco/api/managers/ContextManager.java new file mode 100644 index 0000000..bb7ebf6 --- /dev/null +++ b/api/src/main/java/dev/xhyrom/lighteco/api/managers/ContextManager.java @@ -0,0 +1,10 @@ +package dev.xhyrom.lighteco.api.managers; + +import org.checkerframework.checker.nullness.qual.NonNull; + +import java.util.UUID; + +public interface ContextManager { + @NonNull UUID getPlayerUniqueId(@NonNull T context); + @NonNull Class getPlayerClass(); +} diff --git a/api/src/main/java/dev/xhyrom/lighteco/api/managers/UserManager.java b/api/src/main/java/dev/xhyrom/lighteco/api/managers/UserManager.java new file mode 100644 index 0000000..a941e92 --- /dev/null +++ b/api/src/main/java/dev/xhyrom/lighteco/api/managers/UserManager.java @@ -0,0 +1,18 @@ +package dev.xhyrom.lighteco.api.managers; + +import dev.xhyrom.lighteco.api.model.user.User; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; + +import java.util.UUID; +import java.util.concurrent.CompletableFuture; + +public interface UserManager { + @NonNull CompletableFuture loadUser(@NonNull UUID uniqueId); + + @NonNull CompletableFuture saveUser(@NonNull User user); + + @Nullable User getUser(@NonNull UUID uniqueId); + + boolean isLoaded(@NonNull UUID uniqueId); +} diff --git a/api/src/main/java/dev/xhyrom/lighteco/api/model/user/User.java b/api/src/main/java/dev/xhyrom/lighteco/api/model/user/User.java new file mode 100644 index 0000000..97ae61c --- /dev/null +++ b/api/src/main/java/dev/xhyrom/lighteco/api/model/user/User.java @@ -0,0 +1,21 @@ +package dev.xhyrom.lighteco.api.model.user; + +import org.checkerframework.checker.nullness.qual.NonNull; + +import java.util.UUID; + +public interface User { + /** + * Get the unique id of this user. + * + * @return the unique id + */ + @NonNull UUID getUniqueId(); + + /** + * Get the username of this user. + * + * @return the username + */ + @NonNull String getUsername(); +} diff --git a/api/src/main/java/dev/xhyrom/lighteco/api/platform/Platform.java b/api/src/main/java/dev/xhyrom/lighteco/api/platform/Platform.java new file mode 100644 index 0000000..6babce5 --- /dev/null +++ b/api/src/main/java/dev/xhyrom/lighteco/api/platform/Platform.java @@ -0,0 +1,23 @@ +package dev.xhyrom.lighteco.api.platform; + +import org.checkerframework.checker.nullness.qual.NonNull; + +public interface Platform { + @NonNull Type getType(); + + enum Type { + BUKKIT("Bukkit"), + VELOCITY("Velocity"), + BUNGEECORD("BungeeCord"); + + private final String displayName; + + Type(String displayName) { + this.displayName = displayName; + } + + public String getName() { + return displayName; + } + } +} diff --git a/api/src/main/java/dev/xhyrom/lighteco/api/platform/PlayerAdapter.java b/api/src/main/java/dev/xhyrom/lighteco/api/platform/PlayerAdapter.java new file mode 100644 index 0000000..bf3be6a --- /dev/null +++ b/api/src/main/java/dev/xhyrom/lighteco/api/platform/PlayerAdapter.java @@ -0,0 +1,10 @@ +package dev.xhyrom.lighteco.api.platform; + +import dev.xhyrom.lighteco.api.model.user.User; +import org.checkerframework.checker.nullness.qual.NonNull; + +import java.util.concurrent.CompletableFuture; + +public interface PlayerAdapter { + @NonNull CompletableFuture getUser(@NonNull T player); +} diff --git a/buildSrc/src/main/kotlin/lighteco.base-logic.gradle.kts b/buildSrc/src/main/kotlin/lighteco.base-logic.gradle.kts index 2d169f1..a799e87 100644 --- a/buildSrc/src/main/kotlin/lighteco.base-logic.gradle.kts +++ b/buildSrc/src/main/kotlin/lighteco.base-logic.gradle.kts @@ -4,7 +4,7 @@ plugins { } java { - toolchain.languageVersion.set(JavaLanguageVersion.of(17)) + // toolchain.languageVersion.set(JavaLanguageVersion.of(17)) withSourcesJar() } diff --git a/bukkit/build.gradle.kts b/bukkit/build.gradle.kts index bf9743a..395dec8 100644 --- a/bukkit/build.gradle.kts +++ b/bukkit/build.gradle.kts @@ -7,5 +7,13 @@ repositories { } dependencies { + implementation(project(":lighteco-common")) + compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") + + 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") } \ No newline at end of file diff --git a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/BukkitContextManager.java b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/BukkitContextManager.java new file mode 100644 index 0000000..bf63e0b --- /dev/null +++ b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/BukkitContextManager.java @@ -0,0 +1,19 @@ +package dev.xhyrom.lighteco.bukkit; + +import dev.xhyrom.lighteco.api.managers.ContextManager; +import org.bukkit.entity.Player; +import org.checkerframework.checker.nullness.qual.NonNull; + +import java.util.UUID; + +public class BukkitContextManager implements ContextManager { + @Override + public @NonNull UUID getPlayerUniqueId(@NonNull Player player) { + return player.getUniqueId(); + } + + @Override + public @NonNull Class getPlayerClass() { + return Player.class; + } +} diff --git a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/BukkitLightEcoPlugin.java b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/BukkitLightEcoPlugin.java index b4f364f..d1057de 100644 --- a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/BukkitLightEcoPlugin.java +++ b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/BukkitLightEcoPlugin.java @@ -1,4 +1,34 @@ package dev.xhyrom.lighteco.bukkit; -public class BukkitLightEcoPlugin extends JavaPlugin { +import dev.xhyrom.lighteco.api.managers.ContextManager; +import dev.xhyrom.lighteco.api.managers.UserManager; +import dev.xhyrom.lighteco.api.platform.Platform; +import dev.xhyrom.lighteco.common.LightEcoPlugin; +import dev.xhyrom.lighteco.common.managers.StandardUserManager; +import lombok.Getter; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.checkerframework.checker.nullness.qual.NonNull; + +public class BukkitLightEcoPlugin extends JavaPlugin implements LightEcoPlugin { + @Getter + private UserManager userManager; + @Getter + private ContextManager contextManager; + + @Override + public void onLoad() { + this.userManager = new StandardUserManager(this); + this.contextManager = new BukkitContextManager(); + } + + @Override + public void onEnable() { + getLogger().info("BukkitLightEco is enabled!"); + } + + @Override + public Platform.@NonNull Type getPlatformType() { + return Platform.Type.BUKKIT; + } } diff --git a/bukkit/src/main/resources/plugin.yml b/bukkit/src/main/resources/plugin.yml new file mode 100644 index 0000000..5cdd92e --- /dev/null +++ b/bukkit/src/main/resources/plugin.yml @@ -0,0 +1,9 @@ +name: ${name} +description: ${description} +version: ${version} +main: dev.xhyrom.lighteco.bukkit.BukkitLightEcoPlugin +author: ${author} +api-version: 1.20 + +softdepend: + - Vault \ No newline at end of file diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 0e30611..b3736fe 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -1,3 +1,13 @@ plugins { id("lighteco.shadow-logic") +} + +dependencies { + api(project(":lighteco-api")) + + 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") } \ No newline at end of file diff --git a/common/src/main/java/dev/xhyrom/Main.java b/common/src/main/java/dev/xhyrom/Main.java deleted file mode 100644 index aec9966..0000000 --- a/common/src/main/java/dev/xhyrom/Main.java +++ /dev/null @@ -1,7 +0,0 @@ -package dev.xhyrom; - -public class Main { - public static void main(String[] args) { - System.out.println("Hello world!"); - } -} \ No newline at end of file diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/LightEcoPlugin.java b/common/src/main/java/dev/xhyrom/lighteco/common/LightEcoPlugin.java new file mode 100644 index 0000000..d73d8d2 --- /dev/null +++ b/common/src/main/java/dev/xhyrom/lighteco/common/LightEcoPlugin.java @@ -0,0 +1,13 @@ +package dev.xhyrom.lighteco.common; + +import dev.xhyrom.lighteco.api.managers.ContextManager; +import dev.xhyrom.lighteco.api.managers.UserManager; +import dev.xhyrom.lighteco.api.platform.Platform; +import org.checkerframework.checker.nullness.qual.NonNull; + +public interface LightEcoPlugin { + Platform.@NonNull Type getPlatformType(); + + @NonNull UserManager getUserManager(); + @NonNull ContextManager getContextManager(); +} diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/api/LightEcoApi.java b/common/src/main/java/dev/xhyrom/lighteco/common/api/LightEcoApi.java new file mode 100644 index 0000000..8e850dc --- /dev/null +++ b/common/src/main/java/dev/xhyrom/lighteco/common/api/LightEcoApi.java @@ -0,0 +1,45 @@ +package dev.xhyrom.lighteco.common.api; + +import dev.xhyrom.lighteco.api.LightEco; +import dev.xhyrom.lighteco.api.managers.UserManager; +import dev.xhyrom.lighteco.api.platform.Platform; +import dev.xhyrom.lighteco.api.platform.PlayerAdapter; +import dev.xhyrom.lighteco.common.LightEcoPlugin; +import dev.xhyrom.lighteco.common.api.impl.ApiPlatform; +import dev.xhyrom.lighteco.common.api.impl.ApiPlayerAdapter; +import org.checkerframework.checker.nullness.qual.NonNull; + +public class LightEcoApi implements LightEco { + private final LightEcoPlugin plugin; + + private final Platform platform; + private final PlayerAdapter playerAdapter; + + public LightEcoApi(LightEcoPlugin plugin) { + this.plugin = plugin; + + this.platform = new ApiPlatform(plugin); + this.playerAdapter = new ApiPlayerAdapter<>(plugin.getUserManager(), plugin.getContextManager()); + } + + @Override + public @NonNull Platform getPlatform() { + return this.platform; + } + + @Override + public @NonNull UserManager getUserManager() { + return this.plugin.getUserManager(); + } + + @Override + public @NonNull PlayerAdapter getPlayerAdapter(@NonNull Class playerClass) { + Class expected = this.plugin.getContextManager().getPlayerClass(); + + if (!expected.equals(playerClass)) { + throw new IllegalArgumentException("Expected player class " + expected.getName() + ", got " + playerClass.getName()); + } + + return (PlayerAdapter) this.playerAdapter; + } +} diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/api/impl/ApiPlatform.java b/common/src/main/java/dev/xhyrom/lighteco/common/api/impl/ApiPlatform.java new file mode 100644 index 0000000..199e081 --- /dev/null +++ b/common/src/main/java/dev/xhyrom/lighteco/common/api/impl/ApiPlatform.java @@ -0,0 +1,18 @@ +package dev.xhyrom.lighteco.common.api.impl; + +import dev.xhyrom.lighteco.api.platform.Platform; +import dev.xhyrom.lighteco.common.LightEcoPlugin; +import org.checkerframework.checker.nullness.qual.NonNull; + +public class ApiPlatform implements Platform { + private final LightEcoPlugin plugin; + + public ApiPlatform(LightEcoPlugin plugin) { + this.plugin = plugin; + } + + @Override + public @NonNull Type getType() { + return this.plugin.getPlatformType(); + } +} diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/api/impl/ApiPlayerAdapter.java b/common/src/main/java/dev/xhyrom/lighteco/common/api/impl/ApiPlayerAdapter.java new file mode 100644 index 0000000..ad74806 --- /dev/null +++ b/common/src/main/java/dev/xhyrom/lighteco/common/api/impl/ApiPlayerAdapter.java @@ -0,0 +1,32 @@ +package dev.xhyrom.lighteco.common.api.impl; + +import dev.xhyrom.lighteco.api.managers.ContextManager; +import dev.xhyrom.lighteco.api.model.user.User; +import dev.xhyrom.lighteco.api.managers.UserManager; +import dev.xhyrom.lighteco.api.platform.PlayerAdapter; +import org.checkerframework.checker.nullness.qual.NonNull; + +import java.util.UUID; +import java.util.concurrent.CompletableFuture; + +public class ApiPlayerAdapter implements PlayerAdapter { + private final UserManager userManager; + private final ContextManager contextManager; + + public ApiPlayerAdapter(UserManager userManager, ContextManager contextManager) { + this.userManager = userManager; + this.contextManager = contextManager; + } + + @Override + public @NonNull CompletableFuture getUser(@NonNull T player) { + UUID uniqueId = contextManager.getPlayerUniqueId(player); + boolean loaded = userManager.isLoaded(uniqueId); + + if (loaded) { + return CompletableFuture.completedFuture(userManager.getUser(uniqueId)); + } + + return userManager.loadUser(uniqueId); + } +} diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/managers/StandardUserManager.java b/common/src/main/java/dev/xhyrom/lighteco/common/managers/StandardUserManager.java new file mode 100644 index 0000000..84f5e0c --- /dev/null +++ b/common/src/main/java/dev/xhyrom/lighteco/common/managers/StandardUserManager.java @@ -0,0 +1,41 @@ +package dev.xhyrom.lighteco.common.managers; + +import dev.xhyrom.lighteco.api.model.user.User; +import dev.xhyrom.lighteco.api.managers.UserManager; +import dev.xhyrom.lighteco.common.LightEcoPlugin; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; + +import java.util.UUID; +import java.util.concurrent.CompletableFuture; + +public class StandardUserManager implements UserManager { + private final LightEcoPlugin plugin; + + public StandardUserManager(LightEcoPlugin plugin) { + this.plugin = plugin; + } + + public User apply(UUID uniqueId) { + return new dev.xhyrom.lighteco.common.model.user.User(uniqueId); + } + @Override + public @NonNull CompletableFuture loadUser(@NonNull UUID uniqueId) { + return null; + } + + @Override + public @NonNull CompletableFuture saveUser(User user) { + return null; + } + + @Override + public @Nullable User getUser(@NonNull UUID uniqueId) { + return null; + } + + @Override + public boolean isLoaded(@NonNull UUID uniqueId) { + return false; + } +} diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/model/user/User.java b/common/src/main/java/dev/xhyrom/lighteco/common/model/user/User.java new file mode 100644 index 0000000..ab609dc --- /dev/null +++ b/common/src/main/java/dev/xhyrom/lighteco/common/model/user/User.java @@ -0,0 +1,20 @@ +package dev.xhyrom.lighteco.common.model.user; + +import lombok.Getter; +import org.checkerframework.checker.nullness.qual.NonNull; + +import java.util.UUID; + +public class User implements dev.xhyrom.lighteco.api.model.user.User { + @Getter + private final UUID uniqueId; + + public User(UUID uniqueId) { + this.uniqueId = uniqueId; + } + + @Override + public @NonNull String getUsername() { + return null; + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 8567d08..1ddc1bb 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,7 @@ rootProject.name = "lighteco-parent" sequenceOf( + "api", "common", "bukkit", "velocity"