Make book byte limits configurable per player permissions
This commit is contained in:
parent
ff9133ecfa
commit
18de5cebd6
|
|
@ -23,7 +23,7 @@ public class BookByteLimitListener implements Listener {
|
|||
|
||||
private boolean isOversizedBook(ItemStack stack) {
|
||||
boolean isOversizedBook = BookByteUtils.shouldCountForBookByteLimit(stack)
|
||||
&& BookByteUtils.computeBytes(stack) > BookByteUtils.MAX_BOOK_BYTES;
|
||||
&& BookByteUtils.computeBytes(stack) > BookByteUtils.getMAX_BOOK_BYTES();
|
||||
if (isOversizedBook) {
|
||||
log.warn("Player tried to drop an oversized book");
|
||||
Component message = MiniMessage.miniMessage().deserialize(
|
||||
|
|
@ -35,7 +35,7 @@ public class BookByteLimitListener implements Listener {
|
|||
|
||||
private boolean isOversizedBook(ItemStack stack, HumanEntity humanEntity) {
|
||||
boolean isOversizedBook = BookByteUtils.shouldCountForBookByteLimit(stack)
|
||||
&& BookByteUtils.computeBytes(stack) > BookByteUtils.MAX_BOOK_BYTES;
|
||||
&& BookByteUtils.computeBytes(stack) > BookByteUtils.getMaxBookBytes(humanEntity);
|
||||
if (isOversizedBook) {
|
||||
log.warn("{} [{}] tried to drop an oversized book", humanEntity.getName(), humanEntity.getUniqueId());
|
||||
Component message = MiniMessage.miniMessage().deserialize(
|
||||
|
|
@ -96,7 +96,9 @@ public class BookByteLimitListener implements Listener {
|
|||
|
||||
@EventHandler
|
||||
public void onInventoryMoveItem(InventoryMoveItemEvent event) {
|
||||
if (isOversizedBook(event.getItem())) {
|
||||
if (event.getSource().getHolder() instanceof HumanEntity humanEntity && isOversizedBook(event.getItem(), humanEntity)) {
|
||||
event.setCancelled(true);
|
||||
} else if (isOversizedBook(event.getItem())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class BookWriteEvent implements Listener {
|
|||
|
||||
int totalBytes = BookByteUtils.computeBytes(meta);
|
||||
|
||||
if (totalBytes > BookByteUtils.MAX_BOOK_BYTES) {
|
||||
if (totalBytes > BookByteUtils.getMaxBookBytes(player)) {
|
||||
log.warn("Player {} [{}] tried to write a book with {} bytes",
|
||||
player.getName(), player.getUniqueId(), totalBytes);
|
||||
event.setCancelled(true);
|
||||
|
|
@ -31,7 +31,7 @@ public class BookWriteEvent implements Listener {
|
|||
"<red>Player <player> tried to write a book with <bytes> bytes</red>",
|
||||
Placeholder.unparsed("player", player.getName()), Placeholder.parsed("bytes", String.valueOf(totalBytes)));
|
||||
Bukkit.broadcast(message, "staffutils.patrol");
|
||||
} else if (totalBytes > BookByteUtils.BIG_BOOK_BYTES) {
|
||||
} else if (totalBytes > BookByteUtils.getBigBookBytes(player)) {
|
||||
log.warn("Player {} [{}] wrote a large book with {} bytes",
|
||||
player.getName(), player.getUniqueId(), totalBytes);
|
||||
Component message = MiniMessage.miniMessage().deserialize(
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
package com.alttd.playerutils.util;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.ShulkerBox;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||
|
|
@ -19,8 +22,30 @@ public final class BookByteUtils {
|
|||
}
|
||||
|
||||
// 65,000 bytes per book (below CoreProtect hard limit ~65,535)
|
||||
public static final int MAX_BOOK_BYTES = 30_000;
|
||||
public static final int BIG_BOOK_BYTES = 10_000;
|
||||
@Getter
|
||||
private static final int MAX_BOOK_BYTES = 30_000;
|
||||
@Getter
|
||||
private static final int BIG_BOOK_BYTES = 10_000;
|
||||
|
||||
public static int getBigBookBytes(HumanEntity humanEntity) {
|
||||
return calcBookBytes(humanEntity, BIG_BOOK_BYTES);
|
||||
}
|
||||
|
||||
public static int getMaxBookBytes(HumanEntity humanEntity) {
|
||||
return calcBookBytes(humanEntity, MAX_BOOK_BYTES);
|
||||
}
|
||||
|
||||
private static int calcBookBytes(HumanEntity humanEntity, int bookBytes) {
|
||||
if (humanEntity.hasPermission("playerutils.bigbook.bypass")) {
|
||||
return Integer.MAX_VALUE;
|
||||
} else if (humanEntity.hasPermission("playerutils.bigbook.double")) {
|
||||
return bookBytes * 2;
|
||||
} else if (humanEntity.hasPermission("playerutils.bigbook.quadruple")) {
|
||||
return bookBytes * 4;
|
||||
} else {
|
||||
return bookBytes;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean shouldCountForBookByteLimit(ItemStack stack) {
|
||||
if (stack == null) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user