Mitigate liquid server freezes

This commit is contained in:
mathias 2019-07-25 20:33:46 +03:00
parent 1e4a8b4fdb
commit e64e59e06d
2 changed files with 64 additions and 21 deletions

View file

@ -191,38 +191,65 @@ class Events implements Listener {
event.getToBlock().getState(); event.getToBlock().getState();
} catch (Exception exception) { } catch (Exception exception) {
event.setCancelled(true); event.setCancelled(true);
return;
}
final double tps = Bukkit.getServer().getTPS()[0];
if (tps < 15) {
event.setCancelled(true);
} }
} }
@EventHandler @EventHandler
void onBlockPhysics(BlockPhysicsEvent event) { void onBlockPhysics(BlockPhysicsEvent event) {
final Block block = event.getBlock(); final Material material = event.getChangedType();
if (main.fallingBlockList.contains(block.getType())) { if (main.fallingBlockList.contains(material)) {
main.fallingBlockCount++; main.fallingBlockCount++;
if (main.fallingBlockCount == 10) { if (main.fallingBlockCount == 10) {
event.setCancelled(true); event.setCancelled(true);
main.fallingBlockCount = 0; main.fallingBlockCount = 0;
} }
} else if (block.getType() == Material.FARMLAND) { } else if (material == Material.FARMLAND) {
event.setCancelled(true); event.setCancelled(true);
} else if (block.getType() == Material.WATER || } else if (material == Material.WATER ||
block.getType() == Material.LAVA) { material == Material.LAVA) {
final Block block = event.getBlock();
final Levelled levelledBlock = (Levelled) block.getBlockData(); final Levelled levelledBlock = (Levelled) block.getBlockData();
if (levelledBlock.getLevel() <= 7 && if (levelledBlock.getLevel() <= 7) {
block.getRelative(BlockFace.UP).getType() == block.getType()) { if (block.getRelative(BlockFace.UP).getType() != material) {
if (block.getRelative(BlockFace.DOWN).getType() != Material.AIR && boolean cancel = true;
block.getRelative(BlockFace.NORTH).getType() != Material.AIR && boolean solid = false;
block.getRelative(BlockFace.SOUTH).getType() != Material.AIR &&
block.getRelative(BlockFace.WEST).getType() != Material.AIR && for (BlockFace face : main.faces) {
block.getRelative(BlockFace.EAST).getType() != Material.AIR) { if (block.getRelative(face).getType() == Material.AIR ||
event.setCancelled(true); block.getRelative(face).getType() == Material.CAVE_AIR) {
cancel = false;
}
if (block.getRelative(face).getType() != Material.AIR ||
block.getRelative(face).getType() != Material.CAVE_AIR ||
block.getRelative(face).getType() != Material.LAVA ||
block.getRelative(face).getType() != Material.WATER) {
solid = true;
}
}
if (block.getRelative(BlockFace.UP).getType() == Material.WATER &&
solid != true) {
event.setCancelled(true);
} else if (cancel == true) {
event.setCancelled(true);
}
} }
} }
} else if (main.nonSolidWallMountedBlockList.contains(block.getType())) { } else if (main.nonSolidWallMountedBlockList.contains(material)) {
final World world = event.getBlock().getWorld(); final Block block = event.getBlock();
final World world = block.getWorld();
final int radius = 5; final int radius = 5;
int blockCount = 0; int blockCount = 0;
@ -233,7 +260,7 @@ class Events implements Listener {
final Location blockLocation = new Location(world, block.getX() + x, block.getY() + y, block.getZ() + z); final Location blockLocation = new Location(world, block.getX() + x, block.getY() + y, block.getZ() + z);
final Block coordBlock = world.getBlockAt(blockLocation); final Block coordBlock = world.getBlockAt(blockLocation);
if (coordBlock.getType() == block.getType() || if (coordBlock.getType() == material ||
main.nonSolidWallMountedBlockList.contains(coordBlock.getType())) { main.nonSolidWallMountedBlockList.contains(coordBlock.getType())) {
blockCount++; blockCount++;
} }
@ -248,7 +275,9 @@ class Events implements Listener {
if (blockCount == 42) { if (blockCount == 42) {
event.setCancelled(true); event.setCancelled(true);
} }
} else if (main.nonSolidDoubleBlockList.contains(block.getType())) { } else if (main.nonSolidDoubleBlockList.contains(material)) {
final Block block = event.getBlock();
if (main.nonSolidDoubleBlockList.contains(block.getRelative(BlockFace.DOWN).getType())) { if (main.nonSolidDoubleBlockList.contains(block.getRelative(BlockFace.DOWN).getType())) {
event.setCancelled(true); event.setCancelled(true);
} else if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR || } else if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR ||
@ -268,7 +297,9 @@ class Events implements Listener {
block.setType(Material.AIR, false); block.setType(Material.AIR, false);
} }
} else if (main.nonSolidSingularBlockList.contains(block.getType())) { } else if (main.nonSolidSingularBlockList.contains(material)) {
final Block block = event.getBlock();
if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR || if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR ||
main.nonSolidBlockList.contains(block.getRelative(BlockFace.DOWN).getType())) { main.nonSolidBlockList.contains(block.getRelative(BlockFace.DOWN).getType())) {
block.setType(Material.AIR, false); block.setType(Material.AIR, false);
@ -554,10 +585,10 @@ class Events implements Listener {
@EventHandler @EventHandler
void onPlayerLogin(PlayerLoginEvent event) { void onPlayerLogin(PlayerLoginEvent event) {
if (!(event.getHostname().startsWith("play.kaboom.pw") && /*if (!(event.getHostname().startsWith("play.kaboom.pw") &&
event.getHostname().endsWith(":53950"))) { event.getHostname().endsWith(":53950"))) {
event.disallow(Result.KICK_OTHER, "You connected to the server using an outdated server address/IP.\nPlease use the following address/IP:\n\nkaboom.pw"); event.disallow(Result.KICK_OTHER, "You connected to the server using an outdated server address/IP.\nPlease use the following address/IP:\n\nkaboom.pw");
} else { } else {*/
final Player player = event.getPlayer(); final Player player = event.getPlayer();
event.allow(); event.allow();
@ -569,7 +600,7 @@ class Events implements Listener {
} catch (Exception exception) { } catch (Exception exception) {
} }
main.playerProfile.remove(player.getName()); main.playerProfile.remove(player.getName());
} /*}*/
} }
@EventHandler @EventHandler

View file

@ -6,6 +6,7 @@ import java.util.HashSet;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import com.destroystokyo.paper.profile.PlayerProfile; import com.destroystokyo.paper.profile.PlayerProfile;
@ -16,6 +17,7 @@ public class Main extends JavaPlugin {
HashMap<UUID, Long> interactMillisList = new HashMap<>(); HashMap<UUID, Long> interactMillisList = new HashMap<>();
HashMap<String, PlayerProfile> playerProfile = new HashMap<>(); HashMap<String, PlayerProfile> playerProfile = new HashMap<>();
HashSet<String> consoleCommandBlacklist = new HashSet<>(); HashSet<String> consoleCommandBlacklist = new HashSet<>();
HashSet<BlockFace> faces = new HashSet<>();
HashSet<Material> fallingBlockList = new HashSet<>(); HashSet<Material> fallingBlockList = new HashSet<>();
HashSet<Material> nonSolidBlockList = new HashSet<>(); HashSet<Material> nonSolidBlockList = new HashSet<>();
HashSet<Material> nonSolidDoubleBlockList = new HashSet<>(); HashSet<Material> nonSolidDoubleBlockList = new HashSet<>();
@ -351,6 +353,16 @@ public class Main extends JavaPlugin {
"whisper" "whisper"
); );
Collections.addAll(
faces,
BlockFace.NORTH,
BlockFace.SOUTH,
BlockFace.WEST,
BlockFace.EAST,
BlockFace.UP,
BlockFace.DOWN
);
Collections.addAll( Collections.addAll(
fallingBlockList, fallingBlockList,
Material.ANVIL, Material.ANVIL,