Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d8e825ede | ||
|
|
cbbb11ba3f | ||
|
|
8c75d21e11 |
No files matched your search
@@ -20,6 +20,19 @@ encounter any compatibility issues, please report them in the
|
||||
[Issues tab](https://github.com/EternalCodeTeam/EternalCombat/issues). The plugin requires Java 17 or later, so please
|
||||
make sure it is installed on your server.
|
||||
|
||||
## PlaceholderAPI
|
||||
|
||||
EternalCombat supports PlaceholderAPI, which allows you to use placeholders in other plugins that support it.
|
||||
To use placeholders, follow PlaceholderAPI's [instructions](https://wiki.placeholderapi.com/users/) and use the placeholders provided by EternalCombat.
|
||||
Provided placeholders:
|
||||
- `%eternalcombat_opponent%` - Returns the name of the player with whom the player is fighting.
|
||||
- `%eternalcombat_opponent_healths%` - Returns the number of minutes remaining until the player is no longer in combat.
|
||||
- `%eternalcombat_remaining_seconds%` - Returns the number of seconds remaining until the player is no longer in combat.
|
||||
- `%eternalcombat_remaining_millis%` - Returns the number of milliseconds remaining until the player is no longer in combat.
|
||||
|
||||
If the player is not in combat, the placeholders will return an empty string.
|
||||
If combat was not caused by other player, opponent placeholders will return empty string.
|
||||
|
||||
## Building
|
||||
Build EternalCombat using:
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ object Versions {
|
||||
const val B_STATS_BUKKIT = "3.0.2"
|
||||
const val WORLD_GUARD_BUKKIT = "7.0.9"
|
||||
|
||||
const val PLACEHOLDER_API = "2.11.5"
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,4 +11,5 @@ repositories {
|
||||
maven { url = uri("https://storehouse.okaeri.eu/repository/maven-public/") }
|
||||
maven { url = uri("https://repo.panda-lang.org/releases") }
|
||||
maven { url = uri("https://maven.enginehub.org/repo/") }
|
||||
maven { url = uri("https://repo.extendedclip.com/content/repositories/placeholderapi/")}
|
||||
}
|
||||
@@ -42,4 +42,7 @@ dependencies {
|
||||
// worldguard
|
||||
compileOnly("com.sk89q.worldguard:worldguard-bukkit:${Versions.WORLD_GUARD_BUKKIT}")
|
||||
|
||||
// PlaceholderAPI
|
||||
compileOnlyApi("me.clip:placeholderapi:${Versions.PLACEHOLDER_API}")
|
||||
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public class CombatCommand {
|
||||
Formatter formatter = new Formatter()
|
||||
.register("{PLAYER}", target.getName());
|
||||
|
||||
FightTagEvent event = this.fightManager.tag(targetUniqueId, time, CauseOfTag.COMMAND);
|
||||
FightTagEvent event = this.fightManager.tag(targetUniqueId, time, CauseOfTag.COMMAND, null);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
this.announcer.sendMessage(sender, event.getCancelMessage());
|
||||
@@ -80,8 +80,8 @@ public class CombatCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
FightTagEvent firstTagEvent = this.fightManager.tag(firstTarget.getUniqueId(), combatTime, CauseOfTag.COMMAND);
|
||||
FightTagEvent secondTagEvent = this.fightManager.tag(secondTarget.getUniqueId(), combatTime, CauseOfTag.COMMAND);
|
||||
FightTagEvent firstTagEvent = this.fightManager.tag(firstTarget.getUniqueId(), combatTime, CauseOfTag.COMMAND, null);
|
||||
FightTagEvent secondTagEvent = this.fightManager.tag(secondTarget.getUniqueId(), combatTime, CauseOfTag.COMMAND, null);
|
||||
|
||||
Formatter formatter = new Formatter()
|
||||
.register("{FIRST_PLAYER}", firstTarget.getName())
|
||||
|
||||
@@ -43,7 +43,7 @@ public class FightManager {
|
||||
return event;
|
||||
}
|
||||
|
||||
public FightTagEvent tag(UUID target, Duration delay, CauseOfTag causeOfTag) {
|
||||
public FightTagEvent tag(UUID target, Duration delay, CauseOfTag causeOfTag, UUID tagger) {
|
||||
FightTagEvent event = this.eventCaller.publishEvent(new FightTagEvent(target, causeOfTag));
|
||||
|
||||
if (event.isCancelled()) {
|
||||
@@ -52,7 +52,7 @@ public class FightManager {
|
||||
Instant now = Instant.now();
|
||||
Instant endOfCombatLog = now.plus(delay);
|
||||
|
||||
FightTag fightTag = new FightTag(target, endOfCombatLog);
|
||||
FightTag fightTag = new FightTag(target, endOfCombatLog, tagger);
|
||||
|
||||
this.fights.put(target, fightTag);
|
||||
return event;
|
||||
|
||||
@@ -8,11 +8,12 @@ public class FightTag {
|
||||
|
||||
private final UUID taggedPlayer;
|
||||
private final Instant endOfCombatLog;
|
||||
private UUID tagger;
|
||||
|
||||
FightTag(UUID personToAddCombat, Instant endOfCombatLog) {
|
||||
FightTag(UUID personToAddCombat, Instant endOfCombatLog, UUID tagger) {
|
||||
this.taggedPlayer = personToAddCombat;
|
||||
this.endOfCombatLog = endOfCombatLog;
|
||||
|
||||
this.tagger = tagger;
|
||||
}
|
||||
|
||||
public UUID getTaggedPlayer() {
|
||||
@@ -37,4 +38,8 @@ public class FightTag {
|
||||
return between;
|
||||
}
|
||||
|
||||
public UUID getTagger() {
|
||||
return this.tagger;
|
||||
}
|
||||
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
package com.eternalcode.combat.fight;
|
||||
|
||||
import com.eternalcode.combat.util.DurationUtil;
|
||||
import com.eternalcode.commons.time.DurationParser;
|
||||
import java.time.Duration;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FightTagPlaceholder extends PlaceholderExpansion {
|
||||
|
||||
private final FightManager fightManager;
|
||||
private final Server server;
|
||||
|
||||
public FightTagPlaceholder(FightManager fightManager, Server server) {
|
||||
this.fightManager = fightManager;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRegister() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "eternalcombat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getAuthor() {
|
||||
return "EternalCode";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getVersion() {
|
||||
return "1.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onRequest(OfflinePlayer player, String identifier) {
|
||||
if (identifier.equals("remaining_seconds")) {
|
||||
|
||||
FightTag fightTag = this.getFightTag(player);
|
||||
|
||||
if (fightTag == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
Duration duration = fightTag.getRemainingDuration();
|
||||
|
||||
return DurationUtil.format(duration);
|
||||
|
||||
}
|
||||
if (identifier.equals("remaining_millis")) {
|
||||
|
||||
FightTag fightTag = this.getFightTag(player);
|
||||
|
||||
if (fightTag == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
Duration duration = fightTag.getRemainingDuration();
|
||||
|
||||
return DurationParser.TIME_UNITS.format(duration);
|
||||
|
||||
}
|
||||
if (identifier.equals("opponent")) {
|
||||
|
||||
FightTag fightTag = this.getFightTag(player);
|
||||
|
||||
if (fightTag == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
Player opponent = this.server.getPlayer(fightTag.getTagger());
|
||||
|
||||
if (opponent == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return opponent.getName();
|
||||
|
||||
}
|
||||
if (identifier.equals("opponent_health")) {
|
||||
|
||||
FightTag fightTag = this.getFightTag(player);
|
||||
|
||||
if (fightTag == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
Player opponent = this.server.getPlayer(fightTag.getTagger());
|
||||
|
||||
if (opponent == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return String.valueOf(opponent.getHealth());
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private FightTag getFightTag(OfflinePlayer player) {
|
||||
if (player.isOnline()) {
|
||||
Player onlinePlayer = player.getPlayer();
|
||||
assert onlinePlayer != null;
|
||||
|
||||
if (!this.fightManager.isInCombat(onlinePlayer.getUniqueId())) {
|
||||
return null;
|
||||
}
|
||||
return this.fightManager.getTag(onlinePlayer.getUniqueId());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -74,8 +74,8 @@ public class FightTagController implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
this.fightManager.tag(attackedUniqueId, combatTime, CauseOfTag.PLAYER);
|
||||
this.fightManager.tag(attackerUniqueId, combatTime, CauseOfTag.PLAYER);
|
||||
this.fightManager.tag(attackedUniqueId, combatTime, CauseOfTag.PLAYER, attackerUniqueId);
|
||||
this.fightManager.tag(attackerUniqueId, combatTime, CauseOfTag.PLAYER, attackedUniqueId);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
@@ -107,7 +107,7 @@ public class FightTagController implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
this.fightManager.tag(uuid, combatTime, CauseOfTag.NON_PLAYER);
|
||||
this.fightManager.tag(uuid, combatTime, CauseOfTag.NON_PLAYER, null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -18,6 +18,7 @@ bukkit {
|
||||
prefix = "EternalCombat"
|
||||
name = "EternalCombat"
|
||||
softDepend = listOf("WorldGuard")
|
||||
softDepend = listOf("PlaceholderAPI")
|
||||
version = "${project.version}"
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.eternalcode.combat.drop.DropKeepInventoryManager;
|
||||
import com.eternalcode.combat.drop.DropManager;
|
||||
import com.eternalcode.combat.drop.impl.PercentDropModifier;
|
||||
import com.eternalcode.combat.drop.impl.PlayersHealthDropModifier;
|
||||
import com.eternalcode.combat.fight.FightTagPlaceholder;
|
||||
import com.eternalcode.combat.fight.controller.FightActionBlockerController;
|
||||
import com.eternalcode.combat.fight.controller.FightMessageController;
|
||||
import com.eternalcode.combat.fight.controller.FightTagController;
|
||||
@@ -46,6 +47,7 @@ import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
@@ -85,6 +87,8 @@ public final class CombatPlugin extends JavaPlugin implements EternalCombatApi {
|
||||
|
||||
EventCaller eventCaller = new EventCaller(server);
|
||||
|
||||
Plugin placeholderAPI = this.getServer().getPluginManager().getPlugin("PlaceholderAPI");
|
||||
|
||||
this.pluginConfig = configService.create(PluginConfig.class, new File(dataFolder, "config.yml"));
|
||||
|
||||
this.fightManager = new FightManager(eventCaller);
|
||||
@@ -133,6 +137,14 @@ public final class CombatPlugin extends JavaPlugin implements EternalCombatApi {
|
||||
new PlayersHealthDropModifier(this.pluginConfig.dropSettings, this.logoutService)
|
||||
).forEach(this.dropManager::registerModifier);
|
||||
|
||||
if (placeholderAPI != null && placeholderAPI.isEnabled()) {
|
||||
new FightTagPlaceholder(this.fightManager, server).register();
|
||||
}
|
||||
else {
|
||||
getLogger().warning("PlaceholderAPI is not enabled. Placeholders will not work.");
|
||||
}
|
||||
|
||||
|
||||
Stream.of(
|
||||
new DropController(this.dropManager, this.dropKeepInventoryManager, this.pluginConfig.dropSettings, this.fightManager),
|
||||
new FightTagController(this.fightManager, this.pluginConfig),
|
||||
|
||||
Reference in new issue
Block a user