diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java index ffd89b81..76ca5242 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java @@ -145,7 +145,9 @@ public class FactionsBlockListener implements Listener { continue; } - if (blockLoc.getBlock().getType() == Material.CHEST) { + Material blockMaterial = blockLoc.getBlock().getType(); + + if (blockMaterial == Material.CHEST || (P.p.getConfig().getBoolean("fvault.No-Hoppers-near-vault") && blockMaterial == Material.HOPPER)) { e.setCancelled(true); fme.msg(TL.COMMAND_GETVAULT_CHESTNEAR); return; @@ -161,6 +163,45 @@ public class FactionsBlockListener implements Listener { } } + @EventHandler + public void onHopperPlace(BlockPlaceEvent e) { + + if (e.getItemInHand().getType() != Material.HOPPER && !P.p.getConfig().getBoolean("fvault.No-Hoppers-near-vault")) { + return; + } + + Faction factionAt = Board.getInstance().getFactionAt(new FLocation(e.getBlockPlaced().getLocation())); + + if (factionAt.isWilderness() || factionAt.getVault() == null) { + return; + } + + + FPlayer fme = FPlayers.getInstance().getByPlayer(e.getPlayer()); + + Block start = e.getBlockPlaced(); + int radius = 1; + for (double x = start.getLocation().getX() - radius; x <= start.getLocation().getX() + radius; x++) { + for (double y = start.getLocation().getY() - radius; y <= start.getLocation().getY() + radius; y++) { + for (double z = start.getLocation().getZ() - radius; z <= start.getLocation().getZ() + radius; z++) { + Location blockLoc = new Location(e.getPlayer().getWorld(), x, y, z); + if (blockLoc.getX() == start.getLocation().getX() && blockLoc.getY() == start.getLocation().getY() && blockLoc.getZ() == start.getLocation().getZ()) { + continue; + } + + if (blockLoc.getBlock().getType() == Material.CHEST) { + if (factionAt.getVault().equals(blockLoc)) { + e.setCancelled(true); + fme.msg(TL.COMMAND_VAULT_NO_HOPPER); + return; + } + } + } + } + } + + } + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onBlockPistonRetract(BlockPistonRetractEvent event) { // if not a sticky piston, retraction should be fine diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TL.java b/src/main/java/com/massivecraft/factions/zcore/util/TL.java index 94fb7abf..508d47c2 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -580,10 +580,11 @@ public enum TL { COMMAND_VAULT_DESCRIPTION("Open your placed faction vault!"), COMMAND_VAULT_INVALID("&c&l[!]&7 Your vault was either&c claimed&7, &cbroken&7, or has&c not been&7 placed yet."), COMMAND_VAULT_OPENING("&c&l[!]&7 Opening faction vault."), + COMMAND_VAULT_NO_HOPPER("&c&l[!] &7You cannot place a hopper near a vault!"), COMMAND_GETVAULT_ALREADYSET("&c&l[!]&7 Vault has already been set!"), COMMAND_GETVAULT_ALREADYHAVE("&c&l[!]&7 You already have a vault in your inventory!"), - COMMAND_GETVAULT_CHESTNEAR("&c&l[!]&7 &7There is a chest &cnearby"), + COMMAND_GETVAULT_CHESTNEAR("&c&l[!]&7 &7There is a chest or hopper &cnearby"), COMMAND_GETVAULT_SUCCESS("&cSucessfully set vault."), COMMAND_GETVAULT_INVALIDLOCATION("&cVault can only be placed in faction land!"), COMMAND_GETVAULT_DESCRIPTION("Get the faction vault item!"), diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 835d9ba0..d30df7b4 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -721,6 +721,7 @@ fnear: # +------------------------------------------------------+ # fvault: Enabled: true + No-Hoppers-near-vault: true Price: 5000 Item: Name: '&e&l*&f&l*&e&l* &e&lFaction Vault &7(Place) &e&l*&f&l*&e&l*'