Skip to content

Commit

Permalink
Refactor to use Geyser's version of Configurate
Browse files Browse the repository at this point in the history
  • Loading branch information
RealTriassic committed Oct 12, 2024
1 parent 08ffeed commit e95b11e
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 205 deletions.
26 changes: 16 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
java
alias(libs.plugins.shadow)
id("io.freefair.lombok") version "8.10.2"
id("com.gradleup.shadow") version "8.3.3"
}

repositories {
Expand All @@ -9,8 +10,14 @@ repositories {
}

dependencies {
compileOnly(libs.geyser.core)
implementation(libs.configurate.yaml)
implementation("org.spongepowered", "configurate-yaml", "4.2.0-GeyserMC-SNAPSHOT")

compileOnly("org.geysermc.geyser", "core", "2.4.3-SNAPSHOT")
compileOnly("org.projectlombok", "lombok", "1.18.34")
annotationProcessor("org.projectlombok", "lombok", "1.18.34")

testCompileOnly("org.projectlombok", "lombok", "1.18.34")
testAnnotationProcessor("org.projectlombok", "lombok", "1.18.34")
}

tasks {
Expand All @@ -24,19 +31,18 @@ tasks {
}

shadowJar {
archiveBaseName.set(rootProject.name)
archiveBaseName.set(project.name)
archiveClassifier.set(null as String?)

listOf(
"org.spongepowered",
).forEach {
relocate(it, "com.triassic.geyserdebuginfo.lib.$it")
}
relocate("org.spongepowered", "com.triassic.geyserdebuginfo.lib.org.spongepowered")
}

processResources {
filesMatching("extension.yml") {
expand("version" to project.version)
expand(
"name" to project.name,
"version" to project.version
)
}
}
}
Expand Down
11 changes: 0 additions & 11 deletions gradle/libs.versions.toml

This file was deleted.

55 changes: 14 additions & 41 deletions src/main/java/com/triassic/geyserdebuginfo/GeyserDebugInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.triassic.geyserdebuginfo.command.commands.ReloadCommand;
import com.triassic.geyserdebuginfo.command.commands.ToggleCommand;
import com.triassic.geyserdebuginfo.config.Configuration;
import com.triassic.geyserdebuginfo.config.ConfigurationContainer;
import com.triassic.geyserdebuginfo.configuration.ConfigurationLoader;
import com.triassic.geyserdebuginfo.configuration.Configuration;
import com.triassic.geyserdebuginfo.listener.PlayerJoinListener;
import com.triassic.geyserdebuginfo.manager.BossBarManager;
import com.triassic.geyserdebuginfo.manager.PlaceholderManager;
Expand All @@ -12,6 +12,7 @@
import com.triassic.geyserdebuginfo.placeholder.modifiers.TextModifierProvider;
import com.triassic.geyserdebuginfo.placeholder.placeholders.PlayerPlaceholderProvider;
import com.triassic.geyserdebuginfo.placeholder.placeholders.ServerPlaceholderProvider;
import lombok.Getter;
import org.geysermc.event.subscribe.Subscribe;
import org.geysermc.geyser.api.event.lifecycle.GeyserDefineCommandsEvent;
import org.geysermc.geyser.api.event.lifecycle.GeyserPreInitializeEvent;
Expand All @@ -24,10 +25,15 @@
public class GeyserDebugInfo implements Extension {

private File dataFolder;

@Getter
private Configuration config;
@Getter
private BossBarManager bossBarManager;
@Getter
private PlayerDataManager playerDataManager;
@Getter
private PlaceholderManager placeholderManager;
private ConfigurationContainer<Configuration> config;

/**
* Initializes the extension.
Expand All @@ -42,7 +48,9 @@ public void onPostInitialize(GeyserPreInitializeEvent event) {
if (!dataFolder.exists() && !dataFolder.mkdirs())
logger().error("Failed to create data folder " + dataFolder.getAbsolutePath());

loadConfig();
this.config = new ConfigurationLoader(this)
.load(Configuration.class);

this.playerDataManager = new PlayerDataManager(dataFolder, this.logger(), false);
this.placeholderManager = new PlaceholderManager();
this.bossBarManager = new BossBarManager(this);
Expand All @@ -66,11 +74,7 @@ public void onPostInitialize(GeyserPreInitializeEvent event) {
* This method attempts to load the configuration file and logs an error if the process fails.
*/
private void loadConfig() {
try {
this.config = ConfigurationContainer.load(dataFolder.toPath(), Configuration.class);
} catch (Throwable e) {
logger().error("Could not load config.yml file", e);
}

}

/**
Expand Down Expand Up @@ -98,37 +102,6 @@ public void onShutdown(GeyserShutdownEvent event) {
* Reloads the configuration settings.
*/
public synchronized void reload() {
config.reload();
}

/**
* Gets the current configuration container.
*
* @return the configuration container
*/
public ConfigurationContainer<Configuration> config() {
return this.config;
}

/**
* Retrieves the {@link BossBarManager} instance associated with this class.
*
* @return the {@link BossBarManager} used for managing boss bars.
*/
public BossBarManager bossBarManager() {
return this.bossBarManager;
}

/**
* Retrieves the {@link PlayerDataManager} instance associated with this class.
*
* @return the {@link PlayerDataManager} used for managing player data.
*/
public PlayerDataManager playerDataManager() {
return this.playerDataManager;
}

public PlaceholderManager placeholderManager() {
return this.placeholderManager;
// TODO: add reloading for configuration.
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.triassic.geyserdebuginfo.command;

public interface Command {

org.geysermc.geyser.api.command.Command createCommand();
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.triassic.geyserdebuginfo.command.commands;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.api.command.Command;
import org.geysermc.geyser.api.command.CommandSource;
import com.triassic.geyserdebuginfo.GeyserDebugInfo;
import com.triassic.geyserdebuginfo.command.BaseCommand;
import com.triassic.geyserdebuginfo.command.Command;

public class ReloadCommand implements BaseCommand {
public class ReloadCommand implements Command {

private final GeyserDebugInfo instance;

Expand All @@ -17,8 +16,8 @@ public ReloadCommand(
}

@Override
public Command createCommand() {
return Command.builder(instance)
public org.geysermc.geyser.api.command.Command createCommand() {
return org.geysermc.geyser.api.command.Command.builder(instance)
.name("reload")
.playerOnly(false)
.bedrockOnly(false)
Expand All @@ -29,7 +28,7 @@ public Command createCommand() {
.build();
}

private void execute(@NonNull CommandSource commandSource, @NonNull Command command, @NonNull String[] strings) {
private void execute(@NonNull CommandSource commandSource, org.geysermc.geyser.api.command.Command command, @NonNull String[] strings) {
instance.reload();
commandSource.sendMessage("§aGeyserDebugInfo configuration has been reloaded.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.triassic.geyserdebuginfo.command.commands;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.api.command.Command;
import org.geysermc.geyser.api.command.CommandSource;
import org.geysermc.geyser.entity.type.player.SessionPlayerEntity;
import org.geysermc.geyser.session.GeyserSession;
import com.triassic.geyserdebuginfo.GeyserDebugInfo;
import com.triassic.geyserdebuginfo.command.BaseCommand;
import com.triassic.geyserdebuginfo.command.Command;
import com.triassic.geyserdebuginfo.manager.BossBarManager;
import com.triassic.geyserdebuginfo.manager.PlayerDataManager;

public class ToggleCommand implements BaseCommand {
public class ToggleCommand implements Command {

private final GeyserDebugInfo instance;
private final BossBarManager bossBarManager;
Expand All @@ -20,13 +19,13 @@ public ToggleCommand(
final GeyserDebugInfo instance
) {
this.instance = instance;
this.bossBarManager = instance.bossBarManager();
this.playerDataManager = instance.playerDataManager();
this.bossBarManager = instance.getBossBarManager();
this.playerDataManager = instance.getPlayerDataManager();
}

@Override
public Command createCommand() {
return Command.builder(instance)
public org.geysermc.geyser.api.command.Command createCommand() {
return org.geysermc.geyser.api.command.Command.builder(instance)
.name("toggle")
.playerOnly(true)
.bedrockOnly(true)
Expand All @@ -37,7 +36,7 @@ public Command createCommand() {
.build();
}

private void execute(@NonNull CommandSource commandSource, @NonNull Command command, @NonNull String[] strings) {
private void execute(@NonNull CommandSource commandSource, org.geysermc.geyser.api.command.Command command, @NonNull String[] strings) {
final GeyserSession session = (GeyserSession) commandSource.connection();
final SessionPlayerEntity player = session.getPlayerEntity();

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.triassic.geyserdebuginfo.configuration;

import lombok.Getter;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;

import java.util.Arrays;
import java.util.List;

@Getter
@ConfigSerializable
@SuppressWarnings("FieldMayBeFinal")
public class Configuration {

private long refreshInterval = 50;
private List<String> displayFormat = Arrays.asList(
"Geyser Debug Information",
"",
"%player_world%",
"",
"XYZ: %player_x% / %player_y% / %player_z%",
"Block: %player_x:floor% %player_y:floor% %player_z:floor% [%player_relative_x% %player_relative_y% %player_relative_z%]",
"Chunk: %player_chunk_x% %player_chunk_y% %player_chunk_z% [%player_global_x% %player_global_z% in %player_region_file%]",
"Facing: %player_facing% (%player_yaw% / %player_pitch%)"
);
}
Loading

0 comments on commit e95b11e

Please sign in to comment.