Merge remote-tracking branch 'origin/master'

This commit is contained in:
zhangyuheng 2024-08-24 19:20:12 +08:00
commit 2e589287b5
3 changed files with 87 additions and 0 deletions

View File

@ -46,6 +46,7 @@ public enum Flag {
HONEY("honey", "蜂巢交互", "是否可以采蜂蜜", false, false, true),
HOOK("hook", "使用钓钩", "是否可以使用钓钩", false, false, true),
HOPPER("hopper", "特殊容器", "包含:漏斗/熔炉/发射器/投掷器/高炉/烟熏炉", false, false, true),
HOPPER_OUTSIDE("hopper_outside", "领地外漏斗对领地内箱子是否生效", "领地外的漏斗是否可以对领地内的箱子生效", false, true, 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),
@ -56,6 +57,7 @@ public enum Flag {
MOVE("move", "移动", "是否可以移动", true, false, true),
NOTE_BLOCK("note_block", "点击音符盒", "红石音乐或者某些红石机器会用到...", false, false, true),
PLACE("place", "放置方块", "是否可以放置方块(包括:一般方块、展示框、岩浆、水)", false, false, true),
PISTON_OUTSIDE("piston_outside", "活塞是否可以跨领地推动方块", "活塞是否可以往领地内推东西或推东西到领地外", false, true, true),
PRESSURE("pressure", "压力板交互", "是否可以触发各种材质的压力板", false, false, true),
RIDING("riding", "骑乘载具", "是否可以骑乘各种载具", false, false, true),
REPEATER("repeater", "中继器交互", "是否可以与中继器交互", false, false, true),

View File

@ -7,6 +7,7 @@ import cn.lunadeer.minecraftpluginutils.XLogger;
import org.bukkit.Location;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -14,10 +15,13 @@ 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.block.BlockPistonExtendEvent;
import org.bukkit.event.entity.*;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import java.util.Objects;
@ -305,4 +309,42 @@ public class EnvironmentEvents implements Listener {
DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation());
checkFlag(dom, Flag.VILLAGER_SPAWN, event);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onHopper(InventoryMoveItemEvent event) {
Inventory hopper = event.getDestination();
Inventory inventory = event.getSource();
DominionDTO hopperDom = Cache.instance.getDominionByLoc(hopper.getLocation());
DominionDTO inventoryDom = Cache.instance.getDominionByLoc(inventory.getLocation());
if (hopperDom == null && inventoryDom != null) {
checkFlag(inventoryDom, Flag.HOPPER_OUTSIDE, event);
}
if (hopperDom != null && inventoryDom != null) {
if (!hopperDom.getId().equals(inventoryDom.getId())) {
checkFlag(inventoryDom, Flag.HOPPER_OUTSIDE, event);
}
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPushedByPiston(BlockPistonExtendEvent event) {
Block piston = event.getBlock();
DominionDTO pistonDom = Cache.instance.getDominionByLoc(piston.getLocation());
BlockFace direction = event.getDirection();
Block endBlockAfterPush = piston.getRelative(direction, event.getBlocks().size() + 1);
DominionDTO endBlockDom = Cache.instance.getDominionByLoc(endBlockAfterPush.getLocation());
if (pistonDom != null && endBlockDom == null) {
checkFlag(pistonDom, Flag.PISTON_OUTSIDE, event);
}
if (pistonDom == null && endBlockDom != null) {
checkFlag(endBlockDom, Flag.PISTON_OUTSIDE, event);
}
if (pistonDom != null && endBlockDom != null) {
if (!pistonDom.getId().equals(endBlockDom.getId())) {
if (!endBlockDom.getFlagValue(Flag.PISTON_OUTSIDE) || !pistonDom.getFlagValue(Flag.PISTON_OUTSIDE)) {
event.setCancelled(true);
}
}
}
}
}

View File

@ -7,6 +7,7 @@ import cn.lunadeer.minecraftpluginutils.XLogger;
import org.bukkit.Location;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -14,10 +15,13 @@ 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.block.BlockPistonExtendEvent;
import org.bukkit.event.entity.*;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import java.util.Objects;
@ -305,4 +309,43 @@ public class EnvironmentEvents implements Listener {
DominionDTO dom = Cache.instance.getDominionByLoc(entity.getLocation());
checkFlag(dom, Flag.VILLAGER_SPAWN, event);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onHopper(InventoryMoveItemEvent event) {
Inventory hopper = event.getDestination();
Inventory inventory = event.getSource();
DominionDTO hopperDom = Cache.instance.getDominionByLoc(hopper.getLocation());
DominionDTO inventoryDom = Cache.instance.getDominionByLoc(inventory.getLocation());
if (hopperDom == null && inventoryDom != null) {
checkFlag(inventoryDom, Flag.HOPPER_OUTSIDE, event);
}
if (hopperDom != null && inventoryDom != null) {
if (!hopperDom.getId().equals(inventoryDom.getId())) {
checkFlag(inventoryDom, Flag.HOPPER_OUTSIDE, event);
}
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPushedByPiston(BlockPistonExtendEvent event) {
Block piston = event.getBlock();
DominionDTO pistonDom = Cache.instance.getDominionByLoc(piston.getLocation());
BlockFace direction = event.getDirection();
Block endBlockAfterPush = piston.getRelative(direction, event.getBlocks().size() + 1);
DominionDTO endBlockDom = Cache.instance.getDominionByLoc(endBlockAfterPush.getLocation());
if (pistonDom != null && endBlockDom == null) {
checkFlag(pistonDom, Flag.PISTON_OUTSIDE, event);
}
if (pistonDom == null && endBlockDom != null) {
checkFlag(endBlockDom, Flag.PISTON_OUTSIDE, event);
}
if (pistonDom != null && endBlockDom != null) {
if (!pistonDom.getId().equals(endBlockDom.getId())) {
if (!endBlockDom.getFlagValue(Flag.PISTON_OUTSIDE) || !pistonDom.getFlagValue(Flag.PISTON_OUTSIDE)) {
event.setCancelled(true);
}
}
}
}
}