|
@ -3,16 +3,21 @@ package cx.sfy.LagAssist.microfeatures; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.Arrays; |
|
|
import java.util.Arrays; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
import java.util.WeakHashMap; |
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit; |
|
|
import org.bukkit.Bukkit; |
|
|
|
|
|
import org.bukkit.ChatColor; |
|
|
import org.bukkit.Material; |
|
|
import org.bukkit.Material; |
|
|
import org.bukkit.block.Block; |
|
|
import org.bukkit.block.Block; |
|
|
import org.bukkit.block.BlockFace; |
|
|
import org.bukkit.block.BlockFace; |
|
|
import org.bukkit.block.BlockState; |
|
|
import org.bukkit.block.BlockState; |
|
|
|
|
|
import org.bukkit.entity.Player; |
|
|
import org.bukkit.event.EventHandler; |
|
|
import org.bukkit.event.EventHandler; |
|
|
import org.bukkit.event.EventPriority; |
|
|
import org.bukkit.event.EventPriority; |
|
|
import org.bukkit.event.Listener; |
|
|
import org.bukkit.event.Listener; |
|
|
import org.bukkit.event.block.BlockGrowEvent; |
|
|
import org.bukkit.event.block.BlockGrowEvent; |
|
|
|
|
|
import org.bukkit.event.player.PlayerInteractEvent; |
|
|
import org.bukkit.material.MaterialData; |
|
|
import org.bukkit.material.MaterialData; |
|
|
import org.bukkit.material.PistonBaseMaterial; |
|
|
import org.bukkit.material.PistonBaseMaterial; |
|
|
|
|
|
|
|
@ -36,9 +41,13 @@ public class MicroManager implements Listener { |
|
|
for (BlockState b : breakables) { |
|
|
for (BlockState b : breakables) { |
|
|
b.getBlock().breakNaturally(); |
|
|
b.getBlock().breakNaturally(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
breakables.clear(); |
|
|
breakables.clear(); |
|
|
|
|
|
|
|
|
|
|
|
for(Player p : intervals.keySet()) { |
|
|
|
|
|
intervals.compute(p, (key, value) -> value - 5 < 0 ? null : value-5); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
}, 5, 5); |
|
|
}, 5, 5); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -89,4 +98,45 @@ public class MicroManager implements Listener { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static Map<Player, Integer> 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);
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|