Skip to content

Commit

Permalink
1.4, adding a shit ton of features, Bow bomb, ability to disable link…
Browse files Browse the repository at this point in the history
…s, and some other lag stuff.
  • Loading branch information
KRYMZ0N committed Nov 2, 2021
1 parent 11f747d commit 9f06428
Show file tree
Hide file tree
Showing 12 changed files with 389 additions and 65 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.krymz0n</groupId>
<artifactId>SimpleExploitFixer</artifactId>
<version>1.2</version>
<version>1.4</version>
<packaging>jar</packaging>

<name>SimpleExploitFixer</name>
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/me/krymz0n/simpleexploitfixer/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import me.krymz0n.simpleexploitfixer.commands.Reload;
import me.krymz0n.simpleexploitfixer.listener.*;
import me.krymz0n.simpleexploitfixer.listener.ArmorStand;
import me.krymz0n.simpleexploitfixer.util.ItemUtil;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Material;
Expand All @@ -25,6 +27,11 @@ public void onEnable() {
pm.registerEvents(new ChunkBan(this), this);
pm.registerEvents(new WitherSkulls(this), this);
pm.registerEvents(new InteractEvent(this), this);
pm.registerEvents(new ArmorStand(this), this);
pm.registerEvents(new RedstoneLag(this), this);
pm.registerEvents(new Rail(this), this);
pm.registerEvents(new Chat(this), this);
pm.registerEvents(new TabComplete(this), this);

Objects.requireNonNull(getCommand("sef")).setExecutor(new Reload(this));

Expand Down Expand Up @@ -58,6 +65,46 @@ public void onEnable() {

}

if (getConfig().getBoolean("PreventTooManyEntitiesInChunk")) {
Bukkit.getScheduler().runTaskTimer(this, () -> {
for (World w : Bukkit.getWorlds()) {
for (Chunk c : w.getLoadedChunks()) {
int count = 0;
for (Entity entity : c.getEntities()) {
if (ItemUtil.isEntity(entity) && !(entity instanceof LivingEntity)) {
if (count > getConfig().getInt("MaxEntitiesInChunk")) {
entity.remove();
if (getConfig().getBoolean("LogEntityRemovals")) {
getLogger().warning("Removed entity " + entity.getType() + " at " + entity.getLocation() + " because reached entity limit of " + getConfig().getInt("MaxEntitiesInChunk"));
}
}
count++;
}
}
}
}
}, 0L, getConfig().getInt("EntityCheckTimeTicks"));
}

if (getConfig().getBoolean("StrictArmorStandCheck")) {
Bukkit.getScheduler().runTaskTimer(this, () -> {
for (World w : Bukkit.getWorlds()) {
for (Chunk c : w.getLoadedChunks()) {
int count = 0;
for (Entity entity : c.getEntities()) {
if (entity instanceof ArmorStand) {
if (count > getConfig().getInt("MaxArmorStandPerChunk")) {
entity.remove();
}
count++;
}
}
}
}
}, 0L, 200L);

}

if (getConfig().getBoolean("PreventChunkBan")) {
Bukkit.getScheduler().runTaskTimer(this, () -> {
for (World w : Bukkit.getWorlds()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package me.krymz0n.simpleexploitfixer.listener;

import me.krymz0n.simpleexploitfixer.Main;
import org.bukkit.Chunk;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkLoadEvent;

import java.util.ArrayList;

public class ArmorStand implements Listener {
private final Main plugin;

public ArmorStand(Main plugin) {
this.plugin = plugin;
}

@EventHandler
public void onChunkLoad(ChunkLoadEvent evt) {
Chunk c = evt.getChunk();
if (!evt.isNewChunk()) {
ArrayList<Entity> entities = new ArrayList<>();
for (Entity entity : c.getEntities()) {
if (entity.getType().equals(EntityType.ARMOR_STAND) && (!(entity.getType() == null))) {
entities.add(entity);
for (int i = plugin.getConfig().getInt("MaxArmorStandPerChunk"); i < entities.size(); i++) {
entity.remove();
}
}
}
}
}
}
26 changes: 26 additions & 0 deletions src/main/java/me/krymz0n/simpleexploitfixer/listener/BowBomb.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package me.krymz0n.simpleexploitfixer.listener;

import me.krymz0n.simpleexploitfixer.Main;
import org.bukkit.entity.Arrow;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ProjectileLaunchEvent;

public class BowBomb implements Listener {
private final Main plugin;

public BowBomb(Main plugin) {
this.plugin = plugin;
}

@EventHandler
public void onArrow(ProjectileLaunchEvent evt) {
if (plugin.getConfig().getBoolean("PreventBowBombExploit")) {
if (evt.getEntity() instanceof Arrow) {
if (evt.getEntity().getVelocity().lengthSquared() > plugin.getConfig().getInt("MaxBowSquaredVelocity")) {
evt.setCancelled(true);
}
}
}
}
}
36 changes: 36 additions & 0 deletions src/main/java/me/krymz0n/simpleexploitfixer/listener/Chat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package me.krymz0n.simpleexploitfixer.listener;

import io.papermc.paper.event.player.AsyncChatEvent;
import me.krymz0n.simpleexploitfixer.Main;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Chat implements Listener {
private static final Pattern httpRegexCheck =
Pattern.compile("(https?://(?:www\\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\\.[^\\s]{2,}|www\\.[a-zA-Z0-9]" +
"[a-zA-Z0-9-]+[a-zA-Z0-9]\\.[^\\s]{2,}|https?://(?:www\\.|(?!www))[a-zA-Z0-9]+\\.[^\\s]{2,}|www\\.[a-zA-Z0-9]+\\.[^\\s]{2,})", Pattern.CASE_INSENSITIVE);
private final Main plugin;

public Chat(Main plugin) {
this.plugin = plugin;
}

@EventHandler
private void onChat(AsyncPlayerChatEvent evt) {
Player p = evt.getPlayer();
if (link(evt.getMessage())) {
evt.setCancelled(true);
}
}

public static boolean link(String s) {
Matcher matcher = httpRegexCheck.matcher(s);
return matcher.find();
}
}

141 changes: 80 additions & 61 deletions src/main/java/me/krymz0n/simpleexploitfixer/listener/ChunkBan.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ public void onBlockPlace(BlockPlaceEvent evt) {
}
break;
}
case ARMOR_STAND: {
if ((bl.getType().equals(Material.ARMOR_STAND)) && plugin.count(ch, bl.getType()) > plugin.getConfig().getInt("MaxArmorStandPerChunk")) {
evt.setCancelled(true);
Audience.audience(p).sendActionBar(Component.text(message));
}
break;
}
default: {
if (bl.getState() instanceof Container) {
if (plugin.count(ch, bl.getType()) > plugin.getConfig().getInt("MaxContainerPerChunk")) {
Expand All @@ -92,80 +99,92 @@ public void onBlockPlace(BlockPlaceEvent evt) {

@EventHandler
public void onChunkLoad(ChunkLoadEvent evt) {
if (plugin.getConfig().getBoolean("RemoveChunkBansOnChunkLoad") && !evt.isNewChunk()) {
Chunk ch = evt.getChunk();
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
for (int y = 0; y < 256; y++) {
Block bl = evt.getChunk().getBlock(x, y, z);
switch (bl.getType()) {
case ENCHANTING_TABLE: {
if (plugin.getConfig().getBoolean("RemoveEnchantingTablesOnChunkLoad") && evt.getChunk().getBlock(x, y, z).getType().equals(Material.ENCHANTING_TABLE)) {
if (plugin.count(ch, Material.ENCHANTING_TABLE) > plugin.getConfig().getInt("MaxEnchantingTablePerChunk")) {
ch.getBlock(x, y, z).setType(Material.AIR);
if (plugin.getConfig().getBoolean("RemoveChunkBansOnChunkLoad")) {
if (!evt.isNewChunk()) {
new Thread(() -> {
Chunk ch = evt.getChunk();
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
for (int y = 0; y < 256; y++) {
Block bl = evt.getChunk().getBlock(x, y, z);
switch (bl.getType()) {
case ENCHANTING_TABLE: {
if (plugin.getConfig().getBoolean("RemoveEnchantingTablesOnChunkLoad") && evt.getChunk().getBlock(x, y, z).getType().equals(Material.ENCHANTING_TABLE)) {
if (plugin.count(ch, Material.ENCHANTING_TABLE) > plugin.getConfig().getInt("MaxEnchantingTablePerChunk")) {
ch.getBlock(x, y, z).setType(Material.AIR);
}
}
break;
}
}
break;
}
case ENDER_CHEST: {
if (plugin.getConfig().getBoolean("RemoveEnderChestsOnChunkLoad") && evt.getChunk().getBlock(x, y, z).getType().equals(Material.ENDER_CHEST)) {
if (plugin.count(ch, Material.ENDER_CHEST) > plugin.getConfig().getInt("MaxEnderchestPerChunk")) {
ch.getBlock(x, y, z).setType(Material.AIR);
case ENDER_CHEST: {
if (plugin.getConfig().getBoolean("RemoveEnderChestsOnChunkLoad") && evt.getChunk().getBlock(x, y, z).getType().equals(Material.ENDER_CHEST)) {
if (plugin.count(ch, Material.ENDER_CHEST) > plugin.getConfig().getInt("MaxEnderchestPerChunk")) {
ch.getBlock(x, y, z).setType(Material.AIR);
}
}
break;
}
}
break;
}
case HOPPER: {
if (plugin.getConfig().getBoolean("RemoveHoppersOnChunkLoad") && evt.getChunk().getBlock(x, y, z).getType().equals(Material.HOPPER)) {
if (plugin.count(ch, Material.HOPPER) > plugin.getConfig().getInt("MaxHopperPerChunk")) {
ch.getBlock(x, y, z).setType(Material.AIR);
case HOPPER: {
if (plugin.getConfig().getBoolean("RemoveHoppersOnChunkLoad") && evt.getChunk().getBlock(x, y, z).getType().equals(Material.HOPPER)) {
if (plugin.count(ch, Material.HOPPER) > plugin.getConfig().getInt("MaxHopperPerChunk")) {
ch.getBlock(x, y, z).setType(Material.AIR);
}
}
break;
}
}
break;
}
case SLIME_BLOCK: {
if (plugin.getConfig().getBoolean("RemoveSlimeBlocksOnChunkLoad") && evt.getChunk().getBlock(x, y, z).getType().equals(Material.SLIME_BLOCK)) {
if (plugin.count(ch, bl.getType()) > plugin.getConfig().getInt("MaxSlimePerChunk")) {
ch.getBlock(x, y, z).setType(Material.AIR);
case SLIME_BLOCK: {
if (plugin.getConfig().getBoolean("RemoveSlimeBlocksOnChunkLoad") && evt.getChunk().getBlock(x, y, z).getType().equals(Material.SLIME_BLOCK)) {
if (plugin.count(ch, bl.getType()) > plugin.getConfig().getInt("MaxSlimePerChunk")) {
ch.getBlock(x, y, z).setType(Material.AIR);
}
}
break;
}
}
break;
}
case BEACON: {
if (plugin.getConfig().getBoolean("RemoveBeaconsOnChunkLoad") && evt.getChunk().getBlock(x, y, z).getType().equals(Material.BEACON)) {
if (plugin.count(ch, bl.getType()) > plugin.getConfig().getInt("MaxBeaconPerChunk")) {
ch.getBlock(x, y, z).setType(Material.AIR);
case BEACON: {
if (plugin.getConfig().getBoolean("RemoveBeaconsOnChunkLoad") && evt.getChunk().getBlock(x, y, z).getType().equals(Material.BEACON)) {
if (plugin.count(ch, bl.getType()) > plugin.getConfig().getInt("MaxBeaconPerChunk")) {
ch.getBlock(x, y, z).setType(Material.AIR);
}
}
break;
}
}
break;
}
case GLOWSTONE: {
if (plugin.getConfig().getBoolean("RemoveGlowStoneOnChunkLoad") && evt.getChunk().getBlock(x, y, z).getType().equals(Material.GLOWSTONE)) {
if ((bl.getType().equals(Material.GLOWSTONE)) && plugin.count(ch, bl.getType()) > plugin.getConfig().getInt("MaxGlowstonePerChunk")) {
ch.getBlock(x, y, z).setType(Material.AIR);
case GLOWSTONE: {
if (plugin.getConfig().getBoolean("RemoveGlowStoneOnChunkLoad") && evt.getChunk().getBlock(x, y, z).getType().equals(Material.GLOWSTONE)) {
if ((bl.getType().equals(Material.GLOWSTONE)) && plugin.count(ch, bl.getType()) > plugin.getConfig().getInt("MaxGlowstonePerChunk")) {
ch.getBlock(x, y, z).setType(Material.AIR);
}
}
break;
}
}
break;
}
case LECTERN:
if (plugin.getConfig().getBoolean("RemoveLecternOnChunkLoad") && evt.getChunk().getBlock(x, y, z).getType().equals(Material.LECTERN)) {
if ((bl.getType().equals(Material.LECTERN)) && plugin.count(ch, bl.getType()) > plugin.getConfig().getInt("MaxLecternPerChunk")) {
ch.getBlock(x, y, z).setType(Material.AIR);
case LECTERN:
if (plugin.getConfig().getBoolean("RemoveLecternOnChunkLoad") && evt.getChunk().getBlock(x, y, z).getType().equals(Material.LECTERN)) {
if ((bl.getType().equals(Material.LECTERN)) && plugin.count(ch, bl.getType()) > plugin.getConfig().getInt("MaxLecternPerChunk")) {
ch.getBlock(x, y, z).setType(Material.AIR);
}
}
case ARMOR_STAND: {
if (plugin.getConfig().getBoolean("RemoveArmorStandOnChunkLoad")) {
if ((bl.getType().equals(Material.ARMOR_STAND)) && plugin.count(ch, bl.getType()) > plugin.getConfig().getInt("MaxArmorStandPerChunk")) {
ch.getBlock(x, y, z).setType(Material.AIR);
}
}
break;
}
}
default: {
if (plugin.getConfig().getBoolean("RemoveContainersOnChunkLoad")) {
if (bl.getState() instanceof Container) {
if (plugin.count(ch, bl.getType()) > plugin.getConfig().getInt("MaxContainerPerChunk")) {
ch.getBlock(x, y, z).setType(Material.AIR);
default: {
if (plugin.getConfig().getBoolean("RemoveContainersOnChunkLoad")) {
if (bl.getState() instanceof Container) {
if (plugin.count(ch, bl.getType()) > plugin.getConfig().getInt("MaxContainerPerChunk")) {
ch.getBlock(x, y, z).setType(Material.AIR);
}
}
}
break;
}
}
break;
}
}
}
}
}).start();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ public void onInteract(PlayerInteractEvent evt) {
if (plugin.getConfig().getBoolean("DisableRespawnAnchorExplosions")) {
Player p = evt.getPlayer();
if (evt.getAction() == Action.RIGHT_CLICK_BLOCK) {
System.out.println("Right click");
Block block = evt.getClickedBlock();
assert block != null;
if (block.getType().equals(Material.RESPAWN_ANCHOR)) {
System.out.println("anchor");
final RespawnAnchor ra = (RespawnAnchor) block.getBlockData();
if (evt.getMaterial().equals(Material.GLOWSTONE) && ra.getCharges() >= ra.getMaximumCharges() && !p.getWorld().getEnvironment().equals(World.Environment.NETHER)) {
if (evt.getMaterial().equals(Material.GLOWSTONE) && ra.getCharges() >= ra.getMaximumCharges() || !evt.getMaterial().equals(Material.GLOWSTONE) && ra.getCharges() > 0 && !p.getWorld().getEnvironment().equals(World.Environment.NETHER)) {
evt.setCancelled(true);
Audience.audience(p).sendActionBar(Component.text(ChatColor.RED + "Due to a poll in the discord, respawn anchor explosions have been disabled"));
}
Expand Down
Loading

0 comments on commit 9f06428

Please sign in to comment.