Skip to content

Commit

Permalink
优化防爆玻璃逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
Sobadfish committed Aug 19, 2024
1 parent d0011b4 commit 09f9a42
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/sobadfish/bedwar/entity/EntityTnt.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 19 additions & 10 deletions src/main/java/org/sobadfish/bedwar/manager/RoomManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Block> 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<Block> 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;
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/org/sobadfish/bedwar/tools/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,32 @@ public static void spawnBlock(GameRoom room, List<BlockPosition> spawn, boolean
// player.getInventory().removeItem(item);
}

/**
* 获取路径中的方块
* */
public static List<Block> getBlocksBetweenPositions(Position pos1, Position pos2) {
List<Block> 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;
}


/**
* 在游戏地图生成方块
Expand Down

0 comments on commit 09f9a42

Please sign in to comment.