Skip to content

Commit

Permalink
修复了领地外边缘的爆炸会波及领地内的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdeZhang committed Jul 26, 2024
1 parent bdfb368 commit 5e5d45e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>cn.lunadeer</groupId>
<artifactId>Dominion</artifactId>
<version>1.42.5-beta</version>
<version>1.42.6-beta</version>
<packaging>jar</packaging>

<name>Dominion</name>
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/cn/lunadeer/dominion/events/Apis.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;

public class Apis {
public static boolean canByPass(Player player, DominionDTO dom, MemberDTO prev) {
Expand Down Expand Up @@ -82,7 +85,7 @@ public static boolean checkFlag(DominionDTO dom, Flag flag, Player player, Cance
return false;
}

public static boolean checkFlag(DominionDTO dom, Flag flag, Cancellable event) {
public static boolean checkFlag(@Nullable DominionDTO dom, @NotNull Flag flag, @Nullable Cancellable event) {
if (!flag.getEnable()) {
return true;
}
Expand All @@ -92,7 +95,9 @@ public static boolean checkFlag(DominionDTO dom, Flag flag, Cancellable event) {
if (dom.getFlagValue(flag)) {
return true;
}
event.setCancelled(true);
if (event != null) {
event.setCancelled(true);
}
return false;
}
}
58 changes: 38 additions & 20 deletions src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.minecraftpluginutils.XLogger;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.*;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.player.PlayerInteractEvent;

import java.util.Objects;
Expand All @@ -25,21 +25,21 @@ public class EnvironmentEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // creeper_explode
public void onEntityExplode(EntityExplodeEvent event) {
Entity entity = event.getEntity();
if (isExplodeEntity(entity)) {
XLogger.debug("EntityExplodeEvent: " + entity.getType());
if (isNotExplodeEntity(entity)) {
return;
}
DominionDTO dom = Cache.instance.getDominionByLoc(event.getLocation());
checkFlag(dom, Flag.CREEPER_EXPLODE, event);
XLogger.debug("blockList" + event.blockList().size());
event.blockList().removeIf(block -> {
DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation());
return !checkFlag(dom, Flag.CREEPER_EXPLODE, null);
});
}

@EventHandler(priority = EventPriority.HIGHEST) // creeper_explode - item frame
public void onItemFrameExploded(HangingBreakByEntityEvent event) {
Entity entity = event.getEntity();
Entity remover = event.getRemover();
if (remover == null) {
return;
}
if (!isExplodeEntity(remover)) {
if (event.getCause() != HangingBreakEvent.RemoveCause.EXPLOSION) {
return;
}
DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation());
Expand All @@ -53,18 +53,18 @@ public void onArmorStandExploded(EntityDamageByEntityEvent event) {
return;
}
Entity damager = event.getDamager();
if (!isExplodeEntity(damager)) {
if (isNotExplodeEntity(damager)) {
return;
}
DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation());
checkFlag(dom, Flag.CREEPER_EXPLODE, event);
}

private static boolean isExplodeEntity(Entity damager) {
return damager.getType() == EntityType.CREEPER
|| damager.getType() == EntityType.WITHER_SKULL
|| damager.getType() == EntityType.FIREBALL
|| damager.getType() == EntityType.ENDER_CRYSTAL;
private static boolean isNotExplodeEntity(Entity damager) {
return damager.getType() != EntityType.CREEPER
&& damager.getType() != EntityType.WITHER_SKULL
&& damager.getType() != EntityType.FIREBALL
&& damager.getType() != EntityType.ENDER_CRYSTAL;
}

@EventHandler(priority = EventPriority.HIGHEST) // dragon_break_block
Expand All @@ -73,8 +73,10 @@ public void onDragonBreakBlock(EntityExplodeEvent event) {
if (entity.getType() != EntityType.ENDER_DRAGON) {
return;
}
DominionDTO dom = Cache.instance.getDominionByLoc(event.getLocation());
checkFlag(dom, Flag.DRAGON_BREAK_BLOCK, event);
event.blockList().removeIf(block -> {
DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation());
return !checkFlag(dom, Flag.DRAGON_BREAK_BLOCK, null);
});
}

@EventHandler(priority = EventPriority.HIGHEST) // fire_spread
Expand Down Expand Up @@ -130,7 +132,23 @@ public void onTntExplode(EntityExplodeEvent event) {
if (entity.getType() != EntityType.MINECART_TNT && entity.getType() != EntityType.PRIMED_TNT) {
return;
}
DominionDTO dom = Cache.instance.getDominionByLoc(event.getLocation());
event.blockList().removeIf(block -> {
DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation());
return !checkFlag(dom, Flag.TNT_EXPLODE, null);
});
}

@EventHandler(priority = EventPriority.HIGHEST) // tnt_explode - armor stand
public void onArmorStandExplodedByTnt(EntityDamageByEntityEvent event) {
Entity entity = event.getEntity();
if (entity.getType() != EntityType.ARMOR_STAND) {
return;
}
Entity damager = event.getDamager();
if (damager.getType() != EntityType.PRIMED_TNT && damager.getType() != EntityType.MINECART_TNT) {
return;
}
DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation());
checkFlag(dom, Flag.TNT_EXPLODE, event);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.bukkit.event.entity.EntityPlaceEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryType;
Expand Down Expand Up @@ -144,8 +145,7 @@ public void onBlockBreak(BlockBreakEvent event) {
@EventHandler(priority = EventPriority.HIGHEST) // break - item frame
public void onItemFrameBreak(HangingBreakByEntityEvent event) {
Entity entity = event.getEntity();
Entity remover = event.getRemover();
if (!(remover instanceof Player)) {
if (event.getCause() != HangingBreakEvent.RemoveCause.ENTITY) {
return;
}
if (entity instanceof ItemFrame) {
Expand Down

0 comments on commit 5e5d45e

Please sign in to comment.