-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix code style inconsistencies * Improve dispatching flow and internal encapsulation * Add delegating placeholder sanitizer * Add more efficient implementation for placeholder sanitizer for adventure * Decomposition of functions, support dry kiss principles / noyzys
- Loading branch information
Showing
47 changed files
with
586 additions
and
479 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
42 changes: 42 additions & 0 deletions
42
...on/src/dev/shiza/honey/adventure/placeholder/sanitizer/AdventurePlaceholderSanitizer.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,42 @@ | ||
package dev.shiza.honey.adventure.placeholder.sanitizer; | ||
|
||
import dev.shiza.honey.placeholder.evaluator.PlaceholderEvaluator.EvaluatedPlaceholder; | ||
import dev.shiza.honey.placeholder.sanitizer.PlaceholderSanitizer; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* This class is responsible for placeholder sanitization, which is the process of transforming | ||
* placeholder key from honey's format to match the MiniMessage's format. | ||
*/ | ||
final class AdventurePlaceholderSanitizer implements PlaceholderSanitizer { | ||
|
||
private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("\\{\\{(.*?)}}"); | ||
private static final String MINI_MESSAGE_PLACEHOLDER_FORMAT = "<%s>"; | ||
|
||
AdventurePlaceholderSanitizer() {} | ||
|
||
@Override | ||
public String getSanitizedContent( | ||
final String content, final List<SanitizedPlaceholder> placeholders) { | ||
return processPlaceholders(content, MINI_MESSAGE_PLACEHOLDER_FORMAT); | ||
} | ||
|
||
@Override | ||
public SanitizedPlaceholder getSanitizedPlaceholder(final EvaluatedPlaceholder placeholder) { | ||
final String sanitized = processPlaceholders(placeholder.placeholder().key(), "%s"); | ||
return new SanitizedPlaceholder( | ||
sanitized, placeholder.placeholder().key(), placeholder.evaluatedValue()); | ||
} | ||
|
||
private String processPlaceholders(final String input, final String format) { | ||
final Matcher matcher = PLACEHOLDER_PATTERN.matcher(input); | ||
final StringBuilder result = new StringBuilder(); | ||
while (matcher.find()) { | ||
matcher.appendReplacement(result, format.formatted(matcher.group(1))); | ||
} | ||
matcher.appendTail(result); | ||
return result.toString(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...dev/shiza/honey/adventure/placeholder/sanitizer/AdventurePlaceholderSanitizerFactory.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,16 @@ | ||
package dev.shiza.honey.adventure.placeholder.sanitizer; | ||
|
||
import dev.shiza.honey.placeholder.sanitizer.PlaceholderSanitizer; | ||
|
||
public final class AdventurePlaceholderSanitizerFactory { | ||
|
||
private AdventurePlaceholderSanitizerFactory() {} | ||
|
||
public static PlaceholderSanitizer create() { | ||
return new AdventurePlaceholderSanitizer(); | ||
} | ||
|
||
public static PlaceholderSanitizer createReflective() { | ||
return new AdventureReflectivePlaceholderSanitizer(); | ||
} | ||
} |
Oops, something went wrong.