mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-07 07:51:41 +01:00
protects 1.14 blocks
https://github.com/BentoBoxWorld/BentoBox/issues/732
This commit is contained in:
parent
88a3ebbf2a
commit
7f2d7ab03b
@ -1,5 +1,8 @@
|
|||||||
package world.bentobox.bentobox.listeners.flags.protection;
|
package world.bentobox.bentobox.listeners.flags.protection;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -11,18 +14,37 @@ import org.bukkit.event.block.Action;
|
|||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.block.BlockFromToEvent;
|
import org.bukkit.event.block.BlockFromToEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
|
import world.bentobox.bentobox.BentoBox;
|
||||||
|
import world.bentobox.bentobox.api.flags.Flag;
|
||||||
import world.bentobox.bentobox.api.flags.FlagListener;
|
import world.bentobox.bentobox.api.flags.FlagListener;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
import world.bentobox.bentobox.lists.Flags;
|
import world.bentobox.bentobox.lists.Flags;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle interaction with blocks
|
* Handle interaction with blocks
|
||||||
* @author tastybento
|
* @author tastybento
|
||||||
*/
|
*/
|
||||||
public class BlockInteractionListener extends FlagListener {
|
public class BlockInteractionListener extends FlagListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* These cover materials in another server version.
|
||||||
|
* This avoids run time errors due to unknown enum values, at the expense of a string comparison
|
||||||
|
*/
|
||||||
|
Map<String, String> STRING_FLAGS = ImmutableMap.<String, String>builder()
|
||||||
|
.put("CAMPFIRE", "FURNACE")
|
||||||
|
.put("CARTOGRAPHY_TABLE", "CRAFTING")
|
||||||
|
.put("GRINDSTONE", "CRAFTING")
|
||||||
|
.put("LECTERN", "BREAK_BLOCKS")
|
||||||
|
.put("LOOM", "CRAFTING")
|
||||||
|
.put("STONECUTTER", "CRAFTING")
|
||||||
|
.put("SMOKER", "FURNACE")
|
||||||
|
.put("BLAST_FURNACE", "FURNACE")
|
||||||
|
.put("COMPOSTER", "CONTAINER")
|
||||||
|
.build();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle interaction with blocks
|
* Handle interaction with blocks
|
||||||
* @param e - event
|
* @param e - event
|
||||||
@ -36,7 +58,7 @@ public class BlockInteractionListener extends FlagListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, we just don't care about the RIGHT_CLICK_BLOCK action.
|
// We only care about the RIGHT_CLICK_BLOCK action.
|
||||||
if (!e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
if (!e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -263,8 +285,10 @@ public class BlockInteractionListener extends FlagListener {
|
|||||||
checkIsland(e, player, loc, Flags.ITEM_FRAME);
|
checkIsland(e, player, loc, Flags.ITEM_FRAME);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
if (STRING_FLAGS.containsKey(type.name())) {
|
||||||
|
Optional<Flag> f = BentoBox.getInstance().getFlagsManager().getFlag(STRING_FLAGS.get(type.name()));
|
||||||
|
if (f.isPresent()) checkIsland(e, player, loc, f.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,16 +2,13 @@ package world.bentobox.bentobox.listeners.flags.protection;
|
|||||||
|
|
||||||
import org.bukkit.block.Beacon;
|
import org.bukkit.block.Beacon;
|
||||||
import org.bukkit.block.BrewingStand;
|
import org.bukkit.block.BrewingStand;
|
||||||
import org.bukkit.block.Chest;
|
|
||||||
import org.bukkit.block.Dispenser;
|
import org.bukkit.block.Dispenser;
|
||||||
import org.bukkit.block.Dropper;
|
import org.bukkit.block.Dropper;
|
||||||
import org.bukkit.block.Furnace;
|
import org.bukkit.block.Furnace;
|
||||||
import org.bukkit.block.Hopper;
|
import org.bukkit.block.Hopper;
|
||||||
import org.bukkit.block.ShulkerBox;
|
|
||||||
import org.bukkit.entity.Animals;
|
import org.bukkit.entity.Animals;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.minecart.HopperMinecart;
|
import org.bukkit.entity.minecart.HopperMinecart;
|
||||||
import org.bukkit.entity.minecart.StorageMinecart;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
@ -32,19 +29,15 @@ public class InventoryListener extends FlagListener {
|
|||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
|
||||||
public void onInventoryClick(InventoryClickEvent e) {
|
public void onInventoryClick(InventoryClickEvent e) {
|
||||||
|
Player player = (Player)e.getWhoClicked();
|
||||||
|
|
||||||
InventoryHolder inventoryHolder = e.getInventory().getHolder();
|
InventoryHolder inventoryHolder = e.getInventory().getHolder();
|
||||||
if (inventoryHolder == null || !(e.getWhoClicked() instanceof Player)) {
|
if (inventoryHolder == null || !(e.getWhoClicked() instanceof Player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Player player = (Player)e.getWhoClicked();
|
|
||||||
if (inventoryHolder instanceof Animals) {
|
if (inventoryHolder instanceof Animals) {
|
||||||
checkIsland(e, player, e.getInventory().getLocation(), Flags.MOUNT_INVENTORY);
|
checkIsland(e, player, e.getInventory().getLocation(), Flags.MOUNT_INVENTORY);
|
||||||
}
|
}
|
||||||
else if (inventoryHolder instanceof Chest
|
|
||||||
|| inventoryHolder instanceof ShulkerBox
|
|
||||||
|| inventoryHolder instanceof StorageMinecart) {
|
|
||||||
checkIsland(e, player, e.getInventory().getLocation(), Flags.CONTAINER);
|
|
||||||
}
|
|
||||||
else if (inventoryHolder instanceof Dispenser) {
|
else if (inventoryHolder instanceof Dispenser) {
|
||||||
checkIsland(e, player, e.getInventory().getLocation(), Flags.DISPENSER);
|
checkIsland(e, player, e.getInventory().getLocation(), Flags.DISPENSER);
|
||||||
}
|
}
|
||||||
@ -52,7 +45,7 @@ public class InventoryListener extends FlagListener {
|
|||||||
checkIsland(e, player, e.getInventory().getLocation(), Flags.DROPPER);
|
checkIsland(e, player, e.getInventory().getLocation(), Flags.DROPPER);
|
||||||
}
|
}
|
||||||
else if (inventoryHolder instanceof Hopper
|
else if (inventoryHolder instanceof Hopper
|
||||||
|| inventoryHolder instanceof HopperMinecart) {
|
|| inventoryHolder instanceof HopperMinecart) {
|
||||||
checkIsland(e, player, e.getInventory().getLocation(), Flags.HOPPER);
|
checkIsland(e, player, e.getInventory().getLocation(), Flags.HOPPER);
|
||||||
}
|
}
|
||||||
else if (inventoryHolder instanceof Furnace) {
|
else if (inventoryHolder instanceof Furnace) {
|
||||||
@ -64,5 +57,9 @@ public class InventoryListener extends FlagListener {
|
|||||||
else if (inventoryHolder instanceof Beacon) {
|
else if (inventoryHolder instanceof Beacon) {
|
||||||
checkIsland(e, player, e.getInventory().getLocation(), Flags.BEACON);
|
checkIsland(e, player, e.getInventory().getLocation(), Flags.BEACON);
|
||||||
}
|
}
|
||||||
|
else if (!(inventoryHolder instanceof Player)) {
|
||||||
|
// All other containers
|
||||||
|
checkIsland(e, player, e.getInventory().getLocation(), Flags.CONTAINER);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -232,7 +232,7 @@ public class IslandsManager {
|
|||||||
// Check that the space is not solid
|
// Check that the space is not solid
|
||||||
// The isSolid function is not fully accurate (yet) so we have to check a few other items
|
// The isSolid function is not fully accurate (yet) so we have to check a few other items
|
||||||
// isSolid thinks that PLATEs and SIGNS are solid, but they are not
|
// isSolid thinks that PLATEs and SIGNS are solid, but they are not
|
||||||
return (!space1.getType().isSolid() || space1.getType().toString().contains("SIGN")) && (!space2.getType().isSolid() || space2.getType().equals(Material.SIGN) || space2.getType().equals(Material.WALL_SIGN));
|
return (!space1.getType().isSolid() || space1.getType().toString().contains("SIGN")) && (!space2.getType().isSolid() || space2.getType().toString().contains("SIGN"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user