Skip to content
This repository has been archived by the owner on Jul 7, 2023. It is now read-only.

Commit

Permalink
Added protection to the vault where hoppers cannot be placed to use t…
Browse files Browse the repository at this point in the history
…he vault as infinite storage.
  • Loading branch information
prosavage committed Jul 26, 2018
1 parent c368e19 commit e6559a4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ public void onVaultPlace(BlockPlaceEvent e) {
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;
Expand All @@ -161,6 +163,45 @@ public void onVaultPlace(BlockPlaceEvent e) {
}
}

@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
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/massivecraft/factions/zcore/util/TL.java
Original file line number Diff line number Diff line change
Expand Up @@ -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!"),
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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*'
Expand Down

0 comments on commit e6559a4

Please sign in to comment.