优化完善展示框行为

This commit is contained in:
zhangyuheng 2024-07-25 16:54:32 +08:00
parent 8b9e984917
commit f22b97a7f7
4 changed files with 93 additions and 18 deletions

View File

@ -6,7 +6,7 @@
<groupId>cn.lunadeer</groupId>
<artifactId>Dominion</artifactId>
<version>1.42.1-beta</version>
<version>1.42.2-beta</version>
<packaging>jar</packaging>
<name>Dominion</name>

View File

@ -46,6 +46,7 @@ public enum Flag {
HOOK("hook", "使用钓钩", "是否可以使用钓钩", false, false, true),
HOPPER("hopper", "特殊容器", "包含:漏斗/熔炉/发射器/投掷器/高炉/烟熏炉", false, false, true),
IGNITE("ignite", "点燃", "是否可以使用打火石点火", false, false, true),
ITEM_FRAME_INTERACTIVE("item_frame_interactive", "展示框交互", "是否可以与物品展示框交互(旋转展示框的东西)", false, false, true),
LEVER("lever", "使用拉杆", "是否可以使用拉杆", false, false, true),
MOB_DROP_ITEM("mob_drop_item", "生物战利品掉落", "生物死亡时是否产生掉落物", true, true, true),
MONSTER_KILLING("monster_killing", "对怪物造成伤害", "玩家是否可以对怪物造成伤害", false, false, true),

View File

@ -12,10 +12,8 @@ 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.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityTeleportEvent;
import org.bukkit.event.entity.*;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import java.util.Objects;
@ -27,17 +25,48 @@ public class EnvironmentEvents implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) // creeper_explode
public void onEntityExplode(EntityExplodeEvent event) {
Entity entity = event.getEntity();
if (entity.getType() != EntityType.CREEPER
&& entity.getType() != EntityType.WITHER_SKULL
&& entity.getType() != EntityType.FIREBALL
&& entity.getType() != EntityType.ENDER_CRYSTAL
) {
if (isExplodeEntity(entity)) {
return;
}
DominionDTO dom = Cache.instance.getDominionByLoc(event.getLocation());
checkFlag(dom, Flag.CREEPER_EXPLODE, event);
}
@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)) {
return;
}
DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation());
checkFlag(dom, Flag.CREEPER_EXPLODE, event);
}
@EventHandler(priority = EventPriority.HIGHEST) // creeper_explode - armor stand
public void onArmorStandExploded(EntityDamageByEntityEvent event) {
Entity entity = event.getEntity();
if (entity.getType() != EntityType.ARMOR_STAND) {
return;
}
Entity damager = event.getDamager();
if (!isExplodeEntity(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;
}
@EventHandler(priority = EventPriority.HIGHEST) // dragon_break_block
public void onDragonBreakBlock(EntityExplodeEvent event) {
Entity entity = event.getEntity();

View File

@ -16,6 +16,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityPlaceEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
@ -140,22 +141,42 @@ public class PlayerEvents implements Listener {
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.HIGHEST) // break - item frame && armor stand
@EventHandler(priority = EventPriority.HIGHEST) // break - item frame
public void onItemFrameBreak(HangingBreakByEntityEvent event) {
Entity entity = event.getEntity();
if (!(entity instanceof ItemFrame) && !(entity instanceof ArmorStand)) {
return;
}
Entity remover = event.getRemover();
if (!(remover instanceof Player)) {
return;
}
if (entity instanceof ItemFrame) {
if (((ItemFrame) entity).getItem().getType() != Material.AIR) {
if (!hasContainerPermission((Player) event.getRemover(), entity.getLocation())) {
event.setCancelled(true);
return;
}
}
}
if (onBreak((Player) event.getRemover(), entity.getLocation())) {
return;
}
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.HIGHEST) // break - armor stand
public void onArmorStandBreak(EntityDamageByEntityEvent event) {
Entity entity = event.getEntity();
if (!(entity instanceof ArmorStand)) {
return;
}
if (!(event.getDamager() instanceof Player)) {
return;
}
if (onBreak((Player) event.getDamager(), entity.getLocation())) {
return;
}
event.setCancelled(true);
}
public static boolean onBreak(Player player, Location location) {
DominionDTO dom = Cache.instance.getDominionByLoc(location);
return checkFlag(dom, Flag.BREAK_BLOCK, player, null);
@ -233,30 +254,38 @@ public class PlayerEvents implements Listener {
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.HIGHEST) // container item frame
@EventHandler(priority = EventPriority.HIGHEST) // container item frame put
public void putSomeOnItemFrame(PlayerInteractEntityEvent event) {
Entity entity = event.getRightClicked();
if (!(entity instanceof ItemFrame)) {
return;
}
ItemFrame itemFrame = (ItemFrame) entity;
if (itemFrame.getItem().getType() != Material.AIR) {
return;
}
Player bukkitPlayer = event.getPlayer();
if (hasContainerPermission(bukkitPlayer, event.getRightClicked().getLocation())) {
if (hasContainerPermission(bukkitPlayer, entity.getLocation())) {
return;
}
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.HIGHEST) // container item frame
@EventHandler(priority = EventPriority.HIGHEST) // container item frame get
public void removeSomeOnItemFrame(EntityDamageByEntityEvent event) {
Entity entity = event.getEntity();
if (!(entity instanceof ItemFrame)) {
return;
}
ItemFrame itemFrame = (ItemFrame) entity;
if (itemFrame.getItem().getType() == Material.AIR) {
return;
}
if (!(event.getDamager() instanceof Player)) {
return;
}
Player bukkitPlayer = (Player) event.getDamager();
if (hasContainerPermission(bukkitPlayer, event.getEntity().getLocation())) {
if (hasContainerPermission(bukkitPlayer, entity.getLocation())) {
return;
}
event.setCancelled(true);
@ -498,6 +527,22 @@ public class PlayerEvents implements Listener {
checkFlag(dom, Flag.IGNITE, player, event);
}
@EventHandler(priority = EventPriority.HIGHEST) // item_frame_interactive
public void onItemFrameInteractive(PlayerInteractEntityEvent event) {
Entity entity = event.getRightClicked();
if (!(entity instanceof ItemFrame)) {
return;
}
ItemFrame itemFrame = (ItemFrame) entity;
if (itemFrame.getItem().getType() == Material.AIR) {
// 为空则当作容器处理见 putSomeOnItemFrame
return;
}
Player player = event.getPlayer();
DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation());
checkFlag(dom, Flag.ITEM_FRAME_INTERACTIVE, player, event);
}
@EventHandler(priority = EventPriority.HIGHEST) // lever
public void onLever(PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {