-
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
8 changed files
with
358 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
27 changes: 27 additions & 0 deletions
27
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,27 @@ | ||
package tc.oc.pgm.action.replacements; | ||
|
||
import net.kyori.adventure.text.ComponentLike; | ||
import tc.oc.pgm.api.feature.FeatureDefinition; | ||
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> extends FeatureDefinition { | ||
/** | ||
* Gets the scope of the replacement. | ||
* | ||
* @return The scope of the replacement | ||
*/ | ||
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); | ||
} |
Oops, something went wrong.