diff --git a/src/main/java/org/sobadfish/bedwar/entity/EntityTnt.java b/src/main/java/org/sobadfish/bedwar/entity/EntityTnt.java index afe4e8f..1526d42 100644 --- a/src/main/java/org/sobadfish/bedwar/entity/EntityTnt.java +++ b/src/main/java/org/sobadfish/bedwar/entity/EntityTnt.java @@ -139,7 +139,7 @@ private void resetNameTag(){ @Override public void explode() { - EntityExplosionPrimeEvent event = new EntityExplosionPrimeEvent(this, 4); + EntityExplosionPrimeEvent event = new EntityExplosionPrimeEvent(this, 3); server.getPluginManager().callEvent(event); if (event.isCancelled()) { return; diff --git a/src/main/java/org/sobadfish/bedwar/manager/RoomManager.java b/src/main/java/org/sobadfish/bedwar/manager/RoomManager.java index 3bc9284..5e30c66 100644 --- a/src/main/java/org/sobadfish/bedwar/manager/RoomManager.java +++ b/src/main/java/org/sobadfish/bedwar/manager/RoomManager.java @@ -64,10 +64,7 @@ import org.sobadfish.bedwar.tools.Utils; import java.io.File; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author SoBadFish @@ -517,23 +514,35 @@ public void onCraft(CraftItemEvent event){ @EventHandler public void onEntityExplodeEvent(EntityExplodeEvent event){ + Level level = event.getPosition().getLevel(); GameRoom room = getGameRoomByLevel(level); if(room != null) { ArrayList blocks = new ArrayList<>(event.getBlockList()); for (Block block : event.getBlockList()) { - //防爆玻璃 - if (!room.worldInfo.getPlaceBlock().contains(block) || - block instanceof BlockGlass) { - blocks.remove(block); - }else{ - room.worldInfo.getPlaceBlock().remove(block); + if (!room.worldInfo.getPlaceBlock().contains(block)) { + blocks.remove(block); + } + if(block instanceof BlockGlass){ + blocks.remove(block); } + List line = Utils.getBlocksBetweenPositions(event.getPosition(),block); + for (Block b2 : line){ + if(b2 instanceof BlockGlass){ + blocks.remove(block); + } + } + + } + for (Block block : blocks) { + room.worldInfo.getPlaceBlock().remove(block); } event.setBlockList(blocks); } } + + @EventHandler public void onPlaceBlock(BlockPlaceEvent event){ Level level = event.getBlock().level; diff --git a/src/main/java/org/sobadfish/bedwar/tools/Utils.java b/src/main/java/org/sobadfish/bedwar/tools/Utils.java index d61e578..83c5ac5 100644 --- a/src/main/java/org/sobadfish/bedwar/tools/Utils.java +++ b/src/main/java/org/sobadfish/bedwar/tools/Utils.java @@ -561,6 +561,32 @@ public static void spawnBlock(GameRoom room, List spawn, boolean // player.getInventory().removeItem(item); } + /** + * 获取路径中的方块 + * */ + public static List getBlocksBetweenPositions(Position pos1, Position pos2) { + List blocks = new ArrayList<>(); + Level level = pos1.getLevel(); + + int minX = Math.min(pos1.getFloorX(), pos2.getFloorX()); + int maxX = Math.max(pos1.getFloorX(), pos2.getFloorX()); + int minY = Math.min(pos1.getFloorY(), pos2.getFloorY()); + int maxY = Math.max(pos1.getFloorY(), pos2.getFloorY()); + int minZ = Math.min(pos1.getFloorZ(), pos2.getFloorZ()); + int maxZ = Math.max(pos1.getFloorZ(), pos2.getFloorZ()); + + for (int x = minX; x <= maxX; x++) { + for (int y = minY; y <= maxY; y++) { + for (int z = minZ; z <= maxZ; z++) { + Block block = level.getBlock(new Vector3(x, y, z)); + blocks.add(block); + } + } + } + + return blocks; + } + /** * 在游戏地图生成方块