Skip to content

Commit

Permalink
Bundle built in modules with plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Redned235 committed Jul 10, 2024
1 parent d6d9127 commit e73a426
Show file tree
Hide file tree
Showing 22 changed files with 187 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
distribution: 'adopt'
cache: gradle
- name: Build with Gradle
run: ./gradlew build
run: ./gradlew bundledJar
- name: Publish to Maven Repository
if: ${{ success() && github.repository == 'BattlePlugins/BattleArena' && github.ref_name == 'rewrite' }}
run: ./gradlew publish
Expand Down
1 change: 0 additions & 1 deletion module/arena-restoration/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ repositories {
}

dependencies {
compileOnlyApi(project(":plugin"))
compileOnly(libs.worldedit)
}
3 changes: 0 additions & 3 deletions module/boundary-enforcer/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
dependencies {
compileOnlyApi(project(":plugin"))
}
14 changes: 14 additions & 0 deletions module/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
subprojects {
dependencies {
compileOnlyApi(project(":plugin"))
}

tasks.jar {
from("src/main/java/resources") {
include("*")
}

archiveFileName.set("${project.name}.jar")
archiveClassifier.set("")
}
}
3 changes: 0 additions & 3 deletions module/classes/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
dependencies {
compileOnlyApi(project(":plugin"))
}
3 changes: 0 additions & 3 deletions module/team-heads/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
dependencies {
compileOnlyApi(project(":plugin"))
}
3 changes: 0 additions & 3 deletions module/tournaments/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
dependencies {
compileOnlyApi(project(":plugin"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.battleplugins.arena.options.Teams;
import org.battleplugins.arena.team.ArenaTeam;
import org.battleplugins.arena.util.IntRange;
import org.battleplugins.arena.util.UnitUtil;
import org.battleplugins.arena.util.Util;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -211,7 +211,7 @@ public void onAdvance(List<Contestant> contestants) throws TournamentException {
}, ticks);

for (Player watchingPlayer : this.watchingPlayers) {
NEXT_ROUND_STARTING_IN.send(watchingPlayer, UnitUtil.toUnitString(watchingPlayer, advanceTime.toSeconds(), TimeUnit.SECONDS));
NEXT_ROUND_STARTING_IN.send(watchingPlayer, Util.toUnitString(advanceTime.toSeconds(), TimeUnit.SECONDS));
}
}
}
Expand Down
1 change: 0 additions & 1 deletion module/vault-integration/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ repositories {
}

