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;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
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.BlockFromToEvent;
|
||||
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.database.objects.Island;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Handle interaction with blocks
|
||||
* @author tastybento
|
||||
*/
|
||||
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
|
||||
* @param e - event
|
||||
@ -36,7 +58,7 @@ public class BlockInteractionListener extends FlagListener {
|
||||
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)) {
|
||||
return;
|
||||
}
|
||||
@ -263,8 +285,10 @@ public class BlockInteractionListener extends FlagListener {
|
||||
checkIsland(e, player, loc, Flags.ITEM_FRAME);
|
||||
break;
|
||||
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.BrewingStand;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.Dispenser;
|
||||
import org.bukkit.block.Dropper;
|
||||
import org.bukkit.block.Furnace;
|
||||
import org.bukkit.block.Hopper;
|
||||
import org.bukkit.block.ShulkerBox;
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.minecart.HopperMinecart;
|
||||
import org.bukkit.entity.minecart.StorageMinecart;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
@ -32,19 +29,15 @@ public class InventoryListener extends FlagListener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
|
||||
public void onInventoryClick(InventoryClickEvent e) {
|
||||
Player player = (Player)e.getWhoClicked();
|
||||
|
||||
InventoryHolder inventoryHolder = e.getInventory().getHolder();
|
||||
if (inventoryHolder == null || !(e.getWhoClicked() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player)e.getWhoClicked();
|
||||
if (inventoryHolder instanceof Animals) {
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
else if (inventoryHolder instanceof Hopper
|
||||
|| inventoryHolder instanceof HopperMinecart) {
|
||||
|| inventoryHolder instanceof HopperMinecart) {
|
||||
checkIsland(e, player, e.getInventory().getLocation(), Flags.HOPPER);
|
||||
}
|
||||
else if (inventoryHolder instanceof Furnace) {
|
||||
@ -64,5 +57,9 @@ public class InventoryListener extends FlagListener {
|
||||
else if (inventoryHolder instanceof 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
|
||||
// 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
|
||||
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