Skip to content
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/eternalcombat-java.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = "com.eternalcode"
version = "2.2.0"
version = "2.2.1-SNAPSHOT"

tasks.compileJava {
options.compilerArgs = listOf("-Xlint:deprecation", "-parameters")
Expand Down
3 changes: 2 additions & 1 deletion eternalcombat-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ bukkit {
tasks {
runServer {
minecraftVersion("1.21.4")
downloadPlugins.url("https://github.com/retrooper/packetevents/releases/download/v2.8.0/packetevents-spigot-2.8.0.jar")
downloadPlugins.url("https://www.spigotmc.org/resources/packetevents-api.80279/download?version=599651")
downloadPlugins.url("https://www.spigotmc.org/resources/placeholderapi.6245/download?version=541946")
Comment on lines +78 to +79
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you can download plugins from SpigotMC? Don't they have some sort of anti-CDN downloader?

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.bukkit.command.CommandSender;

@Command(name = "combatlog", aliases = "combat")
@Permission("eternalcombat.reload")
public class EternalCombatReloadCommand {

private static final Notice RELOAD_MESSAGE = BukkitNotice.builder()
Expand All @@ -31,6 +30,7 @@ public EternalCombatReloadCommand(ConfigService configService, NoticeService not

@Async
@Execute(name = "reload")
@Permission("eternalcombat.reload")
void execute(@Context CommandSender sender) {
Stopwatch stopwatch = Stopwatch.createStarted();
this.configService.reload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void init(Server server) {

initialize(
"PlaceholderAPI",
() -> new FightTagPlaceholder(this.fightManager, server, this.plugin).register(),
() -> new FightTagPlaceholder(this.config.placeholders, this.fightManager, server, this.plugin).register(),
() -> this.logger.warning("PlaceholderAPI not found; skipping placeholders.")
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.eternalcode.combat.bridge.placeholder;

import com.eternalcode.combat.config.implementation.PlaceholderSettings;
import com.eternalcode.combat.fight.FightManager;
import com.eternalcode.combat.fight.FightTag;
import com.eternalcode.combat.util.DurationUtil;
Expand All @@ -14,12 +15,14 @@

public class FightTagPlaceholder extends PlaceholderExpansion {

private static final String IDENTIFIER = "eternalcombat";
private final PlaceholderSettings placeholderSettings;
private final FightManager fightManager;
private final Server server;
private final Plugin plugin;
private static final String IDENTIFIER = "eternalcombat";

public FightTagPlaceholder(FightManager fightManager, Server server, Plugin plugin) {
public FightTagPlaceholder(PlaceholderSettings placeholderSettings, FightManager fightManager, Server server, Plugin plugin) {
this.placeholderSettings = placeholderSettings;
this.fightManager = fightManager;
this.server = server;
this.plugin = plugin;
Expand All @@ -30,7 +33,6 @@ public boolean canRegister() {
return true;
}


@Override
public @NotNull String getIdentifier() {
return IDENTIFIER;
Expand All @@ -48,15 +50,11 @@ public boolean canRegister() {

@Override
public String onRequest(OfflinePlayer player, String identifier) {
if (identifier.equals("remaining_seconds")) {
return this.getFightTag(player)
.map(fightTagInter -> DurationUtil.format(fightTagInter.getRemainingDuration()))
.orElse("");
}

if (identifier.equals("remaining_millis")) {
if (identifier.equals("remaining_seconds") || identifier.equals("remaining_millis")) {
return this.getFightTag(player)
.map(fightTag -> DurationParser.TIME_UNITS.format(fightTag.getRemainingDuration()))
.map(fightTagInter -> identifier.equals("remaining_millis")
? DurationParser.TIME_UNITS.format(fightTagInter.getRemainingDuration())
: DurationUtil.format(fightTagInter.getRemainingDuration()))
.orElse("");
}

Expand All @@ -72,6 +70,19 @@ public String onRequest(OfflinePlayer player, String identifier) {
.orElse("");
}

if (identifier.equals("isInCombat") || identifier.equals("isInCombat_formatted")) {
Player onlinePlayer = player.getPlayer();
boolean inCombat = onlinePlayer != null && this.fightManager.isInCombat(onlinePlayer.getUniqueId());

if (identifier.equals("isInCombat")) {
return String.valueOf(inCombat);
}

return inCombat
? this.placeholderSettings.isInCombatFormattedTrue
: this.placeholderSettings.isInCombatFormattedFalse;
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.eternalcode.combat.config.implementation;

import eu.okaeri.configs.OkaeriConfig;
import eu.okaeri.configs.annotation.Comment;

public class PlaceholderSettings extends OkaeriConfig {

@Comment("Text returned by %eternalcombat_isInCombat_formatted% placeholder when the player is in combat")
public String isInCombatFormattedTrue = "In Combat";

@Comment("Text returned by %eternalcombat_isInCombat_formatted% placeholder when the player is out of combat")
public String isInCombatFormattedFalse = "Not In Combat";

}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ public class PluginConfig extends OkaeriConfig {
})
public CombatSettings combat = new CombatSettings();

@Comment({
" ",
"# Settings related to placeholders used in the plugin.",
"# Configure default values returned by placeholders"
})
public PlaceholderSettings placeholders = new PlaceholderSettings();

@Comment({
" ",
"# Customize the messages displayed by the plugin.",
Expand Down
Loading