dependencies {
compileOnlyApi(project(":plugin"))
compileOnly("com.github.MilkBowl:VaultAPI:1.7")
}
17 changes: 17 additions & 0 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ java {

tasks {
runServer {
dependsOn("bundledJar")

minecraftVersion("1.20.6")

// Set Java 21 (1.20.6 requires Java 21)
Expand All @@ -39,6 +41,21 @@ tasks {
archiveClassifier.set("")
}

create<Jar>("bundledJar") {
dependsOn(jar)
from(sourceSets.main.get().output)

// Bundle in our modules
project(":module").subprojects.forEach {
from(it.tasks.jar) {
into("modules")
}
}

archiveFileName.set("BattleArena.jar")
archiveClassifier.set("")
}

javadoc {
(options as CoreJavadocOptions).addBooleanOption("Xdoclint:none", true)
}
Expand Down
16 changes: 7 additions & 9 deletions plugin/src/main/java/org/battleplugins/arena/BattleArena.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.battleplugins.arena.team.ArenaTeams;
import org.battleplugins.arena.util.CommandInjector;
import org.battleplugins.arena.util.LoggerHolder;
import org.battleplugins.arena.util.Util;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.Configuration;
Expand Down Expand Up @@ -88,6 +89,8 @@ public void onLoad() {
this.arenasPath = dataFolder.resolve("arenas");
Path modulesPath = dataFolder.resolve("modules");

Util.copyDirectories(this.getFile(), modulesPath, "modules");

this.moduleLoader = new ArenaModuleLoader(this, this.getClassLoader(), modulesPath);
try {
this.moduleLoader.loadModules();
Expand Down Expand Up @@ -130,12 +133,7 @@ private void enable() {
this.debugMode = this.config.isDebugMode();

if (Files.notExists(this.arenasPath)) {
this.saveResource("arenas/arena.yml", false);
this.saveResource("arenas/battlegrounds.yml", false);
this.saveResource("arenas/colosseum.yml", false);
this.saveResource("arenas/deathmatch.yml", false);
this.saveResource("arenas/ffa.yml", false);
this.saveResource("arenas/skirmish.yml", false);
Util.copyDirectories(this.getFile(), this.arenasPath, "arenas");
}

Path dataFolder = this.getDataFolder().toPath();
Expand Down Expand Up @@ -166,9 +164,6 @@ private void enable() {
// Enable modules
this.moduleLoader.enableModules();

// Load messages
MessageLoader.load(dataFolder.resolve("messages.yml"));

// Register base command
PluginCommand command = this.getCommand("battlearena");
if (command == null) {
Expand Down Expand Up @@ -220,6 +215,9 @@ public void onServerLoad(ServerLoadEvent event) {
}

private void postInitialize() {
// Load messages
MessageLoader.load(this.getDataFolder().toPath().resolve("messages.yml"));

// Load all arenas
this.loadArenas();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.battleplugins.arena.messages.Messages;
import org.battleplugins.arena.util.InventoryBackup;
import org.battleplugins.arena.util.OptionSelector;
import org.battleplugins.arena.util.UnitUtil;
import org.battleplugins.arena.util.Util;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -179,7 +179,7 @@ public void reload(Player player) {
}

long end = System.currentTimeMillis();
Messages.RELOAD_COMPLETE.send(player, UnitUtil.toUnitString(player, end - start, TimeUnit.MILLISECONDS));
Messages.RELOAD_COMPLETE.send(player, Util.toUnitString(end - start, TimeUnit.MILLISECONDS));
}

public void sendHeader(CommandSender sender) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.battleplugins.arena.config.ParseException;
import org.battleplugins.arena.config.PostProcessable;
import org.battleplugins.arena.util.BlockUtil;
import org.battleplugins.arena.util.FieldUtil;
import org.battleplugins.arena.util.Util;
import org.battleplugins.arena.util.VoidChunkGenerator;
import org.bukkit.Bukkit;
import org.bukkit.World;
Expand Down Expand Up @@ -249,7 +249,7 @@ public final Competition<?> createDynamicCompetition(Arena arena) {
LiveCompetitionMap copy = arena.getMapFactory().create(this.name, arena, this.type, worldName, this.bounds, this.spawns);
// Copy additional fields for custom maps
if (copy.getClass() != LiveCompetitionMap.class) {
FieldUtil.copyFields(this, copy);
Util.copyFields(this, copy);
}

copy.mapWorld = world;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.battleplugins.arena.event.ArenaEventHandler;
import org.battleplugins.arena.event.player.ArenaLeaveEvent;
import org.battleplugins.arena.messages.Messages;
import org.battleplugins.arena.util.UnitUtil;
import org.battleplugins.arena.util.Util;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
Expand Down Expand Up @@ -63,7 +63,7 @@ private void onCountdown() {
if (this.countdown % 60 == 0 || this.countdown == 30 || this.countdown == 15 || this.countdown == 10 || this.countdown <= 5) {
for (ArenaPlayer arenaPlayer : this.getCompetition().getPlayers()) {
Player player = arenaPlayer.getPlayer();
String timeToStart = UnitUtil.toUnitString(player, this.countdown, TimeUnit.SECONDS);
String timeToStart = Util.toUnitString(this.countdown, TimeUnit.SECONDS);

Messages.ARENA_STARTS_IN.send(player, this.competition.getArena().getName(), timeToStart);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ public Map<ArenaEventType<?>, List<EventAction>> provideInstance(@Nullable Path

EventActionType<?> actionType = EventActionType.get(root.value());
if (actionType == null) {
throw new ParseException("Unrecognized event action detected (" + key + ") when loading configuration section " + configurationSection.getName())
throw new ParseException("Unrecognized event action detected (" + root.value() + ") when loading configuration section " + configurationSection.getName())
.context("Section", configuration.getName())
.context("Provided action", key)
.context("Provided action", root.value())
.context("Valid events", EventActionType.values().stream().map(EventActionType::getName).toList().toString())
.cause(ParseException.Cause.INVALID_VALUE)
.type(EventActionType.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void postProcess(Arena arena, Competition<?> competition, Resolvable reso
};

for (Player player : players) {
Component component = MiniMessage.miniMessage().deserialize(resolvable.resolve().resolveToString(message));
Component component = resolvable.resolve().resolveToComponent(MiniMessage.miniMessage().deserialize(message));
switch (messageType) {
case CHAT -> player.sendMessage(component);
case ACTION_BAR -> player.sendActionBar(component);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void call(ArenaPlayer arenaPlayer, Resolvable resolvable) {
.toUpperCase(Locale.ROOT)
);

Component component = MiniMessage.miniMessage().deserialize(resolvable.resolve().resolveToString(message));
Component component = resolvable.resolve().resolveToComponent(MiniMessage.miniMessage().deserialize(message));
switch (messageType) {
case CHAT -> arenaPlayer.getPlayer().sendMessage(component);
case ACTION_BAR -> arenaPlayer.getPlayer().sendActionBar(component);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package org.battleplugins.arena.resolver;

import net.kyori.adventure.text.Component;

public interface Resolver {

String resolveToString(String string);

Component resolveToComponent(Component component);

<T> T resolve(ResolverKey<T> key);

boolean has(ResolverKey<?> key);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.battleplugins.arena.resolver;

import net.kyori.adventure.text.Component;

import java.util.HashMap;
import java.util.Map;

Expand All @@ -20,6 +22,16 @@ public String resolveToString(String string) {
return string;
}

@Override
public Component resolveToComponent(Component component) {
for (Map.Entry<ResolverKey<?>, ResolverProvider<?>> entry : this.results.entrySet()) {
String key = "%" + entry.getKey().getName().replace("-", "_") + "%";
component = component.replaceText(builder -> builder.matchLiteral(key).replacement(entry.getValue().toComponent(this)));
}

return component;
}

@SuppressWarnings("unchecked")
@Override
public <T> T resolve(ResolverKey<T> key) {
Expand Down
24 changes: 0 additions & 24 deletions plugin/src/main/java/org/battleplugins/arena/util/FieldUtil.java

This file was deleted.

54 changes: 0 additions & 54 deletions plugin/src/main/java/org/battleplugins/arena/util/UnitUtil.java

This file was deleted.

Loading

0 comments on commit e73a426

Please sign in to comment.