2019-12-17 12:37:59 +00:00
|
|
|
package pw.kaboom.extras.modules.block;
|
2019-07-30 17:14:24 +00:00
|
|
|
|
2019-12-17 18:23:24 +00:00
|
|
|
import java.util.HashSet;
|
|
|
|
|
2019-07-30 17:14:24 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.block.BlockFace;
|
2019-09-28 00:29:48 +00:00
|
|
|
import org.bukkit.entity.EntityType;
|
2019-07-30 17:14:24 +00:00
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.Listener;
|
2019-12-03 04:53:37 +00:00
|
|
|
import org.bukkit.event.block.BlockFormEvent;
|
2019-07-30 17:14:24 +00:00
|
|
|
import org.bukkit.event.block.BlockFromToEvent;
|
|
|
|
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-12-03 04:53:37 +00:00
|
|
|
import com.destroystokyo.paper.event.block.BlockDestroyEvent;
|
|
|
|
|
2019-12-17 12:37:59 +00:00
|
|
|
public class BlockPhysics implements Listener {
|
2019-12-17 18:23:24 +00:00
|
|
|
public static HashSet<BlockFace> blockFaces = new HashSet<BlockFace>();
|
|
|
|
|
2019-07-30 17:14:24 +00:00
|
|
|
@EventHandler
|
2019-12-03 04:53:37 +00:00
|
|
|
void onBlockForm(BlockFormEvent event) {
|
|
|
|
if (event.getBlock().getType() == Material.LAVA ||
|
|
|
|
event.getBlock().getType() == Material.WATER) {
|
2019-12-17 18:23:24 +00:00
|
|
|
for (BlockFace face : blockFaces) {
|
2019-12-03 04:53:37 +00:00
|
|
|
if (event.getBlock().getRelative(face).getType() != Material.LAVA &&
|
|
|
|
event.getBlock().getRelative(face).getType() != Material.WATER) {
|
|
|
|
return;
|
2019-09-28 00:29:48 +00:00
|
|
|
}
|
2019-12-03 04:53:37 +00:00
|
|
|
event.setCancelled(true);
|
2019-09-28 00:29:48 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-30 17:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
2019-12-03 04:53:37 +00:00
|
|
|
void onBlockFromTo(BlockFromToEvent event) {
|
|
|
|
if (event.getBlock().getType() == Material.LAVA ||
|
|
|
|
event.getBlock().getType() == Material.WATER) {
|
|
|
|
boolean lavaFound = false;
|
|
|
|
boolean waterFound = false;
|
|
|
|
|
2019-12-17 18:23:24 +00:00
|
|
|
for (BlockFace face : blockFaces) {
|
2019-12-03 04:53:37 +00:00
|
|
|
if (event.getBlock().getRelative(face).getType() == Material.LAVA) {
|
|
|
|
lavaFound = true;
|
|
|
|
} else if (event.getBlock().getRelative(face).getType() == Material.WATER) {
|
|
|
|
waterFound = true;
|
|
|
|
}
|
2019-12-17 18:23:24 +00:00
|
|
|
|
2019-12-03 04:53:37 +00:00
|
|
|
if (lavaFound && waterFound) {
|
|
|
|
event.setCancelled(true);
|
2019-10-03 16:30:18 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-03 04:53:37 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-17 18:23:24 +00:00
|
|
|
|
2019-12-03 04:53:37 +00:00
|
|
|
@EventHandler
|
|
|
|
void onBlockDestroy(BlockDestroyEvent event) {
|
|
|
|
if (!event.getBlock().getType().isSolid()) {
|
2019-12-17 18:23:24 +00:00
|
|
|
for (BlockFace face : blockFaces) {
|
2019-12-03 04:53:37 +00:00
|
|
|
if (event.getBlock().getRelative(face).getType() != event.getBlock().getType()) {
|
|
|
|
return;
|
2019-07-30 17:14:24 +00:00
|
|
|
}
|
2019-12-03 04:53:37 +00:00
|
|
|
event.getBlock().setType(Material.AIR, false);
|
|
|
|
event.setCancelled(true);
|
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-12-17 18:23:24 +00:00
|
|
|
|
2019-12-11 01:36:35 +00:00
|
|
|
int fallingBlockCount;
|
2019-12-17 18:23:24 +00:00
|
|
|
|
2019-09-28 00:29:48 +00:00
|
|
|
@EventHandler
|
|
|
|
void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
|
|
|
if (event.getEntityType() == EntityType.FALLING_BLOCK &&
|
|
|
|
event.getTo() == Material.AIR) {
|
2019-12-11 01:36:35 +00:00
|
|
|
fallingBlockCount++;
|
2019-09-28 00:29:48 +00:00
|
|
|
|
2019-12-11 01:36:35 +00:00
|
|
|
if (fallingBlockCount == 10) {
|
2019-09-28 00:29:48 +00:00
|
|
|
event.setCancelled(true);
|
2019-12-11 01:36:35 +00:00
|
|
|
fallingBlockCount = 0;
|
2019-09-28 00:29:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-30 17:14:24 +00:00
|
|
|
}
|