mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-01-26 01:21:27 +01:00
Implements whitelist for inventories interactions (#1657)
This commit is contained in:
parent
1d6729425f
commit
0b0e8d71b7
@ -53,6 +53,7 @@ import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerShearEntityEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.HashSet;
|
||||
@ -411,11 +412,20 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isInventoryWhitelisted(Inventory inventory) {
|
||||
if (inventory == null) {
|
||||
return false;
|
||||
}
|
||||
Set<String> whitelist = settings.getProperty(RestrictionSettings.UNRESTRICTED_INVENTORIES);
|
||||
return whitelist.contains(ChatColor.stripColor(inventory.getName()));
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onPlayerInventoryOpen(InventoryOpenEvent event) {
|
||||
final HumanEntity player = event.getPlayer();
|
||||
|
||||
if (listenerService.shouldCancelEvent(player)) {
|
||||
if (listenerService.shouldCancelEvent(player)
|
||||
&& !isInventoryWhitelisted(event.getInventory())) {
|
||||
event.setCancelled(true);
|
||||
|
||||
/*
|
||||
@ -428,7 +438,8 @@ public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onPlayerInventoryClick(InventoryClickEvent event) {
|
||||
if (listenerService.shouldCancelEvent(event.getWhoClicked())) {
|
||||
if (listenerService.shouldCancelEvent(event.getWhoClicked())
|
||||
&& !isInventoryWhitelisted(event.getClickedInventory())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -181,6 +181,18 @@ public final class RestrictionSettings implements SettingsHolder {
|
||||
public static final Property<Set<String>> UNRESTRICTED_NAMES =
|
||||
newLowercaseStringSetProperty("settings.unrestrictions.UnrestrictedName");
|
||||
|
||||
@Comment({
|
||||
"Below you can list all inventories names that AuthMe will ignore",
|
||||
"for registration or login. Configure it at your own risk!!",
|
||||
"This option adds compatibility with some mods.",
|
||||
"It is case-insensitive! Example:",
|
||||
"UnrestrictedInventories:",
|
||||
"- 'myCustomInventory1'",
|
||||
"- 'myCustomInventory2'"
|
||||
})
|
||||
public static final Property<Set<String>> UNRESTRICTED_INVENTORIES =
|
||||
newLowercaseStringSetProperty("settings.unrestrictions.UnrestrictedInventories");
|
||||
|
||||
private RestrictionSettings() {
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user