Skip to content

Commit

Permalink
Allow for resolving players in all event actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Redned235 committed Nov 10, 2024
1 parent 26d6038 commit 408f1d8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.battleplugins.arena.event.arena.ArenaLoseEvent;
import org.battleplugins.arena.event.arena.ArenaVictoryEvent;
import org.battleplugins.arena.event.player.ArenaPlayerEvent;
import org.battleplugins.arena.resolver.Resolver;
import org.battleplugins.arena.util.PolymorphicHashMap;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -169,8 +170,12 @@ private <T extends Event & ArenaEvent> void pollActions(T event, Competition<?>
}

for (ArenaPlayer player : new HashSet<>(players)) {
// Resolve with ArenaPlayer context
Resolver.Builder resolver = player.resolve().toBuilder();
event.resolve().mergeInto(resolver);

try {
action.call(player, event);
action.call(player, resolver.build());
} catch (Throwable e) {
this.arena.getPlugin().warn("An error occurred calling event action {}", action, e);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void postProcess(Arena arena, Competition<?> competition, Resolvable reso
return;
}

String message = this.get(MESSAGE_KEY);
String message = resolvable.resolve().resolveToString(this.get(MESSAGE_KEY));
MessageType messageType = MessageType.valueOf(this.getOrDefault(TYPE_KEY, MessageType.CHAT.name())
.toUpperCase(Locale.ROOT)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.kyori.adventure.text.Component;

public interface Resolver {
public interface Resolver extends Resolvable {

String resolveToString(String string);

Expand All @@ -16,6 +16,11 @@ public interface Resolver {

Builder toBuilder();

@Override
default Resolver resolve() {
return this;
}

static Builder builder() {
return new ResolverImpl.BuilderImpl();
}
Expand Down

0 comments on commit 408f1d8

Please sign in to comment.