Skip to content

Commit

Permalink
Add message replacement support
Browse files Browse the repository at this point in the history
  • Loading branch information
Redned235 committed Jul 10, 2024
1 parent b4bec98 commit d6d9127
Show file tree
Hide file tree
Showing 54 changed files with 477 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.battleplugins.arena.competition.LiveCompetition;
import org.battleplugins.arena.competition.map.options.Bounds;
import org.battleplugins.arena.event.action.EventAction;
import org.battleplugins.arena.resolver.Resolvable;

import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -32,7 +33,7 @@ public RestoreArenaAction(Map<String, String> params) {
}

@Override
public void postProcess(Arena arena, Competition<?> competition) {
public void postProcess(Arena arena, Competition<?> competition, Resolvable resolvable) {
if (!arena.isModuleEnabled(ArenaRestoration.ID)) {
return;
}
Expand Down Expand Up @@ -95,7 +96,7 @@ public void postProcess(Arena arena, Competition<?> competition) {
}

@Override
public void call(ArenaPlayer arenaPlayer) {
public void call(ArenaPlayer arenaPlayer, Resolvable resolvable) {
// No-op
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.battleplugins.arena.ArenaPlayer;
import org.battleplugins.arena.event.action.EventAction;
import org.battleplugins.arena.options.types.BooleanArenaOption;
import org.battleplugins.arena.resolver.Resolvable;

import java.util.Map;
import java.util.Optional;
Expand All @@ -18,7 +19,7 @@ public EquipClassAction(Map<String, String> params) {
}

@Override
public void call(ArenaPlayer arenaPlayer) {
public void call(ArenaPlayer arenaPlayer, Resolvable resolvable) {
if (!arenaPlayer.getArena().isModuleEnabled(Classes.ID)) {
return;
}
Expand Down
3 changes: 0 additions & 3 deletions module/join-messages/build.gradle.kts

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.kyori.adventure.text.format.TextDecoration;
import org.battleplugins.arena.ArenaPlayer;
import org.battleplugins.arena.event.action.EventAction;
import org.battleplugins.arena.resolver.Resolvable;
import org.battleplugins.arena.team.ArenaTeam;
import org.bukkit.inventory.ItemStack;

Expand All @@ -17,7 +18,7 @@ public TeamHeadsAction(Map<String, String> params) {
}

@Override
public void call(ArenaPlayer arenaPlayer) {
public void call(ArenaPlayer arenaPlayer, Resolvable resolvable) {
if (!arenaPlayer.getArena().isModuleEnabled(TeamHeads.ID)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.battleplugins.arena.ArenaPlayer;
import org.battleplugins.arena.event.action.EventAction;
import org.battleplugins.arena.resolver.Resolvable;

import java.util.Map;
import java.util.Optional;
Expand All @@ -15,7 +16,7 @@ public AddPermissionAction(Map<String, String> params) {
}

@Override
public void call(ArenaPlayer arenaPlayer) {
public void call(ArenaPlayer arenaPlayer, Resolvable resolvable) {
if (!arenaPlayer.getArena().isModuleEnabled(VaultIntegration.ID)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.battleplugins.arena.ArenaPlayer;
import org.battleplugins.arena.event.action.EventAction;
import org.battleplugins.arena.resolver.Resolvable;

import java.util.Map;
import java.util.Optional;
Expand All @@ -15,7 +16,7 @@ public EditCurrencyAction(Map<String, String> params) {
}

@Override
public void call(ArenaPlayer arenaPlayer) {
public void call(ArenaPlayer arenaPlayer, Resolvable resolvable) {
if (!arenaPlayer.getArena().isModuleEnabled(VaultIntegration.ID)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.battleplugins.arena.ArenaPlayer;
import org.battleplugins.arena.event.action.EventAction;
import org.battleplugins.arena.resolver.Resolvable;

import java.util.Map;
import java.util.Optional;
Expand All @@ -15,7 +16,7 @@ public RemovePermissionAction(Map<String, String> params) {
}

@Override
public void call(ArenaPlayer arenaPlayer) {
public void call(ArenaPlayer arenaPlayer, Resolvable resolvable) {
if (!arenaPlayer.getArena().isModuleEnabled(VaultIntegration.ID)) {
return;
}
Expand Down
13 changes: 12 additions & 1 deletion plugin/src/main/java/org/battleplugins/arena/Arena.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
import org.battleplugins.arena.options.ArenaOptionType;
import org.battleplugins.arena.options.Lives;
import org.battleplugins.arena.options.Teams;
import org.battleplugins.arena.resolver.Resolvable;
import org.battleplugins.arena.resolver.Resolver;
import org.battleplugins.arena.resolver.ResolverKeys;
import org.battleplugins.arena.resolver.ResolverProvider;
import org.jetbrains.annotations.Nullable;

import java.nio.file.Path;
Expand All @@ -42,7 +46,7 @@
* active game actions will occur (i.e. game timer, score, etc.)
*/
@DocumentationSource("https://docs.battleplugins.org/books/user-guide/chapter/configuration")
public class Arena implements ArenaLike, ArenaListener {
public class Arena implements ArenaLike, ArenaListener, Resolvable {

@Scoped
private BattleArena plugin;
Expand Down Expand Up @@ -316,4 +320,11 @@ public final <E extends org.battleplugins.arena.options.ArenaOption> E getOption
public final Arena getArena() {
return this;
}

@Override
public Resolver resolve() {
return Resolver.builder()
.define(ResolverKeys.ARENA, ResolverProvider.simple(this, Arena::getName))
.build();
}
}
24 changes: 23 additions & 1 deletion plugin/src/main/java/org/battleplugins/arena/ArenaPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import org.battleplugins.arena.event.player.ArenaStatChangeEvent;
import org.battleplugins.arena.event.player.ArenaTeamJoinEvent;
import org.battleplugins.arena.event.player.ArenaTeamLeaveEvent;
import org.battleplugins.arena.resolver.Resolvable;
import org.battleplugins.arena.resolver.Resolver;
import org.battleplugins.arena.resolver.ResolverKeys;
import org.battleplugins.arena.resolver.ResolverProvider;
import org.battleplugins.arena.stat.ArenaStat;
import org.battleplugins.arena.stat.StatHolder;
import org.battleplugins.arena.team.ArenaTeam;
Expand All @@ -21,7 +25,7 @@
/**
* Represents a player in an active competition.
*/
public class ArenaPlayer implements StatHolder {
public class ArenaPlayer implements StatHolder, Resolvable {
private static final String ARENA_PLAYER_META_KEY = "arena-player";

private final Player player;
Expand Down Expand Up @@ -275,6 +279,24 @@ public void resetState() {
this.competition.findAndJoinTeamIfApplicable(this);
}


@Override
public String describe() {
return this.getPlayer().getName();
}

@Override
public Resolver resolve() {
Resolver.Builder builder = this.competition.resolve().toBuilder()
.define(ResolverKeys.PLAYER, ResolverProvider.simple(this, this.player::getName));

if (this.team != null) {
builder.define(ResolverKeys.TEAM, ResolverProvider.simple(this.team, ArenaTeam::getName, ArenaTeam::getFormattedName));
}

return builder.build();
}

@Override
public String toString() {
return "ArenaPlayer{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
import org.battleplugins.arena.options.ArenaOptionType;
import org.battleplugins.arena.options.TeamSelection;
import org.battleplugins.arena.options.Teams;
import org.battleplugins.arena.resolver.Resolvable;
import org.battleplugins.arena.resolver.Resolver;
import org.battleplugins.arena.resolver.ResolverKeys;
import org.battleplugins.arena.resolver.ResolverProvider;
import org.battleplugins.arena.team.ArenaTeam;
import org.battleplugins.arena.team.ArenaTeams;
import org.battleplugins.arena.util.IntRange;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;

Expand All @@ -37,7 +40,7 @@
* A {@link Competition} that is occurring on the same server
* that this plugin is running on.
*/
public class LiveCompetition<T extends Competition<T>> implements ArenaLike, Competition<T> {
public class LiveCompetition<T extends Competition<T>> implements ArenaLike, Competition<T>, Resolvable {
private final Arena arena;
private final CompetitionType type;
private final LiveCompetitionMap map;
Expand Down Expand Up @@ -364,4 +367,14 @@ private int calculateMaxPlayers() {

return maxPlayers;
}

@Override
public Resolver resolve() {
return this.arena.resolve().toBuilder()
.define(ResolverKeys.COMPETITION, ResolverProvider.simple(this.getCompetition(), this.getMap()::getName))
.define(ResolverKeys.ONLINE_PLAYERS, ResolverProvider.simple(this.getPlayers().size(), String::valueOf))
.define(ResolverKeys.MAX_PLAYERS, ResolverProvider.simple(this.getMaxPlayers(), String::valueOf))
.define(ResolverKeys.PLAYERS, ResolverProvider.simple(this.getPlayers(), players -> String.join(", ", players.stream().map(p -> p.getPlayer().getName()).toList())))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public void onStatChange(ArenaStatChangeEvent<?> event) {
return;
}

if (newValue < 0) {
return;
}

this.competition.getArena().getEventManager().callEvent(new ArenaLifeDepleteEvent(this.competition.getArena(), player, newValue));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public <T> void computeStat(ArenaStat<T> stat, Function<? super T, ? extends T>
});
}

@Override
public String describe() {
return this.team.getName();
}

public ArenaTeam getTeam() {
return this.team;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import org.battleplugins.arena.Arena;
import org.battleplugins.arena.competition.Competition;
import org.battleplugins.arena.resolver.Resolvable;
import org.battleplugins.arena.resolver.Resolver;
import org.battleplugins.arena.resolver.ResolverKeys;
import org.battleplugins.arena.resolver.ResolverProvider;
import org.jetbrains.annotations.Nullable;

/**
* Represents an event that occurs in an {@link Arena}.
*/
public interface ArenaEvent {
public interface ArenaEvent extends Resolvable {

/**
* Gets the {@link Arena} this event is occurring in.
Expand Down Expand Up @@ -36,4 +40,11 @@ default EventTrigger getEventTrigger() {

return null;
}

default Resolver resolve() {
return Resolver.builder()
.define(ResolverKeys.ARENA, ResolverProvider.simple(this.getArena(), Arena::getName))
.define(ResolverKeys.COMPETITION, ResolverProvider.simple(this.getCompetition(), c -> c.getMap().getName()))
.build();
}
}
Loading

0 comments on commit d6d9127

Please sign in to comment.