新增:动物生成(繁殖)、对村民造成伤害、村民繁殖,三种权限(行为)控制
All checks were successful
Java CI-CD with Maven / build (push) Successful in 7m50s

This commit is contained in:
zhangyuheng 2024-06-25 10:37:21 +08:00
parent 570ea0c75c
commit 90245ce5b6
4 changed files with 34 additions and 6 deletions

View File

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

View File

@ -15,7 +15,7 @@ import java.util.List;
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;

View File

@ -160,4 +160,14 @@ public class EnvironmentEvents implements Listener {
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);
}
}

View File

@ -25,6 +25,7 @@ import org.bukkit.event.inventory.InventoryType;
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 class PlayerEvents implements Listener {
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 class PlayerEvents implements Listener {
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 class PlayerEvents implements Listener {
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);
}
}