Skip to content

Commit a85ff8e

Browse files
committed
Clean build jar.
1 parent 2724a67 commit a85ff8e

File tree

8 files changed

+313
-98
lines changed

8 files changed

+313
-98
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
package kr.toxicity.hud.api;
2+
3+
import lombok.Getter;
4+
import org.jetbrains.annotations.NotNull;
5+
import org.jetbrains.annotations.Unmodifiable;
6+
7+
import java.util.ArrayList;
8+
import java.util.Collections;
9+
import java.util.List;
10+
11+
@Getter
12+
@SuppressWarnings("unused")
13+
public class BetterHudDependency {
14+
private static final List<BetterHudDependency> DEPENDENCIES = new ArrayList<>();
15+
16+
private final @NotNull String group;
17+
private final @NotNull String name;
18+
private final @NotNull String version;
19+
private final boolean relocate;
20+
private final @NotNull @Unmodifiable List<BetterHudPlatform> platforms;
21+
22+
private BetterHudDependency(
23+
@NotNull String group,
24+
@NotNull String name,
25+
@NotNull String version,
26+
boolean relocate,
27+
@NotNull @Unmodifiable List<BetterHudPlatform> platforms
28+
) {
29+
this.group = group;
30+
this.name = name;
31+
this.version = version;
32+
this.relocate = relocate;
33+
this.platforms = platforms;
34+
35+
DEPENDENCIES.add(this);
36+
}
37+
38+
public static @NotNull @Unmodifiable List<BetterHudDependency> dependencies() {
39+
return Collections.unmodifiableList(DEPENDENCIES);
40+
}
41+
42+
public static final BetterHudDependency GSON = new BetterHudDependency(
43+
"com{}google{}code{}gson",
44+
"gson",
45+
"2.11.0",
46+
false,
47+
List.of(BetterHudPlatform.VELOCITY)
48+
);
49+
public static final BetterHudDependency SNAKEYAML = new BetterHudDependency(
50+
"org{}yaml",
51+
"snakeyaml",
52+
"2.3",
53+
false,
54+
List.of(BetterHudPlatform.VELOCITY, BetterHudPlatform.FABRIC)
55+
);
56+
public static final BetterHudDependency MYSQL_CONNECTOR_J = new BetterHudDependency(
57+
"com{}mysql",
58+
"mysql-connector-j",
59+
"9.1.0",
60+
false,
61+
List.of(BetterHudPlatform.VELOCITY, BetterHudPlatform.FABRIC)
62+
);
63+
public static final BetterHudDependency ASM_COMMONS = new BetterHudDependency(
64+
"org{}ow2{}asm",
65+
"asm-commons",
66+
"9.7.1",
67+
false,
68+
List.of(BetterHudPlatform.VELOCITY)
69+
);
70+
public static final BetterHudDependency EXP4J = new BetterHudDependency(
71+
"net{}objecthunter",
72+
"exp4j",
73+
"0.4.8",
74+
true,
75+
BetterHudPlatform.ALL
76+
);
77+
78+
79+
public static final BetterHudDependency ADVENTURE_API = new BetterHudDependency(
80+
"net{}kyori",
81+
"adventure-api",
82+
BetterHud.ADVENTURE_VERSION,
83+
false,
84+
List.of(BetterHudPlatform.BUKKIT)
85+
);
86+
public static final BetterHudDependency ADVENTURE_KEY = new BetterHudDependency(
87+
"net{}kyori",
88+
"adventure-key",
89+
BetterHud.ADVENTURE_VERSION,
90+
false,
91+
List.of(BetterHudPlatform.BUKKIT)
92+
);
93+
public static final BetterHudDependency ADVENTURE_TEXT_LOGGER_SLF4J = new BetterHudDependency(
94+
"net{}kyori",
95+
"adventure-text-logger-slf4j",
96+
BetterHud.ADVENTURE_VERSION,
97+
false,
98+
List.of(BetterHudPlatform.BUKKIT)
99+
);
100+
public static final BetterHudDependency ADVENTURE_TEXT_SERIALIZER_ANSI = new BetterHudDependency(
101+
"net{}kyori",
102+
"adventure-text-serializer-ansi",
103+
BetterHud.ADVENTURE_VERSION,
104+
false,
105+
List.of(BetterHudPlatform.BUKKIT)
106+
);
107+
public static final BetterHudDependency ADVENTURE_TEXT_SERIALIZER_GSON = new BetterHudDependency(
108+
"net{}kyori",
109+
"adventure-text-serializer-gson",
110+
BetterHud.ADVENTURE_VERSION,
111+
false,
112+
List.of(BetterHudPlatform.BUKKIT)
113+
);
114+
public static final BetterHudDependency ADVENTURE_TEXT_SERIALIZER_PLAIN = new BetterHudDependency(
115+
"net{}kyori",
116+
"adventure-text-serializer-plain",
117+
BetterHud.ADVENTURE_VERSION,
118+
false,
119+
List.of(BetterHudPlatform.BUKKIT)
120+
);
121+
public static final BetterHudDependency ADVENTURE_TEXT_SERIALIZER_LEGACY = new BetterHudDependency(
122+
"net{}kyori",
123+
"adventure-text-serializer-legacy",
124+
BetterHud.ADVENTURE_VERSION,
125+
false,
126+
List.of(BetterHudPlatform.BUKKIT)
127+
);
128+
public static final BetterHudDependency ADVENTURE_TEXT_SERIALIZER_JSON = new BetterHudDependency(
129+
"net{}kyori",
130+
"adventure-text-serializer-json",
131+
BetterHud.ADVENTURE_VERSION,
132+
false,
133+
List.of(BetterHudPlatform.BUKKIT)
134+
);
135+
public static final BetterHudDependency ADVENTURE_TEXT_MINIMESSAGE = new BetterHudDependency(
136+
"net{}kyori",
137+
"adventure-text-minimessage",
138+
BetterHud.ADVENTURE_VERSION,
139+
false,
140+
List.of(BetterHudPlatform.BUKKIT)
141+
);
142+
public static final BetterHudDependency EXAMINATION_API = new BetterHudDependency(
143+
"net{}kyori",
144+
"examination-api",
145+
BetterHud.EXAMINATION_VERSION,
146+
false,
147+
List.of(BetterHudPlatform.BUKKIT)
148+
);
149+
public static final BetterHudDependency EXAMINATION_STRING = new BetterHudDependency(
150+
"net{}kyori",
151+
"examination-string",
152+
BetterHud.EXAMINATION_VERSION,
153+
false,
154+
List.of(BetterHudPlatform.BUKKIT)
155+
);
156+
public static final BetterHudDependency OPTION = new BetterHudDependency(
157+
"net{}kyori",
158+
"option",
159+
"1.0.0",
160+
false,
161+
List.of(BetterHudPlatform.BUKKIT)
162+
);
163+
public static final BetterHudDependency ADVENTURE_NBT = new BetterHudDependency(
164+
"net{}kyori",
165+
"adventure-nbt",
166+
BetterHud.ADVENTURE_VERSION,
167+
false,
168+
List.of(BetterHudPlatform.BUKKIT, BetterHudPlatform.PAPER)
169+
);
170+
public static final BetterHudDependency ADVENTURE_TEXT_SERIALIZER_GSON_LEGACY_IMPL = new BetterHudDependency(
171+
"net{}kyori",
172+
"adventure-text-serializer-gson-legacy-impl",
173+
BetterHud.ADVENTURE_VERSION,
174+
false,
175+
List.of(BetterHudPlatform.BUKKIT, BetterHudPlatform.PAPER)
176+
);
177+
public static final BetterHudDependency ADVENTURE_TEXT_SERIALIZER_JSON_LEGACY_IMPL = new BetterHudDependency(
178+
"net{}kyori",
179+
"adventure-text-serializer-json-legacy-impl",
180+
BetterHud.ADVENTURE_VERSION,
181+
false,
182+
List.of(BetterHudPlatform.BUKKIT, BetterHudPlatform.PAPER)
183+
);
184+
public static final BetterHudDependency ADVENTURE_PLATFORM_BUKKIT = new BetterHudDependency(
185+
"net{}kyori",
186+
"adventure-platform-bukkit",
187+
BetterHud.PLATFORM_VERSION,
188+
false,
189+
List.of(BetterHudPlatform.BUKKIT, BetterHudPlatform.PAPER)
190+
);
191+
public static final BetterHudDependency ADVENTURE_PLATFORM_API = new BetterHudDependency(
192+
"net{}kyori",
193+
"adventure-platform-api",
194+
BetterHud.PLATFORM_VERSION,
195+
false,
196+
List.of(BetterHudPlatform.BUKKIT, BetterHudPlatform.PAPER)
197+
);
198+
public static final BetterHudDependency ADVENTURE_PLATFORM_FACET = new BetterHudDependency(
199+
"net{}kyori",
200+
"adventure-platform-facet",
201+
BetterHud.PLATFORM_VERSION,
202+
false,
203+
List.of(BetterHudPlatform.BUKKIT, BetterHudPlatform.PAPER)
204+
);
205+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package kr.toxicity.hud.api;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import org.jetbrains.annotations.NotNull;
5+
import org.jetbrains.annotations.Unmodifiable;
6+
7+
import java.util.Arrays;
8+
import java.util.List;
9+
import java.util.function.Predicate;
10+
11+
@RequiredArgsConstructor
12+
public enum BetterHudPlatform {
13+
BUKKIT(b -> !b.isPaper() && !b.isFabric() && !b.isVelocity()),
14+
PAPER(BetterHudBootstrap::isPaper),
15+
VELOCITY(BetterHudBootstrap::isVelocity),
16+
FABRIC(BetterHudBootstrap::isFabric),
17+
;
18+
19+
public static final @NotNull @Unmodifiable List<BetterHudPlatform> ALL = Arrays.stream(values()).toList();
20+
21+
private final @NotNull Predicate<BetterHudBootstrap> predicate;
22+
23+
public boolean match(@NotNull BetterHudBootstrap bootstrap) {
24+
return predicate.test(bootstrap);
25+
}
26+
}

build.gradle.kts

+12-4
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,12 @@ fun Project.adventure() = dependency("net.kyori:adventure-api:$adventure")
192192
.dependency("net.kyori:adventure-text-serializer-gson:$adventure")
193193
fun Project.library() = also {
194194
it.dependencies {
195-
implementation("org.yaml:snakeyaml:2.3")
196-
implementation("com.google.code.gson:gson:2.11.0")
197-
implementation("net.objecthunter:exp4j:0.4.8")
195+
compileOnly("org.yaml:snakeyaml:2.3")
196+
compileOnly("com.google.code.gson:gson:2.11.0")
197+
compileOnly("net.objecthunter:exp4j:0.4.8")
198+
implementation("me.lucko:jar-relocator:1.7") {
199+
exclude("org.ow2.asm")
200+
}
198201
implementation(rootProject.fileTree("shaded"))
199202
}
200203
}
@@ -396,7 +399,12 @@ fun Jar.relocateAll() {
396399
JarRelocator(
397400
tempFile,
398401
file,
399-
listOf("kotlin","net.objecthunter.exp4j","org.bstats","org.yaml.snakeyaml").map {
402+
listOf(
403+
"kotlin",
404+
"net.objecthunter.exp4j",
405+
"org.bstats",
406+
"me.lucko.jarrelocator"
407+
).map {
400408
Relocation(it, "${project.group}.shaded.$it")
401409
}
402410
).run()

dist/src/main/kotlin/kr/toxicity/hud/BetterHudImpl.kt

+5-58
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package kr.toxicity.hud
22

33
import kr.toxicity.hud.api.BetterHud
44
import kr.toxicity.hud.api.BetterHudBootstrap
5+
import kr.toxicity.hud.api.BetterHudDependency
56
import kr.toxicity.hud.api.manager.*
67
import kr.toxicity.hud.api.plugin.ReloadState
78
import kr.toxicity.hud.api.plugin.ReloadState.Failure
89
import kr.toxicity.hud.api.plugin.ReloadState.Success
9-
import kr.toxicity.hud.dependency.Dependency
1010
import kr.toxicity.hud.dependency.DependencyInjector
1111
import kr.toxicity.hud.manager.*
1212
import kr.toxicity.hud.pack.PackGenerator
@@ -29,63 +29,10 @@ class BetterHudImpl(val bootstrap: BetterHudBootstrap): BetterHud {
2929
mkdir()
3030
})
3131
val injector = DependencyInjector(bootstrap.version(), bootstrap.dataFolder(), bootstrap.logger(), bootstrap.loader())
32-
if (!bootstrap.isVelocity && !bootstrap.isFabric) {
33-
if (!bootstrap.isPaper) {
34-
listOf(
35-
"adventure-api",
36-
"adventure-key",
37-
"adventure-text-logger-slf4j",
38-
"adventure-text-serializer-ansi",
39-
"adventure-text-serializer-gson",
40-
"adventure-text-serializer-plain",
41-
"adventure-text-serializer-legacy",
42-
"adventure-text-serializer-json",
43-
"adventure-text-minimessage",
44-
).forEach {
45-
injector.load(Dependency(
46-
"net{}kyori",
47-
it,
48-
BetterHud.ADVENTURE_VERSION
49-
))
50-
}
51-
listOf(
52-
"examination-api",
53-
"examination-string"
54-
).forEach {
55-
injector.load(Dependency(
56-
"net{}kyori",
57-
it,
58-
BetterHud.EXAMINATION_VERSION
59-
))
60-
}
61-
injector.load(Dependency(
62-
"net{}kyori",
63-
"option",
64-
"1.0.0",
65-
))
66-
}
67-
listOf(
68-
"adventure-nbt",
69-
"adventure-text-serializer-gson-legacy-impl",
70-
"adventure-text-serializer-json-legacy-impl"
71-
).forEach {
72-
injector.load(Dependency(
73-
"net{}kyori",
74-
it,
75-
BetterHud.ADVENTURE_VERSION
76-
))
77-
}
78-
listOf(
79-
"adventure-platform-bukkit",
80-
"adventure-platform-api",
81-
"adventure-platform-facet",
82-
).forEach {
83-
injector.load(Dependency(
84-
"net{}kyori",
85-
it,
86-
BetterHud.PLATFORM_VERSION
87-
))
88-
}
32+
BetterHudDependency.dependencies().forEach {
33+
if (it.platforms.any { p ->
34+
p.match(bootstrap)
35+
}) injector.load(it)
8936
}
9037
}
9138

0 commit comments

Comments
 (0)