Skip to content

Commit

Permalink
GH-165 Use eternalcode commons. (#169)
Browse files Browse the repository at this point in the history
* Use eternalcode commons.

* Make DurationUtil final.
  • Loading branch information
vLuckyyy committed May 19, 2024
1 parent 6b6329c commit e732bdf
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 105 deletions.
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ object Versions {
const val JUNIT_JUPITER_PARAMS = "5.10.2"
const val JUNIT_JUPITER_ENGINE = "5.10.2"

const val ETERNALCODE_COMMONS = "1.1.2"
// TODO: Multification.

const val ADVENTURE_PLATFORM_BUKKIT = "4.3.2"
const val ADVENTURE_TEXT_MINIMESSAGE = "4.16.0"

Expand Down
3 changes: 3 additions & 0 deletions eternalcombat-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ dependencies {
// caffeine
api("com.github.ben-manes.caffeine:caffeine:${Versions.CAFFEINE}")

api("com.eternalcode:eternalcode-commons-bukkit:${Versions.ETERNALCODE_COMMONS}")
api("com.eternalcode:eternalcode-commons-adventure:${Versions.ETERNALCODE_COMMONS}")

// worldguard
compileOnly("com.sk89q.worldguard:worldguard-bukkit:${Versions.WORLD_GUARD_BUKKIT}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public class UpdaterNotificationController implements Listener {

private static final String NEW_VERSION_AVAILABLE = "<b><gradient:#8a1212:#fc6b03>EternalCombat:</gradient></b> <color:#fce303>New version of EternalCombat is available, please update!";
private static final String RECEIVE_UPDATES_PERMISSION = "eternalcombat.receiveupdates";

private final UpdaterService updaterService;
private final PluginConfig pluginConfig;
Expand All @@ -32,7 +33,7 @@ void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
Audience audience = this.audienceProvider.player(player.getUniqueId());

if (!player.hasPermission("eternalcombat.receiveupdates") || !this.pluginConfig.settings.shouldReceivePluginUpdates) {
if (!player.hasPermission(RECEIVE_UPDATES_PERMISSION) || !this.pluginConfig.settings.shouldReceivePluginUpdates) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package com.eternalcode.combat.util;

import com.eternalcode.commons.time.DurationParser;
import com.eternalcode.commons.time.TemporalAmountParser;
import java.time.Duration;
import java.time.temporal.ChronoUnit;

public final class DurationUtil {

private DurationUtil() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}
private static final TemporalAmountParser<Duration> WITHOUT_MILLS = new DurationParser()
.withUnit("s", ChronoUnit.SECONDS)
.withUnit("m", ChronoUnit.MINUTES)
.withUnit("h", ChronoUnit.HOURS)
.withUnit("d", ChronoUnit.DAYS)
.roundOff(ChronoUnit.MILLIS);

public static String format(Duration duration) {
return format(duration, true);
public DurationUtil() {
throw new UnsupportedOperationException("This class cannot be instantiated");
}

public static String format(Duration duration, boolean removeMillis) {
if (removeMillis) {
duration = Duration.ofSeconds(duration.toSeconds());
}

return duration.toString()
.substring(2)
.replaceAll("(\\d[HMS])(?!$)", "$1 ")
.toLowerCase();
public static String format(Duration duration) {
return WITHOUT_MILLS.format(duration);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions eternalcombat-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ tasks.shadowJar {
"org.apache.commons",
"javassist",
"com.github.benmanes.caffeine",
"com.eternalcode.commons"
).forEach { pack ->
relocate(pack, "$prefix.$pack")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
import com.eternalcode.combat.region.RegionProvider;
import com.eternalcode.combat.updater.UpdaterNotificationController;
import com.eternalcode.combat.updater.UpdaterService;
import com.eternalcode.combat.util.legacy.LegacyColorProcessor;
import com.eternalcode.commons.adventure.AdventureLegacyColorPostProcessor;
import com.eternalcode.commons.adventure.AdventureLegacyColorPreProcessor;
import com.google.common.base.Stopwatch;
import dev.rollczi.litecommands.LiteCommands;
import dev.rollczi.litecommands.bukkit.adventure.platform.LiteBukkitAdventurePlatformFactory;
Expand All @@ -53,13 +54,19 @@

public final class CombatPlugin extends JavaPlugin implements EternalCombatApi {

private static final String FALLBACK_PREFIX = "eternalcombat";
private static final int BSTATS_METRICS_ID = 17803;

private FightManager fightManager;
private FightPearlManager fightPearlManager;
private FightTagOutService fightTagOutService;
private FightEffectService fightEffectService;

private LogoutService logoutService;

private DropManager dropManager;
private DropKeepInventoryManager dropKeepInventoryManager;

private RegionProvider regionProvider;

private PluginConfig pluginConfig;
Expand Down Expand Up @@ -92,7 +99,8 @@ public void onEnable() {

this.audienceProvider = BukkitAudiences.create(this);
MiniMessage miniMessage = MiniMessage.builder()
.postProcessor(new LegacyColorProcessor())
.postProcessor(new AdventureLegacyColorPostProcessor())
.preProcessor(new AdventureLegacyColorPreProcessor())
.build();

FightBossBarService fightBossBarService = new FightBossBarService(this.pluginConfig, this.audienceProvider, miniMessage);
Expand All @@ -103,7 +111,7 @@ public void onEnable() {

NotificationAnnouncer notificationAnnouncer = new NotificationAnnouncer(this.audienceProvider, miniMessage);

this.liteCommands = LiteBukkitAdventurePlatformFactory.builder(server, "eternalcombat", this.audienceProvider)
this.liteCommands = LiteBukkitAdventurePlatformFactory.builder(server, FALLBACK_PREFIX, this.audienceProvider)
.argument(Player.class, new BukkitPlayerArgument<>(this.getServer(), this.pluginConfig.messages.playerNotFound))
.contextualBind(Player.class, new BukkitOnlyPlayerContextual<>(this.pluginConfig.messages.admin.onlyForPlayers))

Expand All @@ -118,7 +126,7 @@ public void onEnable() {
FightTask fightTask = new FightTask(server, this.pluginConfig, this.fightManager, fightBossBarService, notificationAnnouncer);
this.getServer().getScheduler().runTaskTimer(this, fightTask, 20L, 20L);

new Metrics(this, 17803);
new Metrics(this, BSTATS_METRICS_ID);

Stream.of(
new PercentDropModifier(this.pluginConfig.dropSettings),
Expand Down

0 comments on commit e732bdf

Please sign in to comment.