Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-884 Fix sound serdes #884

Merged
merged 17 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/HOW_USE_DI.md → .github/HOW_USE_TO_DI.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public class UserCommand {
#### 7. Subscriber
```java
@Controller // <- marks a class that will be registered as an event subscriber.
public class UserSubscriber implements Subscriber {
public class UserSubscriber {

private final UserService exampleService;

Expand All @@ -126,12 +126,12 @@ public class UserSubscriber implements Subscriber {
}
```

#### 8. BeanSetup
BeanSetup is a class that allows you to register beans in the bean container.
#### 8. Setup
Setup is an annotation that allows you to register beans in the bean container.
It is used to register dependencies that are cannot be registered in the bean container using annotations. e.g. MiniMessage, AdventureProvider, HikariDataSource, etc.
```java

@BeanSetup // <- marks a class that will be registered as a bean holder.
@Setup // <- marks a class that will be registered as a bean holder.
public class UserBeanSetup {

@Bean // <- marks a method that will be registered as a bean. (dependency)
Expand Down
9 changes: 4 additions & 5 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
object Versions {

const val SPIGOT_API = "1.19.4-R0.1-SNAPSHOT"
const val PAPER_API = "1.19.4-R0.1-SNAPSHOT"
const val SPIGOT_API = "1.21.3-R0.1-SNAPSHOT"
const val PAPER_API = "1.21.3-R0.1-SNAPSHOT"

const val ETERNALCODE_COMMONS = "1.1.5"
const val MULTIFICATION = "1.1.4"
const val MULTIFICATION = "1.2.1"

const val JETBRAINS_ANNOTATIONS = "26.0.1"
const val PLACEHOLDER_API = "2.11.6"
Expand All @@ -23,7 +23,7 @@ object Versions {
const val ORMLITE = "6.1"
const val HIKARI_CP = "6.0.0"

const val LITE_COMMANDS = "3.8.0"
const val LITE_COMMANDS = "3.9.7"
Rollczi marked this conversation as resolved.
Show resolved Hide resolved
const val LITE_SKULL_API = "1.3.0"

const val GUAVA = "33.3.1-jre"
Expand All @@ -36,7 +36,6 @@ object Versions {
const val TRIUMPH_GUI = "3.1.10"

const val BSTATS = "3.1.0"
const val PIXEL_WIDTH = "1.1.0"

const val CAFFEINE = "3.1.8"

Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/eternalcode-java.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ java {
tasks.withType<JavaCompile>() {
options.compilerArgs = listOf("-Xlint:deprecation", "-parameters")
options.encoding = "UTF-8"
options.release = 17
options.release = 21
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void onHomeTeleport(HomeTeleportEvent event) {

player.sendMessage("Teleporting to home...");

if (player.hasPotionEffect(PotionEffectType.SLOW)) {
if (player.hasPotionEffect(PotionEffectType.SLOWNESS)) {
player.sendMessage("You are slowed down!");
player.teleport(player.getWorld().getSpawnLocation());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ public class Delay<T> {

private final Supplier<Duration> delaySettings;

@Deprecated
public Delay(DelaySettings delaySettings) {
this((Supplier<Duration>) () -> delaySettings.delay());
}

public Delay(Supplier<Duration> delayProvider) {
this.delaySettings = delayProvider;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
package com.eternalcode.core;

import com.eternalcode.core.configuration.ReloadableConfig;
import com.eternalcode.core.compatibility.CompatibilityService;
import com.eternalcode.core.injector.DependencyInjector;
import com.eternalcode.core.injector.annotations.component.Component;
import com.eternalcode.core.injector.annotations.component.ConfigurationFile;
import com.eternalcode.core.injector.annotations.component.Controller;
import com.eternalcode.core.injector.annotations.component.Repository;
import com.eternalcode.core.injector.annotations.component.Service;
import com.eternalcode.core.injector.annotations.component.Setup;
import com.eternalcode.core.injector.annotations.component.Task;
import com.eternalcode.core.injector.annotations.lite.LiteArgument;
import com.eternalcode.core.injector.annotations.lite.LiteCommandEditor;
import com.eternalcode.core.injector.annotations.lite.LiteContextual;
import com.eternalcode.core.injector.annotations.lite.LiteHandler;
import com.eternalcode.core.injector.bean.BeanCandidate;
import com.eternalcode.core.injector.bean.BeanFactory;
import com.eternalcode.core.injector.bean.BeanHolder;
import com.eternalcode.core.injector.bean.LazyFieldBeanCandidate;
import com.eternalcode.core.injector.bean.BeanCandidatePriorityProvider;
import com.eternalcode.core.injector.bean.processor.BeanProcessor;
import com.eternalcode.core.injector.bean.processor.BeanProcessorFactory;
import com.eternalcode.core.injector.scan.DependencyScanner;
import com.eternalcode.core.injector.scan.DependencyScannerFactory;
import com.eternalcode.core.publish.Publisher;
import com.eternalcode.core.publish.event.EternalInitializeEvent;
import com.eternalcode.core.publish.event.EternalShutdownEvent;
import net.dzikoysk.cdn.entity.Contextual;
import dev.rollczi.litecommands.annotations.command.Command;
import dev.rollczi.litecommands.annotations.command.RootCommand;
import org.bukkit.Server;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;

import java.io.File;
import java.lang.reflect.Field;
import java.util.List;
import java.util.logging.Logger;

class EternalCore {
Expand All @@ -32,6 +40,7 @@ class EternalCore {
public EternalCore(Plugin plugin) {
this.eternalCoreEnvironment = new EternalCoreEnvironment(plugin.getLogger());

CompatibilityService compatibilityService = new CompatibilityService();
BeanProcessor beanProcessor = BeanProcessorFactory.defaultProcessors(plugin);
BeanFactory beanFactory = new BeanFactory(beanProcessor)
.withCandidateSelf()
Expand All @@ -40,19 +49,35 @@ public EternalCore(Plugin plugin) {
.addCandidate(Logger.class, () -> plugin.getLogger())
.addCandidate(PluginDescriptionFile.class, () -> plugin.getDescription())
.addCandidate(File.class, () -> plugin.getDataFolder())
.addCandidate(PluginManager.class, () -> plugin.getServer().getPluginManager());

DependencyInjector dependencyInjector = new DependencyInjector(beanFactory);
DependencyScanner scanner = DependencyScannerFactory.createDefault(dependencyInjector);

beanFactory.addCandidate(DependencyInjector.class, () -> dependencyInjector);
.addCandidate(PluginManager.class, () -> plugin.getServer().getPluginManager())
.priorityProvider(new BeanCandidatePriorityProvider());

DependencyInjector injector = new DependencyInjector(beanFactory);
DependencyScanner scanner = new DependencyScanner(injector)
.includeType(type -> compatibilityService.isCompatible(type))
.includeAnnotations(
Component.class,
Service.class,
Repository.class,
Task.class,
Controller.class,
ConfigurationFile.class,
Setup.class,

Command.class,
RootCommand.class,
LiteArgument.class,
LiteHandler.class,
LiteContextual.class,
LiteCommandEditor.class
);

beanFactory.addCandidate(DependencyInjector.class, () -> injector);

for (BeanCandidate beanCandidate : scanner.scan(EternalCore.class.getPackage())) {
beanFactory.addCandidate(beanCandidate);
}

this.loadConfigContextual(beanFactory);

beanFactory.initializeCandidates();

this.publisher = beanFactory.getDependency(Publisher.class);
Expand All @@ -67,22 +92,4 @@ public void disable() {
EternalCoreApiProvider.deinitialize();
}

private void loadConfigContextual(BeanFactory beanFactory) {
List<BeanHolder<ReloadableConfig>> beans = beanFactory
.initializeCandidates(ReloadableConfig.class)
.getBeans(ReloadableConfig.class);

for (BeanHolder<ReloadableConfig> bean : beans) {
ReloadableConfig config = bean.get();

for (Field field : config.getClass().getDeclaredFields()) {
if (!field.getType().isAnnotationPresent(Contextual.class)) {
continue;
}

beanFactory.addCandidate(new LazyFieldBeanCandidate(config, field));
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.eternalcode.core.bridge;

import com.eternalcode.core.injector.annotations.Bean;
import com.eternalcode.core.injector.annotations.component.BeanSetup;
import com.eternalcode.core.injector.annotations.component.Setup;
import com.eternalcode.core.placeholder.PlaceholderRegistry;
import java.util.logging.Logger;
import org.bukkit.Server;
import org.bukkit.plugin.PluginDescriptionFile;

@BeanSetup
@Setup
class BridgeManagerInitializer {

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import com.eternalcode.commons.adventure.AdventureLegacyColorPreProcessor;
import com.eternalcode.commons.adventure.AdventureUrlPostProcessor;
import com.eternalcode.core.injector.annotations.Bean;
import com.eternalcode.core.injector.annotations.component.BeanSetup;
import com.eternalcode.core.injector.annotations.component.Setup;
import net.kyori.adventure.platform.AudienceProvider;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.plugin.Plugin;

@BeanSetup
@Setup
class AdventureSetup {

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.eternalcode.core.bridge.litecommand;

import com.eternalcode.core.injector.annotations.Bean;
import com.eternalcode.core.injector.annotations.component.BeanSetup;
import com.eternalcode.core.injector.annotations.component.Setup;
import com.eternalcode.core.injector.bean.BeanFactory;
import com.eternalcode.core.notice.NoticeService;
import com.eternalcode.core.publish.Subscribe;
import com.eternalcode.core.publish.Subscriber;
import com.eternalcode.core.publish.event.EternalInitializeEvent;
import com.eternalcode.core.publish.event.EternalShutdownEvent;
import dev.rollczi.litecommands.LiteCommands;
Expand All @@ -20,8 +19,8 @@
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;

@BeanSetup
class LiteCommandsSetup implements Subscriber {
@Setup
class LiteCommandsSetup {

@Bean
public LiteCommandsBuilder<CommandSender, ?, ?> liteCommandsBuilder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.eternalcode.core.configuration.ReloadableConfig;
import com.eternalcode.core.feature.essentials.gamemode.GameModeArgumentSettings;
import com.eternalcode.core.injector.annotations.Bean;
import com.eternalcode.core.injector.annotations.component.ConfigurationFile;
import net.dzikoysk.cdn.entity.Contextual;
import net.dzikoysk.cdn.entity.Description;
Expand All @@ -19,6 +20,7 @@
@ConfigurationFile
public class CommandConfiguration implements ReloadableConfig {

@Bean
public Argument argument = new Argument();
vLuckyyy marked this conversation as resolved.
Show resolved Hide resolved

@Contextual
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.eternalcode.core.bridge.metrics;

import com.eternalcode.core.injector.annotations.component.Controller;
import com.eternalcode.core.publish.Subscriber;
import com.eternalcode.core.publish.event.EternalInitializeEvent;
import com.eternalcode.core.publish.Subscribe;
import org.bstats.bukkit.Metrics;
import org.bukkit.plugin.java.JavaPlugin;

@Controller
class BStatsMetricsSetup implements Subscriber {
class BStatsMetricsSetup {

@Subscribe(EternalInitializeEvent.class)
public void onInitialize(JavaPlugin javaPlugin) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.eternalcode.core.bridge.skullapi;

import com.eternalcode.core.publish.Subscriber;
import com.eternalcode.core.publish.event.EternalShutdownEvent;
import com.eternalcode.core.injector.annotations.Bean;
import com.eternalcode.core.injector.annotations.component.BeanSetup;
import com.eternalcode.core.injector.annotations.component.Setup;
import com.eternalcode.core.publish.Subscribe;
import dev.rollczi.liteskullapi.LiteSkullFactory;
import dev.rollczi.liteskullapi.SkullAPI;
import org.bukkit.plugin.Plugin;

@BeanSetup
class SkullAPISetup implements Subscriber {
@Setup
class SkullAPISetup {

@Bean
public SkullAPI skullAPI(Plugin plugin) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.eternalcode.core.compatibility;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Compatibility {

Version from() default @Version(minor = Integer.MIN_VALUE, patch = Integer.MIN_VALUE);

Version to() default @Version(minor = Integer.MAX_VALUE, patch = Integer.MAX_VALUE);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.eternalcode.core.compatibility;

import io.papermc.lib.PaperLib;

public class CompatibilityService {

public boolean isCompatible(Class<?> type) {
Compatibility compatibility = type.getAnnotation(Compatibility.class);
if (compatibility == null) {
return true;
}

Version from = compatibility.from();
Version to = compatibility.to();

int minor = PaperLib.getMinecraftVersion();
int patch = PaperLib.getMinecraftPatchVersion();

return isCompatibleFrom(from, minor, patch) && isCompatibleTo(to, minor, patch);
}
vLuckyyy marked this conversation as resolved.
Show resolved Hide resolved

private boolean isCompatibleTo(Version to, int minor, int patch) {
return minor < to.minor() || minor == to.minor() && patch <= to.patch();
}

private boolean isCompatibleFrom(Version from, int minor, int patch) {
return minor > from.minor() || minor == from.minor() && patch >= from.patch();
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.eternalcode.core.compatibility;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Version {

int minor();
int patch();

}
Loading
Loading