Need to improve rate limit logic
This commit is contained in:
@@ -17,11 +17,11 @@ public class NBTConfig implements JsonSerializable<NBTConfig> {
|
||||
public RateLimit rateLimit = new RateLimit();
|
||||
|
||||
public class RateLimit {
|
||||
public int rateLimitBytes = 16348;
|
||||
public int byteDecay = 1024;
|
||||
public int rateLimitBytes = 16348;
|
||||
public int byteDecay = 1024; // Every Minute
|
||||
public int rateLimitItems = 10;
|
||||
public int itemDecay = 2;
|
||||
public List<String> punishmentCommands = List.of("kick %player% Internal Exception: io.netty.handler.codec.DecoderException: java.lang.RuntimeException: Tried to read NBT tag that was too big; tried to allocate 28391038bytes where max allowed: 16348");
|
||||
public int itemDecay = 5; // Every 10 seconds
|
||||
public List<String> punishmentCommands = List.of("kick %player% Internal Exception: io.netty.handler.codec.DecoderException: java.lang.RuntimeException: Tried to read NBT tag that was too big; tried to allocate %s bytes where max allowed: %s");
|
||||
}
|
||||
|
||||
public boolean allowName = true;
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.bukkit.event.inventory.InventoryCreativeEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CreativeHotbar extends AbstractViolation {
|
||||
@@ -42,6 +43,11 @@ public class CreativeHotbar extends AbstractViolation {
|
||||
//ServerUtils.verbose("NBT: Cursor has meta");
|
||||
if (!(i.hasItemMeta() && i.getItemMeta() != null)) return;
|
||||
if (!new RateLimitCheck().passes(new Pair<>(p,i))) {
|
||||
List<String> punishmentCommands = new ArrayList<>();
|
||||
for (String punishmentCommand : Sentinel.getInstance().getDirector().io.nbtConfig.rateLimit.punishmentCommands) {
|
||||
punishmentCommands.add(punishmentCommand.formatted());
|
||||
}
|
||||
|
||||
ServerUtils.verbose("Player flags rate limit, performing action");
|
||||
ActionConfiguration.Builder config = new ActionConfiguration.Builder()
|
||||
.setEvent(e)
|
||||
@@ -49,8 +55,8 @@ public class CreativeHotbar extends AbstractViolation {
|
||||
.cancel(true)
|
||||
.punish(true)
|
||||
.deop(Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.deop)
|
||||
.setPunishmentCommands(Sentinel.getInstance().getDirector().io.nbtConfig.rateLimit.punishmentCommands);
|
||||
|
||||
.setPunishmentCommands();
|
||||
|
||||
runActions(
|
||||
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.grab, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.nbtItem),
|
||||
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.grab, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.nbtItem),
|
||||
|
||||
@@ -14,9 +14,32 @@ import org.bukkit.inventory.meta.BlockStateMeta;
|
||||
import org.bukkit.inventory.meta.BundleMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemCheck extends AbstractCheck<ItemStack> {
|
||||
|
||||
public List<AbstractCheck<ItemStack>> checks;
|
||||
|
||||
public ItemCheck() {
|
||||
enchantmentCheck = new EnchantmentCheck();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passes(ItemStack item) {
|
||||
try {
|
||||
return scan(item);
|
||||
} catch (Exception ex) {
|
||||
Sentinel.getInstance().getLogger().warning("Caught an exception while handling an item check: " + Arrays.toString(ex.getStackTrace()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checksPass(ItemStack item) {
|
||||
|
||||
}
|
||||
|
||||
private boolean scan(ItemStack item) {
|
||||
ServerUtils.verbose("Checking item: " + item.getType().name());
|
||||
NBTConfig config = Sentinel.getInstance().getDirector().io.nbtConfig;
|
||||
|
||||
@@ -188,8 +211,8 @@ public class ItemCheck extends AbstractCheck<ItemStack> {
|
||||
ServerUtils.verbose("Item passed all checks.");
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isSpawnEgg(ItemStack item) {
|
||||
|
||||
private boolean isSpawnEgg(ItemStack item) {
|
||||
return item.getType().name().toLowerCase().contains("spawn_egg");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ public final class Loader {
|
||||
Bukkit.getScheduler().runTaskTimer(Sentinel.getInstance(), SpamFilter::decayHeat,0, 20);
|
||||
Bukkit.getScheduler().runTaskTimer(Sentinel.getInstance(), ProfanityFilter::decayScore,0,1200);
|
||||
Bukkit.getScheduler().runTaskTimer(Sentinel.getInstance(), WandEvents::handleDisplay,0,1);
|
||||
Bukkit.getScheduler().runTaskTimer(Sentinel.getInstance(), RateLimitCheck::decayData,0,20*60);
|
||||
Bukkit.getScheduler().runTaskTimer(Sentinel.getInstance(), RateLimitCheck::decayData,0,1200);
|
||||
Bukkit.getScheduler().runTaskTimer(Sentinel.getInstance(), RateLimitCheck::decayItems,0,200);
|
||||
|
||||
if (Sentinel.getInstance().getDirector().io.mainConfig.backdoorDetection.enabled) Sentinel.getInstance().getDirector().backdoorDetection.init();
|
||||
|
||||
Reference in New Issue
Block a user