2019-07-30 17:14:24 +00:00
|
|
|
package pw.kaboom.extras;
|
|
|
|
|
2019-11-13 20:50:09 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2019-07-30 17:14:24 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.World;
|
|
|
|
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.block.BlockFace;
|
2019-11-15 15:30:36 +00:00
|
|
|
import org.bukkit.block.CommandBlock;
|
|
|
|
import org.bukkit.block.ShulkerBox;
|
2019-07-30 17:14:24 +00:00
|
|
|
|
|
|
|
import org.bukkit.block.data.Levelled;
|
|
|
|
|
2019-09-28 00:29:48 +00:00
|
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
import org.bukkit.entity.TNTPrimed;
|
|
|
|
|
2019-07-30 17:14:24 +00:00
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
|
|
|
|
import org.bukkit.event.block.BlockFromToEvent;
|
|
|
|
import org.bukkit.event.block.BlockPhysicsEvent;
|
|
|
|
import org.bukkit.event.block.BlockRedstoneEvent;
|
|
|
|
|
2019-09-28 00:29:48 +00:00
|
|
|
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
2019-07-30 17:14:24 +00:00
|
|
|
|
2019-09-28 00:29:48 +00:00
|
|
|
class BlockPhysics implements Listener {
|
2019-07-30 17:14:24 +00:00
|
|
|
@EventHandler
|
|
|
|
void onBlockFromTo(BlockFromToEvent event) {
|
|
|
|
try {
|
|
|
|
event.getBlock().getState();
|
|
|
|
event.getToBlock().getState();
|
|
|
|
} catch (Exception exception) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
2019-09-28 00:29:48 +00:00
|
|
|
|
2019-07-30 17:14:24 +00:00
|
|
|
final double tps = Bukkit.getServer().getTPS()[0];
|
|
|
|
|
2019-09-28 00:29:48 +00:00
|
|
|
if (tps < 17) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Block block = event.getBlock();
|
|
|
|
final World world = block.getWorld();
|
|
|
|
final int radius = 5;
|
|
|
|
int blockCount = 0;
|
|
|
|
|
|
|
|
for (int x = -radius; x <= radius; x++) {
|
|
|
|
for (int y = -radius; y <= radius; y++) {
|
|
|
|
for (int z = -radius; z <= radius; z++) {
|
2019-11-13 19:13:54 +00:00
|
|
|
if (blockCount < 200) {
|
2019-09-28 00:29:48 +00:00
|
|
|
final Location blockLocation = new Location(world, block.getX() + x, block.getY() + y, block.getZ() + z);
|
|
|
|
final Block coordBlock = world.getBlockAt(blockLocation);
|
|
|
|
|
2019-11-13 19:13:54 +00:00
|
|
|
if (coordBlock.isLiquid() ||
|
|
|
|
coordBlock.getType() == Material.OBSIDIAN) {
|
2019-09-28 00:29:48 +00:00
|
|
|
blockCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
2019-10-13 13:14:25 +00:00
|
|
|
} else {
|
|
|
|
event.setCancelled(true);
|
2019-09-28 00:29:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-30 17:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
void onBlockPhysics(BlockPhysicsEvent event) {
|
2019-11-13 19:13:54 +00:00
|
|
|
final Material material = event.getChangedType();
|
2019-07-30 17:14:24 +00:00
|
|
|
|
2019-09-28 00:29:48 +00:00
|
|
|
if (material == Material.FARMLAND) {
|
2019-07-30 17:14:24 +00:00
|
|
|
event.setCancelled(true);
|
2019-11-15 15:30:36 +00:00
|
|
|
} else if (event.getSourceBlock().getState() instanceof CommandBlock) {
|
|
|
|
event.getSourceBlock().getState().update();
|
|
|
|
} else if (event.getBlock().getState() instanceof CommandBlock) {
|
|
|
|
event.getBlock().getState().update();
|
2019-11-13 19:13:54 +00:00
|
|
|
} else if (event.getBlock().isLiquid()) {
|
|
|
|
final Block block = event.getBlock();
|
2019-10-04 13:42:11 +00:00
|
|
|
final World world = block.getWorld();
|
|
|
|
final int radius = 5;
|
|
|
|
int blockCount = 0;
|
2019-10-13 13:14:25 +00:00
|
|
|
|
2019-10-04 13:42:11 +00:00
|
|
|
for (int x = -radius; x <= radius; x++) {
|
|
|
|
for (int y = -radius; y <= radius; y++) {
|
|
|
|
for (int z = -radius; z <= radius; z++) {
|
2019-11-13 19:13:54 +00:00
|
|
|
if (blockCount < 200) {
|
2019-10-04 13:42:11 +00:00
|
|
|
final Location blockLocation = new Location(world, block.getX() + x, block.getY() + y, block.getZ() + z);
|
|
|
|
final Block coordBlock = world.getBlockAt(blockLocation);
|
|
|
|
|
2019-11-13 19:13:54 +00:00
|
|
|
if ((coordBlock.isLiquid() ||
|
2019-10-04 13:42:11 +00:00
|
|
|
coordBlock.getType() == Material.OBSIDIAN) &&
|
|
|
|
block.getType() != coordBlock.getType()) {
|
|
|
|
blockCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
2019-10-13 13:14:25 +00:00
|
|
|
} else {
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
2019-10-03 16:30:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-13 13:14:25 +00:00
|
|
|
} else if (Main.nonSolidBlockList.contains(material) ||
|
|
|
|
material == Material.AIR ||
|
|
|
|
material == Material.CAVE_AIR) {
|
2019-11-13 19:13:54 +00:00
|
|
|
final Block block = event.getBlock();
|
2019-07-30 17:14:24 +00:00
|
|
|
final World world = block.getWorld();
|
|
|
|
final int radius = 5;
|
|
|
|
int blockCount = 0;
|
|
|
|
|
|
|
|
for (int x = -radius; x <= radius; x++) {
|
|
|
|
for (int y = -radius; y <= radius; y++) {
|
|
|
|
for (int z = -radius; z <= radius; z++) {
|
2019-11-13 19:13:54 +00:00
|
|
|
if (blockCount < 100) {
|
2019-07-30 17:14:24 +00:00
|
|
|
final Location blockLocation = new Location(world, block.getX() + x, block.getY() + y, block.getZ() + z);
|
|
|
|
final Block coordBlock = world.getBlockAt(blockLocation);
|
|
|
|
|
2019-10-13 13:14:25 +00:00
|
|
|
if (Main.nonSolidBlockList.contains(coordBlock.getType())) {
|
2019-07-30 17:14:24 +00:00
|
|
|
blockCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
2019-10-13 13:14:25 +00:00
|
|
|
} else {
|
|
|
|
for (BlockFace face : BlockFace.values()) {
|
|
|
|
if (Main.nonSolidBlockList.contains(block.getRelative(face).getType())) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
2019-07-30 17:14:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-13 19:13:54 +00:00
|
|
|
}
|
2019-07-30 17:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
void onBlockRedstone(BlockRedstoneEvent event) {
|
|
|
|
final double tps = Bukkit.getServer().getTPS()[0];
|
|
|
|
|
|
|
|
if (tps < 10) {
|
|
|
|
event.setNewCurrent(0);
|
|
|
|
}
|
|
|
|
}
|
2019-09-28 00:29:48 +00:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
|
|
|
if (event.getEntityType() == EntityType.FALLING_BLOCK &&
|
|
|
|
event.getTo() == Material.AIR) {
|
|
|
|
Main.fallingBlockCount++;
|
|
|
|
|
|
|
|
if (Main.fallingBlockCount == 10) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
Main.fallingBlockCount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-30 17:14:24 +00:00
|
|
|
}
|