Improve hopper protection

The InventoryMoveItemEvent is now only used for Hopper Minecarts, other blocks that could move items (Hoppers and Droppers) are checked on place. That way players that have access to a shop can just use the blocks normally but other players can't place them.
This commit is contained in:
Phoenix616 2018-10-23 19:27:39 +01:00
parent fe85dafec5
commit 7adf02e532
3 changed files with 19 additions and 4 deletions

View File

@ -177,7 +177,7 @@ public class Properties {
@ConfigurationComment("Do you want to turn off the default sign protection? Warning! Other players will be able to destroy other people's shops!")
public static boolean TURN_OFF_SIGN_PROTECTION = false;
@ConfigurationComment("Do you want to disable the hopper protection, which prevents the hoppers from taking items out of chests?")
@ConfigurationComment("Do you want to disable the hopper protection, which prevents Hopper-Minecarts from taking items out of shops?")
public static boolean TURN_OFF_HOPPER_PROTECTION = false;
@ConfigurationComment("Do you want to protect shop chests with LWC?")

View File

@ -8,16 +8,19 @@ import com.Acrobot.ChestShop.Utils.uBlock;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Directional;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import java.util.ArrayList;
import java.util.List;
/**
* @author Acrobot
*/
public class BlockPlace implements Listener {
private static BlockFace[] SEARCH_DIRECTIONS = {BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.UP, BlockFace.DOWN};
@EventHandler(ignoreCancelled = true)
public static void onContainerPlace(BlockPlaceEvent event) {
@ -66,7 +69,18 @@ public class BlockPlace implements Listener {
return;
}
for (BlockFace face : SEARCH_DIRECTIONS) {
List<BlockFace> searchDirections = new ArrayList<>();
switch (placed.getType()) {
case HOPPER:
searchDirections.add(BlockFace.UP);
searchDirections.add(((Directional) placed.getBlockData()).getFacing());
break;
case DROPPER:
searchDirections.add(((Directional) placed.getBlockData()).getFacing());
break;
}
for (BlockFace face : searchDirections) {
Block relative = placed.getRelative(face);
if (!uBlock.couldBeShopContainer(relative)) {

View File

@ -1,6 +1,7 @@
package com.Acrobot.ChestShop.Listeners.Item;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import org.bukkit.block.BlockState;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -13,7 +14,7 @@ public class ItemMoveListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public static void onItemMove(InventoryMoveItemEvent event) {
if (event.getSource() == null) {
if (event.getSource() == null || event.getDestination().getHolder() instanceof BlockState) {
return;
}