Skip to content

Commit

Permalink
新增:动物生成(繁殖)、对村民造成伤害、村民繁殖,三种权限(行为)控制
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdeZhang committed Jun 25, 2024
1 parent 570ea0c commit 90245ce
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 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.33.5-beta</version>
<version>1.33.6-beta</version>
<packaging>jar</packaging>

<name>Dominion</name>
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/cn/lunadeer/dominion/dtos/Flag.java
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/cn/lunadeer/dominion/events/EnvironmentEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
22 changes: 19 additions & 3 deletions src/main/java/cn/lunadeer/dominion/events/PlayerEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 90245ce

Please sign in to comment.