From 136bf91c8a8a72a499be57b11d04af70e866d977 Mon Sep 17 00:00:00 2001 From: Ryan Hamshire Date: Wed, 9 May 2012 17:29:51 -0700 Subject: [PATCH] 3.6 --- plugin.yml | 2 +- .../GriefPrevention/BlockEventHandler.java | 41 ++++++++++++++++ .../ryanhamshire/GriefPrevention/Claim.java | 11 ----- .../GriefPrevention/GriefPrevention.java | 20 ++++++++ .../GriefPrevention/PlayerData.java | 2 +- .../GriefPrevention/PlayerEventHandler.java | 47 ++++++------------- .../RestoreNatureProcessingTask.java | 2 + 7 files changed, 80 insertions(+), 45 deletions(-) diff --git a/plugin.yml b/plugin.yml index e050e52..fd328de 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,7 +1,7 @@ name: GriefPrevention main: me.ryanhamshire.GriefPrevention.GriefPrevention softdepend: [Vault, Multiverse-Core] -version: 3.4.1 +version: 3.6 commands: abandonclaim: description: Deletes a claim. diff --git a/src/me/ryanhamshire/GriefPrevention/BlockEventHandler.java b/src/me/ryanhamshire/GriefPrevention/BlockEventHandler.java index 5927487..19ce469 100644 --- a/src/me/ryanhamshire/GriefPrevention/BlockEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/BlockEventHandler.java @@ -25,6 +25,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.OfflinePlayer; import org.bukkit.block.Block; +import org.bukkit.block.BlockState; import org.bukkit.block.Chest; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -40,6 +41,7 @@ import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockSpreadEvent; +import org.bukkit.event.world.StructureGrowEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; @@ -60,6 +62,9 @@ public class BlockEventHandler implements Listener @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(); @@ -409,4 +414,40 @@ public class BlockEventHandler implements Listener } } } + + @EventHandler(ignoreCancelled = true) + public void onTreeGrow (StructureGrowEvent growEvent) + { + Location rootLocation = growEvent.getLocation(); + Claim rootClaim = this.dataStore.getClaimAt(rootLocation, false, null); + + //who owns the root, if anyone? + //who owns the spreading block, if anyone? + OfflinePlayer fromOwner = null; + if(rootClaim != null) + { + //if an administrative claim, just let the tree grow where it wants + if(rootClaim.isAdminClaim()) return; + + //otherwise, note the owner of the claim + fromOwner = GriefPrevention.instance.getServer().getOfflinePlayer(rootClaim.ownerName); + } + + //for each block growing + for(int i = 0; i < growEvent.getBlocks().size(); i++) + { + BlockState block = growEvent.getBlocks().get(i); + Claim blockClaim = this.dataStore.getClaimAt(block.getLocation(), false, rootClaim); + + //if it's growing into a claim + if(blockClaim != null) + { + //if there's no owner for the new tree, or the owner doesn't have permission to build in the claim, don't grow this block + if(fromOwner == null || fromOwner.getPlayer() == null || blockClaim.allowBuild(fromOwner.getPlayer()) != null) + { + growEvent.getBlocks().remove(i--); + } + } + } + } } diff --git a/src/me/ryanhamshire/GriefPrevention/Claim.java b/src/me/ryanhamshire/GriefPrevention/Claim.java index 5417488..7ee52ce 100644 --- a/src/me/ryanhamshire/GriefPrevention/Claim.java +++ b/src/me/ryanhamshire/GriefPrevention/Claim.java @@ -107,17 +107,6 @@ public class Claim this.lesserBoundaryCorner = lesserBoundaryCorner; this.greaterBoundaryCorner = greaterBoundaryCorner; - //if trying to create a claim under the max depth, auto-correct y values - if(this.lesserBoundaryCorner.getBlockY() < GriefPrevention.instance.config_claims_maxDepth) - { - this.lesserBoundaryCorner.setY(GriefPrevention.instance.config_claims_maxDepth); - } - - if(this.greaterBoundaryCorner.getBlockY() < GriefPrevention.instance.config_claims_maxDepth) - { - this.greaterBoundaryCorner.setY(GriefPrevention.instance.config_claims_maxDepth); - } - //owner this.ownerName = ownerName; diff --git a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java index 866d88f..20240b8 100644 --- a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java +++ b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java @@ -88,6 +88,8 @@ public class GriefPrevention extends JavaPlugin public boolean config_pvp_protectFreshSpawns; //whether to make newly spawned players immune until they pick up an item public boolean config_pvp_punishLogout; //whether to kill players who log out during PvP combat + public int config_pvp_combatTimeoutSeconds; //how long combat is considered to continue after the most recent damage + public boolean config_pvp_allowCombatItemDrop; //whether a player can drop items during combat to hide them public boolean config_trees_removeFloatingTreetops; //whether to automatically remove partially cut trees public boolean config_trees_regrowGriefedTrees; //whether to automatically replant partially cut trees @@ -100,6 +102,8 @@ public class GriefPrevention extends JavaPlugin public boolean config_fireSpreads; //whether fire spreads 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 + //reference to the economy plugin, if economy integration is enabled public static Economy economy = null; @@ -177,6 +181,8 @@ public class GriefPrevention extends JavaPlugin this.config_pvp_protectFreshSpawns = config.getBoolean("GriefPrevention.PvP.ProtectFreshSpawns", true); this.config_pvp_punishLogout = config.getBoolean("GriefPrevention.PvP.PunishLogout", true); + this.config_pvp_combatTimeoutSeconds = config.getInt("GriefPrevention.PvP.CombatTimeoutSeconds", 15); + this.config_pvp_allowCombatItemDrop = config.getBoolean("GriefPrevention.PvP.AllowCombatItemDrop", false); this.config_trees_removeFloatingTreetops = config.getBoolean("GriefPrevention.Trees.RemoveFloatingTreetops", true); this.config_trees_regrowGriefedTrees = config.getBoolean("GriefPrevention.Trees.RegrowGriefedTrees", true); @@ -189,6 +195,8 @@ public class GriefPrevention extends JavaPlugin this.config_fireSpreads = config.getBoolean("GriefPrevention.FireSpreads", false); this.config_fireDestroys = config.getBoolean("GriefPrevention.FireDestroys", false); + this.config_addItemsToClaimedChests = config.getBoolean("GriefPrevention.AddItemsToClaimedChests", true); + //default for claims worlds list ArrayList defaultSiegeWorldNames = new ArrayList(); @@ -284,6 +292,8 @@ public class GriefPrevention extends JavaPlugin config.set("GriefPrevention.PvP.ProtectFreshSpawns", this.config_pvp_protectFreshSpawns); config.set("GriefPrevention.PvP.PunishLogout", this.config_pvp_punishLogout); + config.set("GriefPrevention.PvP.CombatTimeoutSeconds", this.config_pvp_combatTimeoutSeconds); + config.set("GriefPrevention.PvP.AllowCombatItemDrop", this.config_pvp_allowCombatItemDrop); config.set("GriefPrevention.Trees.RemoveFloatingTreetops", this.config_trees_removeFloatingTreetops); config.set("GriefPrevention.Trees.RegrowGriefedTrees", this.config_trees_regrowGriefedTrees); @@ -296,6 +306,8 @@ public class GriefPrevention extends JavaPlugin config.set("GriefPrevention.FireSpreads", this.config_fireSpreads); config.set("GriefPrevention.FireDestroys", this.config_fireDestroys); + config.set("GriefPrevention.AddItemsToClaimedChests", this.config_addItemsToClaimedChests); + config.set("GriefPrevention.Siege.Worlds", siegeEnabledWorldNames); config.set("GriefPrevention.Siege.BreakableBlocks", breakableBlocksList); @@ -515,6 +527,7 @@ public class GriefPrevention extends JavaPlugin //confirm GriefPrevention.sendMessage(player, TextMode.Success, "Claim transferred."); + GriefPrevention.AddLogEntry(player.getName() + " transferred a claim at " + GriefPrevention.getfriendlyLocationString(claim.getLesserBoundaryCorner()) + " to " + targetPlayer.getName() + "."); return true; } @@ -918,6 +931,7 @@ public class GriefPrevention extends JavaPlugin { this.dataStore.deleteClaim(claim); GriefPrevention.sendMessage(player, TextMode.Success, "Claim deleted."); + GriefPrevention.AddLogEntry(player.getName() + " deleted " + claim.getOwnerName() + "'s claim at " + GriefPrevention.getfriendlyLocationString(claim.getLesserBoundaryCorner())); //revert any current visualization Visualization.Revert(player); @@ -1007,6 +1021,7 @@ public class GriefPrevention extends JavaPlugin this.dataStore.savePlayerData(targetPlayer.getName(), playerData); GriefPrevention.sendMessage(player, TextMode.Success, "Adjusted " + targetPlayer.getName() + "'s bonus claim blocks by " + adjustment + ". New total bonus blocks: " + playerData.bonusClaimBlocks + "."); + GriefPrevention.AddLogEntry(player.getName() + " adjusted " + targetPlayer.getName() + "'s bonus claim blocks by " + adjustment + "."); return true; } @@ -1167,6 +1182,11 @@ public class GriefPrevention extends JavaPlugin return false; } + public static String getfriendlyLocationString(Location location) + { + return location.getWorld().getName() + "(" + location.getBlockX() + "," + location.getBlockY() + "," + location.getBlockZ() + ")"; + } + private boolean abandonClaimHandler(Player player, boolean deleteTopLevelClaim) { //which claim is being abandoned? diff --git a/src/me/ryanhamshire/GriefPrevention/PlayerData.java b/src/me/ryanhamshire/GriefPrevention/PlayerData.java index d67a06e..7b5c660 100644 --- a/src/me/ryanhamshire/GriefPrevention/PlayerData.java +++ b/src/me/ryanhamshire/GriefPrevention/PlayerData.java @@ -106,7 +106,7 @@ public class PlayerData long elapsed = now - this.lastPvpTimestamp; - if(elapsed > 15000) //15 seconds + if(elapsed > GriefPrevention.instance.config_pvp_combatTimeoutSeconds * 1000) //X seconds { this.lastPvpTimestamp = 0; return false; diff --git a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java index 8012e93..e442da5 100644 --- a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java @@ -290,6 +290,9 @@ class PlayerEventHandler implements Listener //disable ignore claims mode playerData.ignoreClaims = false; + + //drop player data from memory + this.dataStore.clearCachedPlayerData(playerName); } //when a player drops an item @@ -303,7 +306,7 @@ class PlayerEventHandler implements Listener //them or give them away to other players before they are defeated //if in combat, don't let him drop it - if(playerData.inPvpCombat()) + if(!GriefPrevention.instance.config_pvp_allowCombatItemDrop && playerData.inPvpCombat()) { GriefPrevention.sendMessage(player, TextMode.Err, "You can't drop items while in PvP combat."); event.setCancelled(true); @@ -456,34 +459,8 @@ class PlayerEventHandler implements Listener ItemStack newItemStack = player.getInventory().getItem(event.getNewSlot()); if(newItemStack != null && newItemStack.getType() == Material.GOLD_SPADE) { - PlayerData playerData = this.dataStore.getPlayerData(player.getName()); - - //reset any work he might have been doing - playerData.lastShovelLocation = null; - playerData.claimResizing = null; - - //always reset to basic claims mode - if(playerData.shovelMode != ShovelMode.Basic) - { - playerData.shovelMode = ShovelMode.Basic; - GriefPrevention.sendMessage(player, TextMode.Info, "Shovel returned to basic claims mode."); - } - - int remainingBlocks = playerData.getRemainingClaimBlocks(); - - //if he doesn't have enough blocks to create a new claim, tell him so and offer advice - if(remainingBlocks < GriefPrevention.instance.config_claims_minSize * GriefPrevention.instance.config_claims_minSize) - { - GriefPrevention.sendMessage(player, TextMode.Err, "You don't have enough available claim blocks to create a new claim (each new claim must be at least " + GriefPrevention.instance.config_claims_minSize + " x " + GriefPrevention.instance.config_claims_minSize + "). Consider /AbandonClaim to delete an existing claim."); - return; - } - - //otherwise instruct him in the steps to create a claim - else - { - GriefPrevention.sendMessage(player, TextMode.Instr, "To start creating a claim, right-click at one corner of the claim area. You may claim up to " + String.valueOf(remainingBlocks) + " more blocks."); - GriefPrevention.sendMessage(player, TextMode.Instr, "Need a demonstration? Watch the \"Grief Prevention Basics\" YouTube video."); - } + EquipShovelProcessingTask task = new EquipShovelProcessingTask(player); + GriefPrevention.instance.getServer().getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, task, 15L); //15L is approx. 3/4 of a second } } @@ -925,7 +902,13 @@ class PlayerEventHandler implements Listener //inform and show the player GriefPrevention.sendMessage(player, TextMode.Success, "Claim resized. You now have " + playerData.getRemainingClaimBlocks() + " available claim blocks."); Visualization visualization = Visualization.FromClaim(result.claim, clickedBlock.getY(), VisualizationType.Claim); - Visualization.Apply(player, visualization); + Visualization.Apply(player, visualization); + + //if resizing someone else's claim, make a log entry + if(!playerData.claimResizing.ownerName.equals(playerName)) + { + GriefPrevention.AddLogEntry(playerName + " resized " + playerData.claimResizing.getOwnerName() + "'s claim at " + GriefPrevention.getfriendlyLocationString(playerData.claimResizing.lesserBoundaryCorner) + "."); + } //clean up playerData.claimResizing = null; @@ -1082,7 +1065,7 @@ class PlayerEventHandler implements Listener if(playerData.shovelMode != ShovelMode.Admin && (newClaimWidth < GriefPrevention.instance.config_claims_minSize || newClaimHeight < GriefPrevention.instance.config_claims_minSize)) { - GriefPrevention.sendMessage(player, TextMode.Err, "Stopping your claim here would create a too-small claim. A claim must be at least " + GriefPrevention.instance.config_claims_minSize + " x " + GriefPrevention.instance.config_claims_minSize + "."); + GriefPrevention.sendMessage(player, TextMode.Err, "This claim would be too small. Any claim must be at least " + GriefPrevention.instance.config_claims_minSize + " x " + GriefPrevention.instance.config_claims_minSize + "."); return; } @@ -1094,7 +1077,7 @@ class PlayerEventHandler implements Listener if(newClaimArea > remainingBlocks) { GriefPrevention.sendMessage(player, TextMode.Err, "You don't have enough blocks to claim that entire area. You need " + (newClaimArea - remainingBlocks) + " more blocks."); - GriefPrevention.sendMessage(player, TextMode.Instr, "To delete another claim and free up some blocks, use /abandonclaim."); + GriefPrevention.sendMessage(player, TextMode.Instr, "To delete another claim and free up some blocks, use /AbandonClaim."); return; } } diff --git a/src/me/ryanhamshire/GriefPrevention/RestoreNatureProcessingTask.java b/src/me/ryanhamshire/GriefPrevention/RestoreNatureProcessingTask.java index a88662b..9427589 100644 --- a/src/me/ryanhamshire/GriefPrevention/RestoreNatureProcessingTask.java +++ b/src/me/ryanhamshire/GriefPrevention/RestoreNatureProcessingTask.java @@ -70,6 +70,7 @@ class RestoreNatureProcessingTask implements Runnable //answer: better to leave a few player blocks than to remove too many natural blocks. remember we're "restoring nature" //a few extra player blocks can be manually removed, but it will be impossible to guess exactly which natural materials to use in replacements this.playerBlocks = new ArrayList(); + this.playerBlocks.add(Material.FIRE.getId()); this.playerBlocks.add(Material.BED_BLOCK.getId()); this.playerBlocks.add(Material.WOOD.getId()); this.playerBlocks.add(Material.BOOKSHELF.getId()); @@ -319,6 +320,7 @@ class RestoreNatureProcessingTask implements Runnable fillableBlocks.add(Material.AIR.getId()); fillableBlocks.add(Material.STATIONARY_WATER.getId()); fillableBlocks.add(Material.STATIONARY_LAVA.getId()); + fillableBlocks.add(Material.LONG_GRASS.getId()); ArrayList notSuitableForFillBlocks = new ArrayList(); notSuitableForFillBlocks.add(Material.LONG_GRASS.getId());