mirror of
https://github.com/kaboomserver/extras.git
synced 2025-02-11 11:40:19 +00:00
Push latest changes to block physics
This commit is contained in:
parent
44e3d0fbb6
commit
bf6592f9f9
2 changed files with 64 additions and 76 deletions
|
@ -8,6 +8,7 @@ import org.bukkit.block.BlockFace;
|
|||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockFadeEvent;
|
||||
import org.bukkit.event.block.BlockFormEvent;
|
||||
import org.bukkit.event.block.BlockFromToEvent;
|
||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
|
@ -17,8 +18,44 @@ import org.bukkit.event.entity.EntityChangeBlockEvent;
|
|||
import com.destroystokyo.paper.event.block.BlockDestroyEvent;
|
||||
|
||||
public final class BlockPhysics implements Listener {
|
||||
|
||||
// This class contains code to prevent large areas of non-solid blocks
|
||||
// from crashing the server
|
||||
|
||||
public static HashSet<BlockFace> blockFaces = new HashSet<BlockFace>();
|
||||
|
||||
@EventHandler
|
||||
void onBlockDestroy(final BlockDestroyEvent event) {
|
||||
try {
|
||||
if (!event.getBlock().getType().isSolid()) {
|
||||
for (BlockFace face : blockFaces) {
|
||||
if (event.getBlock().getRelative(face).getType() != event.getBlock().getType()) {
|
||||
return;
|
||||
}
|
||||
event.getBlock().setType(Material.AIR, false);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/*@EventHandler
|
||||
void onBlockFade(final BlockFadeEvent event) {
|
||||
try {
|
||||
for (BlockFace face : blockFaces) {
|
||||
if (event.getBlock().getRelative(face).getType() != event.getBlock().getType()) {
|
||||
return;
|
||||
}
|
||||
event.getBlock().setType(Material.AIR, false);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}*/
|
||||
|
||||
@EventHandler
|
||||
void onBlockForm(final BlockFormEvent event) {
|
||||
if (event.getBlock().getType() == Material.LAVA
|
||||
|
@ -54,67 +91,37 @@ public final class BlockPhysics implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onBlockDestroy(final BlockDestroyEvent event) {
|
||||
if (!event.getBlock().getType().isSolid()) {
|
||||
for (BlockFace face : blockFaces) {
|
||||
if (event.getBlock().getRelative(face).getType() != event.getBlock().getType()) {
|
||||
return;
|
||||
}
|
||||
event.getBlock().setType(Material.AIR, false);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onBlockPhysics(final BlockPhysicsEvent event) {
|
||||
switch (event.getChangedType()) {
|
||||
case COMPARATOR:
|
||||
case REDSTONE_TORCH:
|
||||
case REDSTONE_WIRE:
|
||||
case REPEATER:
|
||||
/*for (BlockFace face : blockFaces) {
|
||||
if (event.getBlock().getRelative(face).getType() != event.getChangedType()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
switch (event.getChangedType()) {
|
||||
case COMPARATOR:
|
||||
case REDSTONE_TORCH:
|
||||
case REDSTONE_WIRE:
|
||||
case REPEATER:
|
||||
/*for (BlockFace face : blockFaces) {
|
||||
if (event.getBlock().getRelative(face).getType() != event.getChangedType()) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}*/
|
||||
event.setCancelled(true);
|
||||
}*/
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!event.getBlock().getType().isSolid()) {
|
||||
for (BlockFace face : blockFaces) {
|
||||
if (event.getBlock().getRelative(face).getType() != event.getBlock().getType()) {
|
||||
return;
|
||||
}
|
||||
event.getBlock().setType(Material.AIR, false);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
case ACTIVATOR_RAIL:
|
||||
case DETECTOR_RAIL:
|
||||
case POWERED_RAIL:
|
||||
case RAIL:
|
||||
for (BlockFace face : blockFaces) {
|
||||
if (event.getBlock().getRelative(face).getType() != event.getChangedType()) {
|
||||
return;
|
||||
}
|
||||
event.getBlock().setType(Material.AIR, false);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
case SIGN:
|
||||
case WALL_SIGN:
|
||||
/*try {
|
||||
event.getBlock().getState();
|
||||
event.getSourceBlock().getState();
|
||||
} catch (Exception exception) {
|
||||
event.getBlock().setType(Material.AIR, false);
|
||||
event.setCancelled(true);
|
||||
}*/
|
||||
break;
|
||||
case TNT:
|
||||
for (BlockFace face : blockFaces) {
|
||||
if (event.getBlock().getRelative(face).getType() != Material.REDSTONE_BLOCK
|
||||
&& event.getBlock().getRelative(face).getType() != Material.REDSTONE_TORCH) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package pw.kaboom.extras.modules.player;
|
||||
|
||||
import com.destroystokyo.paper.event.player.PlayerHandshakeEvent;
|
||||
import com.destroystokyo.paper.event.profile.PreLookupProfileEvent;
|
||||
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||
import com.google.common.base.Charsets;
|
||||
|
@ -174,24 +173,6 @@ public final class PlayerConnection implements Listener {
|
|||
void onPlayerQuit(PlayerQuitEvent event) {
|
||||
PlayerCommand.commandMillisList.remove(event.getPlayer().getUniqueId());
|
||||
PlayerInteract.interactMillisList.remove(event.getPlayer().getUniqueId());
|
||||
//SkinDownloader.skinInProgress.remove(event.getPlayer().getUniqueId());
|
||||
|
||||
/*final World world = event.getPlayer().getWorld();
|
||||
|
||||
for (final Chunk chunk : world.getLoadedChunks()) {
|
||||
try {
|
||||
int data = 0;
|
||||
for (BlockState block : chunk.getTileEntities()) {
|
||||
data = data + block.getBlockData().getAsString().length();
|
||||
}
|
||||
|
||||
if (data > 1285579) {
|
||||
world.regenerateChunk(chunk.getX(), chunk.getZ());
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
world.regenerateChunk(chunk.getX(), chunk.getZ());
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
|
Loading…
Reference in a new issue