Skip to content

Commit

Permalink
Clean build jar.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Nov 9, 2024
1 parent 2724a67 commit a85ff8e
Show file tree
Hide file tree
Showing 8 changed files with 313 additions and 98 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
package kr.toxicity.hud.api;

import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Getter
@SuppressWarnings("unused")
public class BetterHudDependency {
private static final List<BetterHudDependency> DEPENDENCIES = new ArrayList<>();

private final @NotNull String group;
private final @NotNull String name;
private final @NotNull String version;
private final boolean relocate;
private final @NotNull @Unmodifiable List<BetterHudPlatform> platforms;

private BetterHudDependency(
@NotNull String group,
@NotNull String name,
@NotNull String version,
boolean relocate,
@NotNull @Unmodifiable List<BetterHudPlatform> platforms
) {
this.group = group;
this.name = name;
this.version = version;
this.relocate = relocate;
this.platforms = platforms;

DEPENDENCIES.add(this);
}

public static @NotNull @Unmodifiable List<BetterHudDependency> dependencies() {
return Collections.unmodifiableList(DEPENDENCIES);
}

public static final BetterHudDependency GSON = new BetterHudDependency(
"com{}google{}code{}gson",
"gson",
"2.11.0",
false,
List.of(BetterHudPlatform.VELOCITY)
);
public static final BetterHudDependency SNAKEYAML = new BetterHudDependency(
"org{}yaml",
"snakeyaml",
"2.3",
false,
List.of(BetterHudPlatform.VELOCITY, BetterHudPlatform.FABRIC)
);
public static final BetterHudDependency MYSQL_CONNECTOR_J = new BetterHudDependency(
"com{}mysql",
"mysql-connector-j",
"9.1.0",
false,
List.of(BetterHudPlatform.VELOCITY, BetterHudPlatform.FABRIC)
);
public static final BetterHudDependency ASM_COMMONS = new BetterHudDependency(
"org{}ow2{}asm",
"asm-commons",
"9.7.1",
false,
List.of(BetterHudPlatform.VELOCITY)
);
public static final BetterHudDependency EXP4J = new BetterHudDependency(
"net{}objecthunter",
"exp4j",
"0.4.8",
true,
BetterHudPlatform.ALL
);


public static final BetterHudDependency ADVENTURE_API = new BetterHudDependency(
"net{}kyori",
"adventure-api",
BetterHud.ADVENTURE_VERSION,
false,
List.of(BetterHudPlatform.BUKKIT)
);
public static final BetterHudDependency ADVENTURE_KEY = new BetterHudDependency(
"net{}kyori",
"adventure-key",
BetterHud.ADVENTURE_VERSION,
false,
List.of(BetterHudPlatform.BUKKIT)
);
public static final BetterHudDependency ADVENTURE_TEXT_LOGGER_SLF4J = new BetterHudDependency(
"net{}kyori",
"adventure-text-logger-slf4j",
BetterHud.ADVENTURE_VERSION,
false,
List.of(BetterHudPlatform.BUKKIT)
);
public static final BetterHudDependency ADVENTURE_TEXT_SERIALIZER_ANSI = new BetterHudDependency(
"net{}kyori",
"adventure-text-serializer-ansi",
BetterHud.ADVENTURE_VERSION,
false,
List.of(BetterHudPlatform.BUKKIT)
);
public static final BetterHudDependency ADVENTURE_TEXT_SERIALIZER_GSON = new BetterHudDependency(
"net{}kyori",
"adventure-text-serializer-gson",
BetterHud.ADVENTURE_VERSION,
false,
List.of(BetterHudPlatform.BUKKIT)
);
public static final BetterHudDependency ADVENTURE_TEXT_SERIALIZER_PLAIN = new BetterHudDependency(
"net{}kyori",
"adventure-text-serializer-plain",
BetterHud.ADVENTURE_VERSION,
false,
List.of(BetterHudPlatform.BUKKIT)
);
public static final BetterHudDependency ADVENTURE_TEXT_SERIALIZER_LEGACY = new BetterHudDependency(
"net{}kyori",
"adventure-text-serializer-legacy",
BetterHud.ADVENTURE_VERSION,
false,
List.of(BetterHudPlatform.BUKKIT)
);
public static final BetterHudDependency ADVENTURE_TEXT_SERIALIZER_JSON = new BetterHudDependency(
"net{}kyori",
"adventure-text-serializer-json",
BetterHud.ADVENTURE_VERSION,
false,
List.of(BetterHudPlatform.BUKKIT)
);
public static final BetterHudDependency ADVENTURE_TEXT_MINIMESSAGE = new BetterHudDependency(
"net{}kyori",
"adventure-text-minimessage",
BetterHud.ADVENTURE_VERSION,
false,
List.of(BetterHudPlatform.BUKKIT)
);
public static final BetterHudDependency EXAMINATION_API = new BetterHudDependency(
"net{}kyori",
"examination-api",
BetterHud.EXAMINATION_VERSION,
false,
List.of(BetterHudPlatform.BUKKIT)
);
public static final BetterHudDependency EXAMINATION_STRING = new BetterHudDependency(
"net{}kyori",
"examination-string",
BetterHud.EXAMINATION_VERSION,
false,
List.of(BetterHudPlatform.BUKKIT)
);
public static final BetterHudDependency OPTION = new BetterHudDependency(
"net{}kyori",
"option",
"1.0.0",
false,
List.of(BetterHudPlatform.BUKKIT)
);
public static final BetterHudDependency ADVENTURE_NBT = new BetterHudDependency(
"net{}kyori",
"adventure-nbt",
BetterHud.ADVENTURE_VERSION,
false,
List.of(BetterHudPlatform.BUKKIT, BetterHudPlatform.PAPER)
);
public static final BetterHudDependency ADVENTURE_TEXT_SERIALIZER_GSON_LEGACY_IMPL = new BetterHudDependency(
"net{}kyori",
"adventure-text-serializer-gson-legacy-impl",
BetterHud.ADVENTURE_VERSION,
false,
List.of(BetterHudPlatform.BUKKIT, BetterHudPlatform.PAPER)
);
public static final BetterHudDependency ADVENTURE_TEXT_SERIALIZER_JSON_LEGACY_IMPL = new BetterHudDependency(
"net{}kyori",
"adventure-text-serializer-json-legacy-impl",
BetterHud.ADVENTURE_VERSION,
false,
List.of(BetterHudPlatform.BUKKIT, BetterHudPlatform.PAPER)
);
public static final BetterHudDependency ADVENTURE_PLATFORM_BUKKIT = new BetterHudDependency(
"net{}kyori",
"adventure-platform-bukkit",
BetterHud.PLATFORM_VERSION,
false,
List.of(BetterHudPlatform.BUKKIT, BetterHudPlatform.PAPER)
);
public static final BetterHudDependency ADVENTURE_PLATFORM_API = new BetterHudDependency(
"net{}kyori",
"adventure-platform-api",
BetterHud.PLATFORM_VERSION,
false,
List.of(BetterHudPlatform.BUKKIT, BetterHudPlatform.PAPER)
);
public static final BetterHudDependency ADVENTURE_PLATFORM_FACET = new BetterHudDependency(
"net{}kyori",
"adventure-platform-facet",
BetterHud.PLATFORM_VERSION,
false,
List.of(BetterHudPlatform.BUKKIT, BetterHudPlatform.PAPER)
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package kr.toxicity.hud.api;

import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;

import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

@RequiredArgsConstructor
public enum BetterHudPlatform {
BUKKIT(b -> !b.isPaper() && !b.isFabric() && !b.isVelocity()),
PAPER(BetterHudBootstrap::isPaper),
VELOCITY(BetterHudBootstrap::isVelocity),
FABRIC(BetterHudBootstrap::isFabric),
;

public static final @NotNull @Unmodifiable List<BetterHudPlatform> ALL = Arrays.stream(values()).toList();

private final @NotNull Predicate<BetterHudBootstrap> predicate;

public boolean match(@NotNull BetterHudBootstrap bootstrap) {
return predicate.test(bootstrap);
}
}
16 changes: 12 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,12 @@ fun Project.adventure() = dependency("net.kyori:adventure-api:$adventure")
.dependency("net.kyori:adventure-text-serializer-gson:$adventure")
fun Project.library() = also {
it.dependencies {
implementation("org.yaml:snakeyaml:2.3")
implementation("com.google.code.gson:gson:2.11.0")
implementation("net.objecthunter:exp4j:0.4.8")
compileOnly("org.yaml:snakeyaml:2.3")
compileOnly("com.google.code.gson:gson:2.11.0")
compileOnly("net.objecthunter:exp4j:0.4.8")
implementation("me.lucko:jar-relocator:1.7") {
exclude("org.ow2.asm")
}
implementation(rootProject.fileTree("shaded"))
}
}
Expand Down Expand Up @@ -396,7 +399,12 @@ fun Jar.relocateAll() {
JarRelocator(
tempFile,
file,
listOf("kotlin","net.objecthunter.exp4j","org.bstats","org.yaml.snakeyaml").map {
listOf(
"kotlin",
"net.objecthunter.exp4j",
"org.bstats",
"me.lucko.jarrelocator"
).map {
Relocation(it, "${project.group}.shaded.$it")
}
).run()
Expand Down
63 changes: 5 additions & 58 deletions dist/src/main/kotlin/kr/toxicity/hud/BetterHudImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package kr.toxicity.hud

import kr.toxicity.hud.api.BetterHud
import kr.toxicity.hud.api.BetterHudBootstrap
import kr.toxicity.hud.api.BetterHudDependency
import kr.toxicity.hud.api.manager.*
import kr.toxicity.hud.api.plugin.ReloadState
import kr.toxicity.hud.api.plugin.ReloadState.Failure
import kr.toxicity.hud.api.plugin.ReloadState.Success
import kr.toxicity.hud.dependency.Dependency
import kr.toxicity.hud.dependency.DependencyInjector
import kr.toxicity.hud.manager.*
import kr.toxicity.hud.pack.PackGenerator
Expand All @@ -29,63 +29,10 @@ class BetterHudImpl(val bootstrap: BetterHudBootstrap): BetterHud {
mkdir()
})
val injector = DependencyInjector(bootstrap.version(), bootstrap.dataFolder(), bootstrap.logger(), bootstrap.loader())
if (!bootstrap.isVelocity && !bootstrap.isFabric) {
if (!bootstrap.isPaper) {
listOf(
"adventure-api",
"adventure-key",
"adventure-text-logger-slf4j",
"adventure-text-serializer-ansi",
"adventure-text-serializer-gson",
"adventure-text-serializer-plain",
"adventure-text-serializer-legacy",
"adventure-text-serializer-json",
"adventure-text-minimessage",
).forEach {
injector.load(Dependency(
"net{}kyori",
it,
BetterHud.ADVENTURE_VERSION
))
}
listOf(
"examination-api",
"examination-string"
).forEach {
injector.load(Dependency(
"net{}kyori",
it,
BetterHud.EXAMINATION_VERSION
))
}
injector.load(Dependency(
"net{}kyori",
"option",
"1.0.0",
))
}
listOf(
"adventure-nbt",
"adventure-text-serializer-gson-legacy-impl",
"adventure-text-serializer-json-legacy-impl"
).forEach {
injector.load(Dependency(
"net{}kyori",
it,
BetterHud.ADVENTURE_VERSION
))
}
listOf(
"adventure-platform-bukkit",
"adventure-platform-api",
"adventure-platform-facet",
).forEach {
injector.load(Dependency(
"net{}kyori",
it,
BetterHud.PLATFORM_VERSION
))
}
BetterHudDependency.dependencies().forEach {
if (it.platforms.any { p ->
p.match(bootstrap)
}) injector.load(it)
}
}

Expand Down
Loading

0 comments on commit a85ff8e

Please sign in to comment.