From 90245ce5b6dd7dd13824998832136b7614a1d4ca Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Tue, 25 Jun 2024 10:37:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=8A=A8=E7=89=A9?= =?UTF-8?q?=E7=94=9F=E6=88=90=EF=BC=88=E7=B9=81=E6=AE=96=EF=BC=89=E3=80=81?= =?UTF-8?q?=E5=AF=B9=E6=9D=91=E6=B0=91=E9=80=A0=E6=88=90=E4=BC=A4=E5=AE=B3?= =?UTF-8?q?=E3=80=81=E6=9D=91=E6=B0=91=E7=B9=81=E6=AE=96=EF=BC=8C=E4=B8=89?= =?UTF-8?q?=E7=A7=8D=E6=9D=83=E9=99=90=EF=BC=88=E8=A1=8C=E4=B8=BA=EF=BC=89?= =?UTF-8?q?=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../java/cn/lunadeer/dominion/dtos/Flag.java | 6 +++-- .../dominion/events/EnvironmentEvents.java | 10 +++++++++ .../dominion/events/PlayerEvents.java | 22 ++++++++++++++++--- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index e136f64a..ed507ed2 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ cn.lunadeer Dominion - 1.33.5-beta + 1.33.6-beta jar Dominion diff --git a/src/main/java/cn/lunadeer/dominion/dtos/Flag.java b/src/main/java/cn/lunadeer/dominion/dtos/Flag.java index f658ad44..974150b7 100644 --- a/src/main/java/cn/lunadeer/dominion/dtos/Flag.java +++ b/src/main/java/cn/lunadeer/dominion/dtos/Flag.java @@ -15,7 +15,7 @@ public enum Flag { ANCHOR("anchor", "重生锚", "是否允许设置重生锚", false, false, true), ANIMAL_KILLING("animal_killing", "对动物造成伤害", "是否允许对动物造成伤害", false, false, true), - ANIMAL_SPAWN("animal_spawn", "动物生成", "是否允许动物生成", true, true, false), + ANIMAL_SPAWN("animal_spawn", "动物生成(繁殖)", "是否允许动物生成(包括繁殖)", true, true, false), ANVIL("anvil", "使用铁砧", "是否允许使用铁砧", false, false, true), BEACON("beacon", "信标交互", "是否允许与信标交互", false, false, true), BED("bed", "床交互", "是否允许使用床睡觉或设置重生点", false, false, true), @@ -34,7 +34,7 @@ public enum Flag { ENCHANT("enchant", "使用附魔台", "是否可以使用附魔台", false, false, true), ENDER_MAN("ender_man", "末影人行为", "包含:末影人是否可以生成、瞬移", false, true, true), ENDER_PEARL("ender_pearl", "投掷末影珍珠", "是否可以使用末影珍珠", false, false, true), - FEED("feed", "喂养", "是否可以喂养动物", false, false, true), + FEED("feed", "喂养动物", "是否可以喂养动物", false, false, true), FIRE_SPREAD("fire_spread", "火焰蔓延", "是否可以火焰蔓延", false, true, true), FLOW_IN_PROTECTION("flow_in_protection", "外部流体是否可以进入", "包含:岩浆、水(不会阻止领地内部的流体蔓延)", false, true, true), FLY("fly", "飞行", "不是翅鞘飞行,是类似于创造模式的飞行", false, false, false), @@ -62,6 +62,8 @@ public enum Flag { TRAMPLE("trample", "作物践踏", "是否可以践踏作物(关闭意味着保护耕地)", false, true, true), VEHICLE_DESTROY("vehicle_destroy", "破坏载具", "是否可以破坏载具(主要是矿车)", false, false, true), VEHICLE_SPAWN("vehicle_spawn", "生成载具", "是否可以生成载具(主要是矿车)", false, false, true), + VILLAGER_KILLING("villager_killing", "对村民造成伤害", "是否可以对村民造成伤害", false, false, true), + VILLAGER_SPAWN("villager_spawn", "村民繁殖", "是否允许村民繁殖", true, true, true), WITHER_SPAWN("wither_spawn", "凋零生成", "凋零生成", false, true, true), ; private final String flag_name; diff --git a/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java b/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java index d71db237..3b72a915 100644 --- a/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java +++ b/src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java @@ -160,4 +160,14 @@ public void onAnimalSpawn(CreatureSpawnEvent event) { DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); checkFlag(dom, Flag.ANIMAL_SPAWN, event); } + + @EventHandler(priority = EventPriority.HIGHEST) // villager_spawn + public void onVillagerSpawn(CreatureSpawnEvent event) { + Entity entity = event.getEntity(); + if (entity.getType() != EntityType.VILLAGER) { + return; + } + DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); + checkFlag(dom, Flag.VILLAGER_SPAWN, event); + } } diff --git a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java index 764e59b4..351b884d 100644 --- a/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java +++ b/src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java @@ -25,6 +25,7 @@ import org.bukkit.event.player.*; import org.bukkit.event.vehicle.VehicleDestroyEvent; import org.bukkit.inventory.Inventory; +import org.bukkit.material.Colorable; import org.spigotmc.event.entity.EntityMountEvent; import static cn.lunadeer.dominion.events.Apis.checkFlag; @@ -316,9 +317,7 @@ public void doorUse(PlayerInteractEvent event) { public void dyeEvent(PlayerInteractEntityEvent event) { Player player = event.getPlayer(); Entity entity = event.getRightClicked(); - if (!(entity instanceof Sheep) - && !(entity instanceof Wolf) - && !(entity instanceof Cat)) { + if (!(entity instanceof Colorable)) { return; } DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); @@ -394,6 +393,10 @@ public void onFeedAnimal(PlayerInteractEntityEvent event) { if (!(event.getRightClicked() instanceof Animals)) { return; } + // if shearing sheep instead + if (event.getPlayer().getInventory().getItem(event.getHand()).getType() == Material.SHEARS) { + return; + } Player player = event.getPlayer(); DominionDTO dom = Cache.instance.getDominion(event.getRightClicked().getLocation()); checkFlag(dom, Flag.FEED, player, event); @@ -688,4 +691,17 @@ public void onVehicleSpawn(EntityPlaceEvent event) { DominionDTO dom = Cache.instance.getDominion(entity.getLocation()); checkFlag(dom, Flag.VEHICLE_SPAWN, player, event); } + + @EventHandler(priority = EventPriority.HIGHEST) // villager_killing + public void onVillagerKilling(EntityDamageByEntityEvent event) { + if (!(event.getDamager() instanceof Player)) { + return; + } + if (!(event.getEntity() instanceof Villager)) { + return; + } + Player player = (Player) event.getDamager(); + DominionDTO dom = Cache.instance.getDominion(event.getEntity().getLocation()); + checkFlag(dom, Flag.VILLAGER_KILLING, player, event); + } }