-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hex color support and papi placeholders support
- Loading branch information
1 parent
86e327e
commit a7b5d93
Showing
3 changed files
with
41 additions
and
8 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
31 changes: 31 additions & 0 deletions
31
src/main/java/me/starchier/inventorykeeper/util/StringUtil.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,31 @@ | ||
package me.starchier.inventorykeeper.util; | ||
|
||
import me.clip.placeholderapi.PlaceholderAPI; | ||
import net.md_5.bungee.api.ChatColor; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class StringUtil { | ||
private static final Pattern hexPattern = Pattern.compile("(#[a-fA-F0-9]{6})"); | ||
|
||
public static String transform(String str) { | ||
try { | ||
Matcher matcher = hexPattern.matcher(str); | ||
while (matcher.find()) { | ||
String hexCode = str.substring(matcher.start(), matcher.end()); | ||
str = str.replace(hexCode, ChatColor.of(hexCode).toString()); | ||
} | ||
} catch (Exception ignored) { | ||
} | ||
return str; | ||
} | ||
|
||
public static String replacePlaceholder(String str, Player player) { | ||
if (PlaceholderAPI.containsPlaceholders(str)) { | ||
return PlaceholderAPI.setPlaceholders(player, str); | ||
} | ||
return str; | ||
} | ||
} |