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

Commit e6559a4

Browse files
committed
Added protection to the vault where hoppers cannot be placed to use the vault as infinite storage.
1 parent c368e19 commit e6559a4

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java

+42-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ public void onVaultPlace(BlockPlaceEvent e) {
145145
continue;
146146
}
147147

148-
if (blockLoc.getBlock().getType() == Material.CHEST) {
148+
Material blockMaterial = blockLoc.getBlock().getType();
149+
150+
if (blockMaterial == Material.CHEST || (P.p.getConfig().getBoolean("fvault.No-Hoppers-near-vault") && blockMaterial == Material.HOPPER)) {
149151
e.setCancelled(true);
150152
fme.msg(TL.COMMAND_GETVAULT_CHESTNEAR);
151153
return;
@@ -161,6 +163,45 @@ public void onVaultPlace(BlockPlaceEvent e) {
161163
}
162164
}
163165

166+
@EventHandler
167+
public void onHopperPlace(BlockPlaceEvent e) {
168+
169+
if (e.getItemInHand().getType() != Material.HOPPER && !P.p.getConfig().getBoolean("fvault.No-Hoppers-near-vault")) {
170+
return;
171+
}
172+
173+
Faction factionAt = Board.getInstance().getFactionAt(new FLocation(e.getBlockPlaced().getLocation()));
174+
175+
if (factionAt.isWilderness() || factionAt.getVault() == null) {
176+
return;
177+
}
178+
179+
180+
FPlayer fme = FPlayers.getInstance().getByPlayer(e.getPlayer());
181+
182+
Block start = e.getBlockPlaced();
183+
int radius = 1;
184+
for (double x = start.getLocation().getX() - radius; x <= start.getLocation().getX() + radius; x++) {
185+
for (double y = start.getLocation().getY() - radius; y <= start.getLocation().getY() + radius; y++) {
186+
for (double z = start.getLocation().getZ() - radius; z <= start.getLocation().getZ() + radius; z++) {
187+
Location blockLoc = new Location(e.getPlayer().getWorld(), x, y, z);
188+
if (blockLoc.getX() == start.getLocation().getX() && blockLoc.getY() == start.getLocation().getY() && blockLoc.getZ() == start.getLocation().getZ()) {
189+
continue;
190+
}
191+
192+
if (blockLoc.getBlock().getType() == Material.CHEST) {
193+
if (factionAt.getVault().equals(blockLoc)) {
194+
e.setCancelled(true);
195+
fme.msg(TL.COMMAND_VAULT_NO_HOPPER);
196+
return;
197+
}
198+
}
199+
}
200+
}
201+
}
202+
203+
}
204+
164205
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
165206
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
166207
// if not a sticky piston, retraction should be fine

src/main/java/com/massivecraft/factions/zcore/util/TL.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,11 @@ public enum TL {
580580
COMMAND_VAULT_DESCRIPTION("Open your placed faction vault!"),
581581
COMMAND_VAULT_INVALID("&c&l[!]&7 Your vault was either&c claimed&7, &cbroken&7, or has&c not been&7 placed yet."),
582582
COMMAND_VAULT_OPENING("&c&l[!]&7 Opening faction vault."),
583+
COMMAND_VAULT_NO_HOPPER("&c&l[!] &7You cannot place a hopper near a vault!"),
583584

584585
COMMAND_GETVAULT_ALREADYSET("&c&l[!]&7 Vault has already been set!"),
585586
COMMAND_GETVAULT_ALREADYHAVE("&c&l[!]&7 You already have a vault in your inventory!"),
586-
COMMAND_GETVAULT_CHESTNEAR("&c&l[!]&7 &7There is a chest &cnearby"),
587+
COMMAND_GETVAULT_CHESTNEAR("&c&l[!]&7 &7There is a chest or hopper &cnearby"),
587588
COMMAND_GETVAULT_SUCCESS("&cSucessfully set vault."),
588589
COMMAND_GETVAULT_INVALIDLOCATION("&cVault can only be placed in faction land!"),
589590
COMMAND_GETVAULT_DESCRIPTION("Get the faction vault item!"),

src/main/resources/config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ fnear:
721721
# +------------------------------------------------------+ #
722722
fvault:
723723
Enabled: true
724+
No-Hoppers-near-vault: true
724725
Price: 5000
725726
Item:
726727
Name: '&e&l*&f&l*&e&l* &e&lFaction Vault &7(Place) &e&l*&f&l*&e&l*'

0 commit comments

Comments
 (0)