-
Notifications
You must be signed in to change notification settings - Fork 89
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
303 additions
and
92 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
26 changes: 26 additions & 0 deletions
26
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,26 @@ | ||
package tc.oc.pgm.action.replacements; | ||
|
||
import net.kyori.adventure.text.ComponentLike; | ||
import tc.oc.pgm.api.feature.FeatureDefinition; | ||
import tc.oc.pgm.filters.Filterable; | ||
|
||
/** A replacement object provides replacement text in message actions. */ | ||
public interface Replacement extends FeatureDefinition { | ||
/** | ||
* Tests if the replacement can be used with the passed filterable. | ||
* | ||
* @param filterable The filterable to test | ||
* @return Whether the replacement can be used with the passed filterable | ||
*/ | ||
default boolean canUse(Class<? extends Filterable<?>> filterable) { | ||
return true; | ||
} | ||
|
||
/** | ||
* Creates a replacement component tailored to the given filterable. | ||
* | ||
* @param filterable The filterable to use when creating the replacement component | ||
* @return The replacement component | ||
*/ | ||
ComponentLike get(Filterable<?> filterable); | ||
} |
Oops, something went wrong.