Skip to content

Commit

Permalink
2 new lag exploits
Browse files Browse the repository at this point in the history
  • Loading branch information
moom0o committed Mar 19, 2021
1 parent 1cabdad commit 0ca8759
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 13 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ DisableExplosions: false
FixChatcoIgnoreBug: true
FixWorldStatsCommandBug: true
# Attempt to prevent chunk bans/fps lag.
# Automatically disabled in non 1.12 due to a shit ton of errors
PreventChunkBan: true
MaxEnchantmentTablePerChunk: 16
MaxEnderchestPerChunk: 64
Expand All @@ -110,6 +111,12 @@ PreventUnicodeDot: true
# Removes entitys or players if "invalid", not sure if this works. Seems too simple. But again, mojang is retarded.
ExperimentalGodModePatch: true
PreventCommandSign: true
# Disable the 1.16 fish from spawning, there is a shit ton of them that spawn and this can cause a ton of lag, automatically disabled in 1.12
DisableFish: true
# Prevent massive sand chunks from killing the server, prevents any falling blocks from falling if there is more than 50 falling blocks in a chunk
LimitFallingBlocks: true
# Prevent having a shit ton of exp bottles in one chunk then loading it to kill the server
LimitExpBottles: true

#Dupe preventions
DisableChestsOnDonkeys: false
Expand Down
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.moomoo</groupId>
<artifactId>anarchyexploitfixes</artifactId>
<version>18.0.4</version>
<version>18.0.5</version>
<packaging>jar</packaging>

<name>AnarchyExploitFixes</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
plugin.getConfig().set("ExperimentalDupePatch2", false);
plugin.getLogger().warning("Disabled:\nRemoveALLIllegalBlocksOnCHUNKLOAD\nFillInBedrockFloor\nFillInBedrockRoof\nExperimentalDupePatch2\nDue to errors with non 1.12.2 versions.");
} else {
plugin. getConfig().set("DisableFish", false);
plugin.getConfig().set("DisableFish", false);
plugin.getLogger().warning("Disabled:\nDisableFish\nbecause server is 1.12");
}
sender.sendMessage(ChatColor.GOLD + "AnarchyExploitFixes config reloaded.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.moomoo.anarchyexploitfixes.prevention;

import me.moomoo.anarchyexploitfixes.Main;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
Expand All @@ -15,10 +14,10 @@ public Entities(Main plugin) {

@EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event) {
if(plugin.config.getBoolean("DisableFish")){
if (plugin.config.getBoolean("DisableFish")) {
// if (event.getEntity().getType().equals(EntityType.COD) || event.getEntity().getType().equals(EntityType.SALMON)) {
// Have to use strings or else maven will get pissed at me
if(event.getEntity().getName().equals("Cod") || event.getEntity().getName().equals("Salmon")){
if (event.getEntity().getName().equals("Cod") || event.getEntity().getName().equals("Salmon")) {
event.setCancelled(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.entity.EntityPortalEvent;
import org.bukkit.event.entity.ExpBottleEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;

import java.awt.*;
import java.util.HashSet;

public class LagExploits implements Listener {
private final Main plugin;
HashSet<String> throwcooldown = new HashSet<>();
HashSet<Location> throwcooldownlocations = new HashSet<>();
HashSet<String> throwCooldown = new HashSet<>();
HashSet<Location> throwCooldownLocations = new HashSet<>();

public LagExploits(Main plugin) {
this.plugin = plugin;
Expand All @@ -30,6 +33,35 @@ private void onEntityChange(BlockPhysicsEvent evt) {
double tps_double = Bukkit.getServer().getTPS()[0];
if (tps_double < config.getDouble("FallingBlocks")) {
evt.setCancelled(true);
} else {
if (plugin.config.getBoolean("LimitFallingBlocks")) {
if (count(evt.getBlock().getChunk().getEntities(), EntityType.FALLING_BLOCK) > 50) {
evt.setCancelled(true);
}
}
}
}

@EventHandler
private void onExpBottle(ExpBottleEvent evt) {
if (plugin.config.getBoolean("LimitExpBottles")) {
if (count(evt.getEntity().getChunk().getEntities(), EntityType.THROWN_EXP_BOTTLE) > 25) {
remove(evt.getEntity().getChunk().getEntities(), EntityType.THROWN_EXP_BOTTLE);
}
}
}

@EventHandler
private void onPortal(EntityPortalEvent evt) {
if (evt.getEntityType().isSpawnable()) {
plugin.getLogger().info("yes spawnable");
} else {
plugin.getLogger().info("no spawnable");
}
if (evt.getEntityType().isAlive()) {
plugin.getLogger().info("yes alive");
} else {
plugin.getLogger().info("no alive");
}
}

Expand All @@ -42,19 +74,19 @@ private void onThrow(ProjectileLaunchEvent evt) {
Point p2 = new Point(p.getLocation().getBlockX(), p.getLocation().getBlockZ());
if (p1.distance(p2) <= 1) {
found = true;
if (throwcooldown.contains(p.getName())) {
if (throwCooldown.contains(p.getName())) {
if (evt.getEntity().getType() != EntityType.THROWN_EXP_BOTTLE) {
evt.setCancelled(true);
}
} else {
throwcooldown.add(p.getName());
Bukkit.getServer().getScheduler().runTaskLater(plugin, () -> throwcooldown.remove(p.getName()), 6L);
throwCooldown.add(p.getName());
Bukkit.getServer().getScheduler().runTaskLater(plugin, () -> throwCooldown.remove(p.getName()), 6L);
}
}
}
if (!found) {
boolean done = false;
for (Location l : throwcooldownlocations) {
for (Location l : throwCooldownLocations) {
Point p1 = new Point(evt.getEntity().getLocation().getBlockX(), evt.getEntity().getLocation().getBlockZ());
Point p2 = new Point(l.getBlockX(), l.getBlockZ());
// We check if the entity is anywhere near our last
Expand All @@ -65,10 +97,28 @@ private void onThrow(ProjectileLaunchEvent evt) {
}
if (!done) {
Location location = evt.getEntity().getLocation();
throwcooldownlocations.add(location);
Bukkit.getServer().getScheduler().runTaskLater(plugin, () -> throwcooldownlocations.remove(location), 20L);
throwCooldownLocations.add(location);
Bukkit.getServer().getScheduler().runTaskLater(plugin, () -> throwCooldownLocations.remove(location), 20L);
}
}
}
}

public Integer count(Entity[] e, EntityType type) {
Integer count = 0;
for (Entity entity : e) {
if (entity.getType().equals(type)) {
count++;
}
}
return count;
}

public void remove(Entity[] e, EntityType type) {
for (Entity entity : e) {
if (entity.getType().equals(type)) {
entity.remove();
}
}
}
}
4 changes: 4 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ ExperimentalGodModePatch: true
PreventCommandSign: true
# Disable the 1.16 fish from spawning, there is a shit ton of them that spawn and this can cause a ton of lag, automatically disabled in 1.12
DisableFish: true
# Prevent massive sand chunks from killing the server, prevents any falling blocks from falling if there is more than 50 falling blocks in a chunk
LimitFallingBlocks: true
# Prevent having a shit ton of exp bottles in one chunk then loading it to kill the server
LimitExpBottles: true

#Dupe preventions
DisableChestsOnDonkeys: false
Expand Down

0 comments on commit 0ca8759

Please sign in to comment.