Removed donation chests option.

This isn't an anti-grief feature, so it belongs in an extension plugin.
This commit is contained in:
ryanhamshire 2014-10-13 13:53:18 -07:00
parent ac657d8a5f
commit b016ad14e7
2 changed files with 0 additions and 87 deletions

View File

@ -79,89 +79,6 @@ public class BlockEventHandler implements Listener
this.trashBlocks.add(Material.WORKBENCH); this.trashBlocks.add(Material.WORKBENCH);
} }
//when a block is damaged...
@EventHandler(ignoreCancelled = true)
public void onBlockDamaged(BlockDamageEvent event)
{
//if placing items in protected chests isn't enabled, none of this code needs to run
if(!GriefPrevention.instance.config_addItemsToClaimedChests) return;
Block block = event.getBlock();
Player player = event.getPlayer();
//only care about player-damaged blocks
if(player == null) return;
//FEATURE: players may add items to a chest they don't have permission for by hitting it
//if it's a chest
if(block.getType() == Material.CHEST)
{
//only care about non-creative mode players, since those would outright break the box in one hit
if(player.getGameMode() == GameMode.CREATIVE) return;
//only care if the player has an itemstack in hand
PlayerInventory playerInventory = player.getInventory();
ItemStack stackInHand = playerInventory.getItemInHand();
if(stackInHand == null || stackInHand.getType() == Material.AIR) return;
//only care if the chest is in a claim, and the player does not have access to the chest
Claim claim = this.dataStore.getClaimAt(block.getLocation(), false, null);
if(claim == null || claim.allowContainers(player) == null) return;
//if the player is under siege, he can't give away items
PlayerData playerData = this.dataStore.getPlayerData(event.getPlayer().getUniqueId());
if(playerData.siegeData != null)
{
GriefPrevention.sendMessage(player, TextMode.Err, Messages.SiegeNoDrop);
event.setCancelled(true);
return;
}
//if a player is in pvp combat, he can't give away items
if(playerData.inPvpCombat()) return;
//NOTE: to eliminate accidental give-aways, first hit on a chest displays a confirmation message
//subsequent hits donate item to the chest
//if first time damaging this chest, show confirmation message
if(playerData.lastChestDamageLocation == null || !block.getLocation().equals(playerData.lastChestDamageLocation))
{
//remember this location
playerData.lastChestDamageLocation = block.getLocation();
//give the player instructions
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.DonateItemsInstruction);
}
//otherwise, try to donate the item stack in hand
else
{
//look for empty slot in chest
Chest chest = (Chest)block.getState();
Inventory chestInventory = chest.getInventory();
int availableSlot = chestInventory.firstEmpty();
//if there isn't one
if(availableSlot < 0)
{
//tell the player and stop here
GriefPrevention.sendMessage(player, TextMode.Err, Messages.ChestFull);
return;
}
//otherwise, transfer item stack from player to chest
//NOTE: Inventory.addItem() is smart enough to add items to existing stacks, making filling a chest with garbage as a grief very difficult
chestInventory.addItem(stackInHand);
playerInventory.setItemInHand(new ItemStack(Material.AIR));
//and confirm for the player
GriefPrevention.sendMessage(player, TextMode.Success, Messages.DonationSuccess);
}
}
}
//when a player breaks a block... //when a player breaks a block...
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onBlockBreak(BlockBreakEvent breakEvent) public void onBlockBreak(BlockBreakEvent breakEvent)

View File

@ -130,7 +130,6 @@ public class GriefPrevention extends JavaPlugin
public boolean config_fireSpreads; //whether fire spreads outside of claims public boolean config_fireSpreads; //whether fire spreads outside of claims
public boolean config_fireDestroys; //whether fire destroys blocks outside of claims public boolean config_fireDestroys; //whether fire destroys blocks outside of claims
public boolean config_addItemsToClaimedChests; //whether players may add items to claimed chests by left-clicking them
public boolean config_eavesdrop; //whether whispered messages will be visible to administrators public boolean config_eavesdrop; //whether whispered messages will be visible to administrators
public ArrayList<String> config_eavesdrop_whisperCommands; //list of whisper commands to eavesdrop on public ArrayList<String> config_eavesdrop_whisperCommands; //list of whisper commands to eavesdrop on
@ -351,7 +350,6 @@ public class GriefPrevention extends JavaPlugin
this.config_fireSpreads = config.getBoolean("GriefPrevention.FireSpreads", false); this.config_fireSpreads = config.getBoolean("GriefPrevention.FireSpreads", false);
this.config_fireDestroys = config.getBoolean("GriefPrevention.FireDestroys", false); this.config_fireDestroys = config.getBoolean("GriefPrevention.FireDestroys", false);
this.config_addItemsToClaimedChests = config.getBoolean("GriefPrevention.AddItemsToClaimedChests", true);
this.config_eavesdrop = config.getBoolean("GriefPrevention.EavesdropEnabled", false); this.config_eavesdrop = config.getBoolean("GriefPrevention.EavesdropEnabled", false);
String whisperCommandsToMonitor = config.getString("GriefPrevention.WhisperCommands", "/tell;/pm;/r"); String whisperCommandsToMonitor = config.getString("GriefPrevention.WhisperCommands", "/tell;/pm;/r");
@ -596,8 +594,6 @@ public class GriefPrevention extends JavaPlugin
outConfig.set("GriefPrevention.FireSpreads", this.config_fireSpreads); outConfig.set("GriefPrevention.FireSpreads", this.config_fireSpreads);
outConfig.set("GriefPrevention.FireDestroys", this.config_fireDestroys); outConfig.set("GriefPrevention.FireDestroys", this.config_fireDestroys);
outConfig.set("GriefPrevention.AddItemsToClaimedChests", this.config_addItemsToClaimedChests);
outConfig.set("GriefPrevention.EavesdropEnabled", this.config_eavesdrop); outConfig.set("GriefPrevention.EavesdropEnabled", this.config_eavesdrop);
outConfig.set("GriefPrevention.WhisperCommands", whisperCommandsToMonitor); outConfig.set("GriefPrevention.WhisperCommands", whisperCommandsToMonitor);
outConfig.set("GriefPrevention.SmartBan", this.config_smartBan); outConfig.set("GriefPrevention.SmartBan", this.config_smartBan);