Skip to content

Commit

Permalink
More config
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreeam-qwq committed Feb 7, 2024
1 parent 51ab07e commit 85a884f
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 54 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/surf/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ public void registerEvents() {
pluginManager.registerEvents(new CleanIllegal(), this);

// AntiLag
if (ConfigCache.BlockPhysicsEnabled) pluginManager.registerEvents(new BlockPhysics(), this);
pluginManager.registerEvents(new MinecartLag(this), this);
pluginManager.registerEvents(new WitherSpawn(), this);
if (ConfigCache.LimitLiquidSpreadEnabled) pluginManager.registerEvents(new BlockPhysics(), this);
if (ConfigCache.LimitVehicleEnabled) pluginManager.registerEvents(new MinecartLag(this), this);
if (ConfigCache.LimitWitherSpawnOnLagEnabled) pluginManager.registerEvents(new WitherSpawn(), this);

// Patches
pluginManager.registerEvents(new BucketEvent(), this);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/surf/modules/antilag/BlockPhysics.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public class BlockPhysics implements Listener {

@EventHandler
public void onLiquidSpread(BlockFromToEvent event) {
if (Utils.getTps() <= ConfigCache.BlockPhysicsDisableTPS) {
if (isChecked(event.getBlock().getType())) {
if (Utils.getTps() <= ConfigCache.LimitLiquidSpreadDisableTPS) {
if (isLiquid(event.getBlock().getType())) {
event.setCancelled(true);
}
}
}

private boolean isChecked(Material material) {
return switch (material) {
private boolean isLiquid(Material m) {
return switch (m) {
case LAVA, WATER -> true;
default -> false;
};
Expand Down
54 changes: 29 additions & 25 deletions src/main/java/org/surf/modules/antilag/MinecartLag.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,42 @@ public MinecartLag(Main plugin) {

@EventHandler(ignoreCancelled = true)
public void onSpawn(VehicleCreateEvent event) {
Chunk chunk = event.getVehicle().getChunk();
Vehicle vehicle = event.getVehicle();
Player player = Utils.getNearbyPlayer(20, vehicle.getLocation());
String formattedName = vehicle.getType().toString().toLowerCase().concat("s");
long amount = Arrays.stream(chunk.getEntities()).filter(entity -> entity instanceof Vehicle).count();
if (amount >= ConfigCache.MinecartPerChunkLimit) {
event.setCancelled(true);
Utils.sendMessage(player, Utils.getPrefix() + "&6Please limit " + formattedName + " to &r&c" + ConfigCache.MinecartPerChunkLimit + "&r&6 per chunk");
Utils.sendOpMessage(Utils.getPrefix() + "&6Removed &r&3" + chunk.getEntities().length + " " + formattedName + "&r&6 from a lag machine owned by&r&3 " + player.getName());
System.out.println(LegacyComponentSerializer.legacyAmpersand().deserialize(Utils.getPrefix() + "&6Removed &r&3" + chunk.getEntities().length + " " + formattedName + "&r&6 from a lag machine owned by&r&3 " + player.getName()));
for (Entity ent : event.getVehicle().getChunk().getEntities()) {
if (ent instanceof Vehicle) {
ent.remove();
if (Utils.getTps() <= ConfigCache.LimitVehicleDisableTPS) {
Chunk chunk = event.getVehicle().getChunk();
Vehicle vehicle = event.getVehicle();
Player player = Utils.getNearbyPlayer(20, vehicle.getLocation());
String formattedName = vehicle.getType().toString().toLowerCase().concat("s");
long amount = Arrays.stream(chunk.getEntities()).filter(entity -> entity instanceof Vehicle).count();
if (amount >= ConfigCache.MinecartPerChunkLimit) {
event.setCancelled(true);
Utils.sendMessage(player, Utils.getPrefix() + "&6Please limit " + formattedName + " to &r&c" + ConfigCache.MinecartPerChunkLimit + "&r&6 per chunk");
Utils.sendOpMessage(Utils.getPrefix() + "&6Removed &r&3" + chunk.getEntities().length + " " + formattedName + "&r&6 from a lag machine owned by&r&3 " + player.getName());
System.out.println(LegacyComponentSerializer.legacyAmpersand().deserialize(Utils.getPrefix() + "&6Removed &r&3" + chunk.getEntities().length + " " + formattedName + "&r&6 from a lag machine owned by&r&3 " + player.getName()));
for (Entity ent : event.getVehicle().getChunk().getEntities()) {
if (ent instanceof Vehicle) {
ent.remove();
}
}
}
}
}

@EventHandler
public void onVehicleMove(VehicleMoveEvent event) {
Chunk chunk = event.getVehicle().getChunk();
Vehicle vehicle = event.getVehicle();
String formattedName = vehicle.getType().toString().toLowerCase().concat("s").replace("_", " ");
String formattedName1 = vehicle.getType().toString().toLowerCase().replace("_", " ");
int max = ConfigCache.MinecartPerChunkLimit;
Player player = Utils.getNearbyPlayer(20, vehicle.getLocation());
if (!event.getFrom().getChunk().equals(event.getTo().getChunk())) {
if (chunk.getEntities().length >= max) {
vehicle.remove();
Utils.sendMessage(player, Utils.getPrefix() + "&6Please limit " + formattedName + " to &r&c" + max + "&r&6 per chunk");
Utils.sendOpMessage(Utils.getPrefix() + "&6Deleted a &r&3" + formattedName1 + "&r&6 from a lag machine owned by&r&3 " + player.getName() + " &4BYPASS ATTEMPT");
plugin.getLogger().info(Utils.getPrefix() + "&6Deleted a &r&3" + formattedName1 + "&r&6 from a lag machine owned by&r&3 " + player.getName() + " &4BYPASS ATTEMPT");
if (Utils.getTps() <= ConfigCache.LimitVehicleDisableTPS) {
Chunk chunk = event.getVehicle().getChunk();
Vehicle vehicle = event.getVehicle();
String formattedName = vehicle.getType().toString().toLowerCase().concat("s").replace("_", " ");
String formattedName1 = vehicle.getType().toString().toLowerCase().replace("_", " ");
int max = ConfigCache.MinecartPerChunkLimit;
Player player = Utils.getNearbyPlayer(20, vehicle.getLocation());
if (!event.getFrom().getChunk().equals(event.getTo().getChunk())) {
if (chunk.getEntities().length >= max) {
vehicle.remove();
Utils.sendMessage(player, Utils.getPrefix() + "&6Please limit " + formattedName + " to &r&c" + max + "&r&6 per chunk");
Utils.sendOpMessage(Utils.getPrefix() + "&6Deleted a &r&3" + formattedName1 + "&r&6 from a lag machine owned by&r&3 " + player.getName() + " &4BYPASS ATTEMPT");
plugin.getLogger().info(Utils.getPrefix() + "&6Deleted a &r&3" + formattedName1 + "&r&6 from a lag machine owned by&r&3 " + player.getName() + " &4BYPASS ATTEMPT");
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/surf/modules/antilag/WitherSpawn.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.surf.util.ConfigCache;
import org.surf.util.Utils;

public class WitherSpawn implements Listener {
@EventHandler(ignoreCancelled = true)
public void onWitherSpawn(EntitySpawnEvent event) {
if (event.getEntity() instanceof Wither && Utils.getTps() <= 16) {
if (Utils.getTps() <= ConfigCache.LimitWitherSpawnOnLagDisableTPS && event.getEntity() instanceof Wither) {
event.setCancelled(true);
}
}
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/org/surf/util/ConfigCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ public class ConfigCache {
public static String IllegalPotionMessage;

// Anti Lag
public static boolean BlockPhysicsEnabled;
public static int BlockPhysicsDisableTPS;
public static boolean LimitLiquidSpreadEnabled;
public static int LimitLiquidSpreadDisableTPS;

public static boolean LimitVehicleEnabled;
public static int LimitVehicleDisableTPS;
public static int MinecartPerChunkLimit;

public static boolean LimitWitherSpawnOnLagEnabled;
public static int LimitWitherSpawnOnLagDisableTPS;

// Patches
public static boolean GateWayPreventCrashExploit;
public static boolean GateWayPreventEntityEnterPortal;
Expand Down Expand Up @@ -89,9 +94,15 @@ public static void loadConfig() {
IllegalPotionMessage = plugin.getConfig().getString("IllegalPotion.Message");

// Anti Lag
BlockPhysicsEnabled = plugin.getConfig().getBoolean("BlockPhysics.Enabled");
BlockPhysicsDisableTPS = plugin.getConfig().getInt("BlockPhysics.disable-tps");
MinecartPerChunkLimit = plugin.getConfig().getInt("Minecart-per-chunk.limit");
LimitLiquidSpreadEnabled = plugin.getConfig().getBoolean("LimitLiquidSpread.Enabled");
LimitLiquidSpreadDisableTPS = plugin.getConfig().getInt("LimitLiquidSpread.disable-tps");

LimitVehicleEnabled = plugin.getConfig().getBoolean("LimitVehicle.Enabled");
LimitVehicleDisableTPS = plugin.getConfig().getInt("LimitVehicle.disable-tps");
MinecartPerChunkLimit = plugin.getConfig().getInt("LimitVehicle.Minecart-per-chunk.limit");

LimitWitherSpawnOnLagEnabled = plugin.getConfig().getBoolean("LimitWitherSpawnOnLag.Enabled");
LimitWitherSpawnOnLagDisableTPS = plugin.getConfig().getInt("LimitWitherSpawnOnLag.disable-tps");

// Patches
GateWayPreventCrashExploit = plugin.getConfig().getBoolean("GateWay.PreventCrashExploit");
Expand Down
32 changes: 16 additions & 16 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
Prefix: "&6&l[&b&lSurf&6&l]&6 "

#Anti-illegal >>

#Messages to send the player when they try to place illegal blocks
IllegalBlockPlace:
Enabled: true
Expand Down Expand Up @@ -54,8 +53,23 @@ IllegalPotion:
Message: "&6&l[&b&lSurf&6&l]&6&6 You can not use this illegal potion"


#Patch >>
#AntiLag >>
#water / lava flowing disable tps this is useful on new servers with lots of block physics updates that cause lag
#Set -1 to disable
LimitLiquidSpread:
Enabled: true
disable-tps: 17
LimitVehicle:
Enabled: true
disable-tps: 17
#Ammount of vehicles allowed in a chunk
Minecart-per-chunk:
limit: 500
LimitWitherSpawnOnLag:
Enabled: true
disable-tps: 17

#Patch >>
#ChunkBan skull limit tile entity limit and prevent message
ChunkBan:
Enabled: true
Expand All @@ -72,21 +86,12 @@ Nether:
top-bottom-do-damage: false
UnbookBan:
Message: "&6&l[&b&lSurf&6&l]&6&6 You have been unbookbanned"
#Ammount of vehicles allowed in a chunk
Minecart-per-chunk:
limit: 500
#water / lava flowing disable tps this is useful on new servers with lots of block physics updates that cause lag
#Set -1 to disable
BlockPhysics:
Enabled: false
disable-tps: 15
GateWay:
PreventCrashExploit: false
PreventEntityEnterPortal: false


#Misc >>

#These are the connection messages for when a player joins / leaves
#Use & for colours and %player% as a placeholder for the players name
Connection:
Expand All @@ -102,8 +107,3 @@ Connection-Prevent-Kick:
- "Kicked for spamming"
- "Invalid hotbar selection (Hacking?)"
- "You released use item too quickly (Hacking?)"
#This is to prevent people from crashing / lagging the server by spam opening chest and other containers
#ChestLagFix:
# MaxOpensPerSecond: 64
# KickMessage: "&6&l[&b&lSurf&6&l]&6&c [AntiChestLag]&r&6 You have lost connection to the server"
# RemoveUnicodeBooks: false

0 comments on commit 85a884f

Please sign in to comment.