-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat,refactor(replacements): add a global replacement registry
Allows for global replacements to be registered on the map level: ```xml <replacements> <switch id="bombsite"> <case filter="filter-a" result="filter-a-result"/> <case filter="filter-b" result="filter-b-result"/> </switch> </replacements> ``` Where required, a global replacement requires a matching scope (in actions, the scope is inherited from the current scope): ```xml <replacements> <switch value="variable" scope="match"> ... <fallback>...</fallback> </switch> </replacements> ``` A globally defined replacement then can be referred to from within as: ```xml <!-- somewhere in <map> --> <replacements> <player id="global-replacement" var="variable" fallback="an unknown player"/> </replacements> <!-- in an action --> <message text="... {replacement}"> <replacements> <replacement id="replacement">global-replacement</replacement> </replacements> </message> ``` To support for this, replacement parsing has been forked out of ActionParser. Signed-off-by: TTtie <[email protected]>
- Loading branch information
Showing
11 changed files
with
430 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
core/src/main/java/tc/oc/pgm/action/replacements/Replacement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package tc.oc.pgm.action.replacements; | ||
|
||
import net.kyori.adventure.text.ComponentLike; | ||
import org.jetbrains.annotations.Nullable; | ||
import tc.oc.pgm.util.Audience; | ||
|
||
/** | ||
* A replacement object provides replacement text in message actions. | ||
* | ||
* @param <S> The scope of the replacement | ||
*/ | ||
public interface Replacement<S extends Audience> { | ||
/** | ||
* Gets the scope of the replacement. May be null if no scope restrictions apply | ||
* | ||
* @return The scope of the replacement | ||
*/ | ||
@Nullable | ||
Class<S> getScope(); | ||
|
||
/** | ||
* Creates a replacement component tailored to the given audience. | ||
* | ||
* @param audience The audience to use when replacing | ||
* @return The replacement component | ||
*/ | ||
ComponentLike replace(S audience); | ||
} |
7 changes: 7 additions & 0 deletions
7
core/src/main/java/tc/oc/pgm/action/replacements/ReplacementDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package tc.oc.pgm.action.replacements; | ||
|
||
import tc.oc.pgm.api.feature.FeatureDefinition; | ||
import tc.oc.pgm.util.Audience; | ||
|
||
public interface ReplacementDefinition<S extends Audience> | ||
extends FeatureDefinition, Replacement<S> {} |
Oops, something went wrong.