From 8c5939ec1c9366358f1c346b0218bd8fe014f8aa Mon Sep 17 00:00:00 2001 From: Stefatorus Date: Wed, 2 Dec 2020 20:21:46 +0200 Subject: [PATCH] Fixed simpleslime with magmacubes + temp patch for redstone lever spam --- plugin.yml | 2 +- server.yml | 13 +++++ .../LagAssist/microfeatures/MicroManager.java | 52 ++++++++++++++++++- src/cx/sfy/LagAssist/mobs/SmartMob.java | 4 +- 4 files changed, 67 insertions(+), 4 deletions(-) diff --git a/plugin.yml b/plugin.yml index 7347c64..3d81996 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: LagAssist author: Stefatorus -version: 2.23.2 +version: 2.23.3 api-version: 1.13 description: LagAssist is an advanced anti-lag solution that allows server owners find and remove lag using multiple advanced and efficient methods. main: cx.sfy.LagAssist.Main diff --git a/server.yml b/server.yml index 21969b6..8ca0231 100644 --- a/server.yml +++ b/server.yml @@ -154,6 +154,19 @@ microfeatures: # Two versions (flattening and pre) - "MELON_BLOCK" - "MELON" + # Fixes issue with redstone item spam causing lag on the server. + # https://rz.al/u/5591.png + click-spam-fix: + enable: false + # Blocks that will increase the counter/ + blocks: + - "LEVER" + counter: + message: "&cStop interacting with this block so fast." + # How much to increment each interact? + increment: 20 + # Max value before showing the message + max: 80 # Laggy Chunk detection. You can fiddle around and find the best settings for your diff --git a/src/cx/sfy/LagAssist/microfeatures/MicroManager.java b/src/cx/sfy/LagAssist/microfeatures/MicroManager.java index 69e1af1..199ca18 100644 --- a/src/cx/sfy/LagAssist/microfeatures/MicroManager.java +++ b/src/cx/sfy/LagAssist/microfeatures/MicroManager.java @@ -3,16 +3,21 @@ package cx.sfy.LagAssist.microfeatures; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; +import java.util.WeakHashMap; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockGrowEvent; +import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.material.MaterialData; import org.bukkit.material.PistonBaseMaterial; @@ -36,9 +41,13 @@ public class MicroManager implements Listener { for (BlockState b : breakables) { b.getBlock().breakNaturally(); } - + breakables.clear(); + for(Player p : intervals.keySet()) { + intervals.compute(p, (key, value) -> value - 5 < 0 ? null : value-5); + } + }, 5, 5); } @@ -89,4 +98,45 @@ public class MicroManager implements Listener { } + private static Map intervals = new WeakHashMap<>(); + + @EventHandler(priority = EventPriority.HIGHEST) + public void onRightClick(PlayerInteractEvent e) { + if (!Main.config.getBoolean("microfeatures.click-spam-fix.enable")) { + return; + } + + if (e.isCancelled()) { + return; + } + + Block b = e.getClickedBlock(); + + if (b == null) { + return; + } + + Material mat = b.getType(); + + if (!Main.config.getStringList("microfeatures.click-spam-fix.blocks").contains(mat.toString())) { + return; + } + + Player p = e.getPlayer(); + + int increment = Main.config.getInt("microfeatures.click-spam-fix.counter.increment"); + + int result = intervals.getOrDefault(p, 0); + + if (result > Main.config.getInt("microfeatures.click-spam-fix.counter.max")) { + e.setCancelled(true); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', Main.config.getString("microfeatures.click-spam-fix.counter.message"))); + return; + } + + intervals.compute(p, (key, counter) -> (counter == null ? increment : counter+increment)); +// +// System.out.println(increment + " " + result); + } + } diff --git a/src/cx/sfy/LagAssist/mobs/SmartMob.java b/src/cx/sfy/LagAssist/mobs/SmartMob.java index aa1d016..b2f1cf9 100644 --- a/src/cx/sfy/LagAssist/mobs/SmartMob.java +++ b/src/cx/sfy/LagAssist/mobs/SmartMob.java @@ -91,7 +91,7 @@ public class SmartMob implements Listener { @EventHandler(priority = EventPriority.LOWEST) public void DeathListener(EntityDeathEvent e) { Entity ent = e.getEntity(); - if (simpleslime && ent instanceof Slime) { + if (simpleslime && ent.getType() == EntityType.SLIME) { Slime slm = (Slime) ent; e.getDrops().clear(); @@ -127,7 +127,7 @@ public class SmartMob implements Listener { }, 40L); } - if (simpleslime && (reason == SpawnReason.SLIME_SPLIT)) { + if (simpleslime && (reason == SpawnReason.SLIME_SPLIT) && ent.getType() == EntityType.SLIME) { e.setCancelled(true); }