Improved inventory whitelist check & prepare for better MiniMessage support
This commit is contained in:
parent
41d04c7604
commit
3e56aacb4e
4
pom.xml
4
pom.xml
@ -835,10 +835,6 @@
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>bungeecord-chat</artifactId>
|
||||
<groupId>net.md-5</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- Keep in sync with spigot 1.19 -->
|
||||
|
||||
@ -495,8 +495,20 @@ public class PlayerListener implements Listener {
|
||||
return false;
|
||||
}
|
||||
Set<String> whitelist = settings.getProperty(RestrictionSettings.UNRESTRICTED_INVENTORIES);
|
||||
if (whitelist.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
//append a string for String whitelist
|
||||
return whitelist.contains(ChatColor.stripColor(inventory.getTitle()).toLowerCase(Locale.ROOT));
|
||||
String invName = ChatColor.stripColor(inventory.getTitle()).toLowerCase(Locale.ROOT);
|
||||
if (settings.getProperty(RestrictionSettings.STRICT_UNRESTRICTED_INVENTORIES_CHECK)) {
|
||||
return whitelist.contains(invName);
|
||||
}
|
||||
for (String wl : whitelist) {
|
||||
if (invName.contains(wl)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
|
||||
@ -205,6 +205,10 @@ public final class RestrictionSettings implements SettingsHolder {
|
||||
public static final Property<Set<String>> UNRESTRICTED_INVENTORIES =
|
||||
newLowercaseStringSetProperty("settings.unrestrictions.UnrestrictedInventories");
|
||||
|
||||
@Comment("Should we check unrestricted inventories strictly? (Original behavior)")
|
||||
public static final Property<Boolean> STRICT_UNRESTRICTED_INVENTORIES_CHECK =
|
||||
newProperty("settings.unrestrictions.StrictUnrestrictedInventoriesCheck", true);
|
||||
|
||||
|
||||
private RestrictionSettings() {
|
||||
|
||||
|
||||
@ -2,7 +2,9 @@ package fr.xephi.authme.util.message;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
public class MiniMessageUtils {
|
||||
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
@ -18,6 +20,17 @@ public class MiniMessageUtils {
|
||||
return LegacyComponentSerializer.legacyAmpersand().serialize(component);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a MiniMessage string into a BaseComponent.
|
||||
*
|
||||
* @param message The message to parse.
|
||||
* @return The parsed message.
|
||||
*/
|
||||
public static BaseComponent[] parseMiniMessageToBaseComponent(String message) {
|
||||
Component component = miniMessage.deserialize(message);
|
||||
return BungeeComponentSerializer.legacy().serialize(component);
|
||||
}
|
||||
|
||||
private MiniMessageUtils() {
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user