新增权限:投掷物触发压力板

新增权限:生物触发压力板
新增权限:掉落物触发压力板
新增权限:投掷物是否可以破坏展示框/画
This commit is contained in:
zhangyuheng 2024-08-02 10:19:24 +08:00
parent 36a32c1d7b
commit 86fe23421f
4 changed files with 65 additions and 24 deletions

View File

@ -5,7 +5,7 @@ plugins {
}
group = "cn.lunadeer"
version = "1.43.0-beta"
version = "1.44.0-beta"
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))

View File

@ -48,6 +48,7 @@ public enum Flag {
HOPPER("hopper", "特殊容器", "包含:漏斗/熔炉/发射器/投掷器/高炉/烟熏炉", false, false, true),
IGNITE("ignite", "点燃", "是否可以使用打火石点火", false, false, true),
ITEM_FRAME_INTERACTIVE("item_frame_interactive", "展示框交互", "是否可以与物品展示框交互(旋转展示框的东西)", false, false, true),
ITEM_FRAME_PROJ_DAMAGE("item_frame_proj_damage", "投掷物是否可以破坏展示框/画", "非玩家发出的投掷物是否可以破坏展示框/画等悬挂物", false, true, true),
LEVER("lever", "使用拉杆", "是否可以使用拉杆", false, false, true),
MOB_DROP_ITEM("mob_drop_item", "生物战利品掉落", "生物死亡时是否产生掉落物", true, true, true),
MONSTER_KILLING("monster_killing", "对怪物造成伤害", "玩家是否可以对怪物造成伤害", false, false, true),
@ -59,12 +60,15 @@ public enum Flag {
RIDING("riding", "骑乘载具", "是否可以骑乘各种载具", false, false, true),
REPEATER("repeater", "中继器交互", "是否可以与中继器交互", false, false, true),
SHEAR("shear", "剪羊毛", "是否可以剪羊毛", false, false, true),
SHOOT("shoot", "发射类型武器", "包括:射箭/雪球/三叉戟", false, false, true),
SHOOT("shoot", "投掷型武器", "包括:射箭/雪球/三叉戟/风弹", false, false, true),
SHOW_BORDER("show_border", "显示领地边界", "是否显示领地边界", true, true, true),
TELEPORT("teleport", "领地传送", "是否开启领地传送", false, false, true),
TNT_EXPLODE("tnt_explode", "TNT爆炸", "TNT是否可以爆炸", false, true, true),
TRADE("trade", "村民交易", "是否可以与村民交易", false, false, true),
TRAMPLE("trample", "作物践踏", "是否可以践踏作物(关闭意味着保护耕地)", false, true, true),
TRIG_PRESSURE_PROJ("trig_pressure_proj", "投掷物触发压力板", "投掷物(箭/风弹/雪球)是否可以触发压力板", false, true, true),
TRIG_PRESSURE_MOB("trig_pressure_mob", "生物触发压力板", "生物(不包含玩家)是否可以触发压力板", false, true, true),
TRIG_PRESSURE_DROP("trig_pressure_drop", "掉落物触发压力板", "掉落物是否可以触发压力板", false, true, true),
VEHICLE_DESTROY("vehicle_destroy", "破坏载具", "是否可以破坏载具(主要是矿车)", false, false, true),
VEHICLE_SPAWN("vehicle_spawn", "生成载具", "是否可以生成载具(主要是矿车)", false, false, true),
VILLAGER_KILLING("villager_killing", "对村民造成伤害", "是否可以对村民造成伤害", false, false, true),

View File

@ -5,6 +5,7 @@ import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.minecraftpluginutils.XLogger;
import org.bukkit.Location;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
@ -17,6 +18,8 @@ import org.bukkit.event.entity.*;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.material.PressurePlate;
import org.bukkit.material.PressureSensor;
import java.util.Objects;
@ -61,22 +64,21 @@ public class EnvironmentEvents implements Listener {
checkFlag(dom, Flag.CREEPER_EXPLODE, event);
}
@EventHandler(priority = EventPriority.HIGHEST) // creeper_explode - other projectiles
public void removeSomeOnItemFrameByArrow(EntityDamageByEntityEvent event) {
Entity entity = event.getEntity();
if (!(entity instanceof ItemFrame)) {
@EventHandler(priority = EventPriority.HIGHEST) // item_frame_proj_damage
public void removeSomeOnItemFrameByArrow(HangingBreakByEntityEvent event) {
if (event.getCause() != HangingBreakEvent.RemoveCause.ENTITY) {
return;
}
ItemFrame itemFrame = (ItemFrame) entity;
if (!(event.getDamager() instanceof Projectile)) {
Entity remover = event.getRemover();
if (!(remover instanceof Projectile projectile)) {
return;
}
Projectile arrow = (Projectile) event.getDamager();
if (arrow.getShooter() instanceof Player) {
if (!(projectile.getShooter() instanceof Player)) {
// 玩家破坏由 玩家 break 权限控制
return;
}
DominionDTO dom = Cache.instance.getDominionByLoc(itemFrame.getLocation());
checkFlag(dom, Flag.CREEPER_EXPLODE, event);
DominionDTO dom = Cache.instance.getDominionByLoc(event.getEntity().getLocation());
checkFlag(dom, Flag.ITEM_FRAME_PROJ_DAMAGE, event);
}
private static boolean isNotExplodeEntity(Entity damager) {
@ -187,6 +189,50 @@ public class EnvironmentEvents implements Listener {
checkFlag(dom, Flag.TRAMPLE, event);
}
/*
TRIG_PRESSURE_PROJ("trig_pressure_proj", "投掷物触发压力板", "投掷物(箭/风弹/雪球)是否可以触发压力板", false, true, true),
TRIG_PRESSURE_MOB("trig_pressure_mob", "生物触发压力板", "生物(不包含玩家)是否可以触发压力板", false, true, true),
TRIG_PRESSURE_DROP("trig_pressure_drop", "掉落物触发压力板", "掉落物是否可以触发压力板", false, true, true),
*/
@EventHandler(priority = EventPriority.HIGHEST) // trig_pressure_proj
public void onPressurePlateTriggeredByProjectile(EntityInteractEvent event) {
if (!(event.getEntity() instanceof Projectile)) {
return;
}
Block block = event.getBlock();
if (!Tag.PRESSURE_PLATES.isTagged(block.getType())) {
return;
}
DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation());
checkFlag(dom, Flag.TRIG_PRESSURE_PROJ, event);
}
@EventHandler(priority = EventPriority.HIGHEST) // trig_pressure_mob
public void onPressurePlateTriggeredByMob(EntityInteractEvent event) {
if (!(event.getEntity() instanceof Mob)) {
return;
}
Block block = event.getBlock();
if (!Tag.PRESSURE_PLATES.isTagged(block.getType())) {
return;
}
DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation());
checkFlag(dom, Flag.TRIG_PRESSURE_MOB, event);
}
@EventHandler(priority = EventPriority.HIGHEST) // trig_pressure_drop
public void onPressurePlateTriggeredByDrop(EntityInteractEvent event) {
if (!(event.getEntity() instanceof Item)) {
return;
}
Block block = event.getBlock();
if (!Tag.PRESSURE_PLATES.isTagged(block.getType())) {
return;
}
DominionDTO dom = Cache.instance.getDominionByLoc(block.getLocation());
checkFlag(dom, Flag.TRIG_PRESSURE_DROP, event);
}
@EventHandler(priority = EventPriority.HIGHEST) // wither_spawn
public void onWitherSpawn(CreatureSpawnEvent event) {
Entity entity = event.getEntity();

View File

@ -15,10 +15,7 @@ import org.bukkit.event.EventHandler;
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.EntityMountEvent;
import org.bukkit.event.entity.EntityPlaceEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.entity.*;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
@ -748,16 +745,10 @@ public class PlayerEvents implements Listener {
}
@EventHandler(priority = EventPriority.HIGHEST) // shoot
public void onShootArrowSnowball(ProjectileLaunchEvent event) {
if (!(event.getEntity().getShooter() instanceof Player)) {
public void onShootArrowSnowball(ProjectileHitEvent event) {
if (!(event.getEntity().getShooter() instanceof Player player)) {
return;
}
if (event.getEntity().getType() != EntityType.ARROW &&
event.getEntity().getType() != EntityType.SNOWBALL &&
event.getEntity().getType() != EntityType.TRIDENT) {
return;
}
Player player = (Player) event.getEntity().getShooter();
DominionDTO dom = Cache.instance.getPlayerCurrentDominion(player);
checkFlag(dom, Flag.SHOOT, player, event);
}