Skip to content
Browse files

Fix explosion regen so containers respawn with the correct inventories.

  • Loading branch information...
1 parent 264d248 commit 228973f105a4603a17e7a85848f221ac9717255a @ElgarL committed Aug 13, 2012
Showing with 103 additions and 79 deletions.
  1. +0 −1 build.xml
  2. +3 −1 src/ChangeLog.txt
  3. +92 −76 src/com/palmergames/bukkit/towny/tasks/ProtectionRegenTask.java
  4. +8 −1 src/plugin.yml
View
1 build.xml
@@ -16,7 +16,6 @@
<javac srcdir="src" destdir="${build}" includeantruntime="false" target="1.6" source="1.6">
<classpath>
<pathelement location="${env.LIB}/bukkit.jar"/>
- <pathelement location="${env.LIB}/craftbukkit.jar"/>
<pathelement location="${env.LIB}/bpermissions.jar"/>
<pathelement location="${env.LIB}/Essentials.jar"/>
<pathelement location="${env.LIB}/EssentialsGroupManager.jar"/>
View
4 src/ChangeLog.txt
@@ -1680,4 +1680,6 @@ v0.81.0.6:
- Add missing towny.command.resident.* permission.
- Fix typo on 'towny.command.town.add' permission.
v0.81.0.7:
- - Fix player permissions not being updated when performing a '/ta reload'.
+ - Fix player permissions not being updated when performing a '/ta reload'.
+v0.81.0.8:
+ - Fix explosion regen so containers respawn with the correct inventories.
View
168 src/com/palmergames/bukkit/towny/tasks/ProtectionRegenTask.java
@@ -1,14 +1,17 @@
package com.palmergames.bukkit.towny.tasks;
+import java.util.ArrayList;
+import java.util.List;
+
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.Sign;
-import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
+import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Attachable;
import org.bukkit.material.Door;
import org.bukkit.material.PistonExtensionMaterial;
@@ -24,6 +27,7 @@
private BlockState altState;
private BlockLocation blockLocation;
private int TaskId;
+ private List<ItemStack> contents = new ArrayList<ItemStack>();
private static final Material placeholder = Material.DIRT;
@@ -33,7 +37,19 @@ public ProtectionRegenTask(Towny plugin, Block block, boolean update) {
this.state = block.getState();
this.altState = null;
this.setBlockLocation(new BlockLocation(block.getLocation()));
+
+ if (state instanceof InventoryHolder) {
+
+ // Contents we are respawning.
+ Inventory inven = ((InventoryHolder) state).getInventory();
+ for (ItemStack item : inven.getContents()) {
+ contents.add((item != null) ? item.clone() : null);
+ }
+
+ inven.clear();
+ }
+
if (update)
if (state.getData() instanceof Door) {
Door door = (Door) state.getData();
@@ -70,87 +86,87 @@ public void run() {
public void replaceProtections() {
- Block block = state.getBlock();
-
- if (state.getData() instanceof Door) {
-
- Door door = (Door) state.getData();
- Block topHalf;
- Block bottomHalf;
- if (door.isTopHalf()) {
- topHalf = block;
- bottomHalf = block.getRelative(BlockFace.DOWN);
+ try {
+
+ Block block = state.getBlock();
+
+ if (state.getData() instanceof Door) {
+
+ Door door = (Door) state.getData();
+ Block topHalf;
+ Block bottomHalf;
+ if (door.isTopHalf()) {
+ topHalf = block;
+ bottomHalf = block.getRelative(BlockFace.DOWN);
+ } else {
+ bottomHalf = block;
+ topHalf = block.getRelative(BlockFace.UP);
+ }
+ door.setTopHalf(true);
+ topHalf.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
+ door.setTopHalf(false);
+ bottomHalf.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
+
+ } else if (state instanceof Sign) {
+
+ block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
+ Sign sign = (Sign) block.getState();
+ int i = 0;
+ for (String line : ((Sign) state).getLines())
+ sign.setLine(i++, line);
+
+ sign.update(true);
+
+ } else if (state instanceof CreatureSpawner) {
+
+ block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
+ ((CreatureSpawner) block.getState()).setSpawnedType(((CreatureSpawner) state).getSpawnedType());
+
+ } else if (state instanceof InventoryHolder) {
+
+ block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
+
+ // Container to receive the inventory
+ Inventory container = ((InventoryHolder) block.getState()).getInventory();
+ container.setContents(contents.toArray(new ItemStack[0]));
+
+ } else if (state.getData() instanceof PistonExtensionMaterial) {
+
+ PistonExtensionMaterial extension = (PistonExtensionMaterial) state.getData();
+ Block piston = block.getRelative(extension.getAttachedFace());
+ block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
+ if (altState != null) {
+ piston.setTypeIdAndData(altState.getTypeId(), altState.getData().getData(), false);
+ }
+ } else if (state.getData() instanceof Attachable) {
+
+ Block attachedBlock = block.getRelative(((Attachable) state.getData()).getAttachedFace());
+ if (attachedBlock.getTypeId() == 0) {
+ attachedBlock.setTypeId(placeholder.getId(), false);
+ TownyRegenAPI.addPlaceholder(attachedBlock);
+ }
+ block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
+
} else {
- bottomHalf = block;
- topHalf = block.getRelative(BlockFace.UP);
- }
- door.setTopHalf(true);
- topHalf.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
- door.setTopHalf(false);
- bottomHalf.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
-
- } else if (state instanceof Sign) {
- block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
- Sign sign = (Sign) block.getState();
- int i = 0;
- for (String line : ((Sign) state).getLines())
- sign.setLine(i++, line);
-
- sign.update(true);
-
- } else if (state instanceof CreatureSpawner) {
-
- block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
- ((CreatureSpawner) block.getState()).setSpawnedType(((CreatureSpawner) state).getSpawnedType());
-
- } else if ((state instanceof InventoryHolder) && !(state instanceof Player)) {
-
- block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
-
- // Container to receive the inventory
- InventoryHolder container = (InventoryHolder) block.getState();
-
- // Contents we are respawning.
- Inventory inven = ((InventoryHolder) state).getInventory();
-
- if (inven.getContents().length > 0)
- container.getInventory().setContents(inven.getContents());
-
-
- } else if (state.getData() instanceof PistonExtensionMaterial) {
-
- PistonExtensionMaterial extension = (PistonExtensionMaterial) state.getData();
- Block piston = block.getRelative(extension.getAttachedFace());
- block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
- if (altState != null) {
- piston.setTypeIdAndData(altState.getTypeId(), altState.getData().getData(), false);
- }
- } else if (state.getData() instanceof Attachable) {
-
- Block attachedBlock = block.getRelative(((Attachable) state.getData()).getAttachedFace());
- if (attachedBlock.getTypeId() == 0) {
- attachedBlock.setTypeId(placeholder.getId(), false);
- TownyRegenAPI.addPlaceholder(attachedBlock);
- }
- block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
-
- } else {
-
- if (NeedsPlaceholder.contains(state.getType())) {
- Block blockBelow = block.getRelative(BlockFace.DOWN);
- if (blockBelow.getTypeId() == 0) {
- if (state.getType().equals(Material.CROPS)) {
- blockBelow.setTypeId(Material.SOIL.getId(), true);
- } else {
- blockBelow.setTypeId(placeholder.getId(), true);
+ if (NeedsPlaceholder.contains(state.getType())) {
+ Block blockBelow = block.getRelative(BlockFace.DOWN);
+ if (blockBelow.getTypeId() == 0) {
+ if (state.getType().equals(Material.CROPS)) {
+ blockBelow.setTypeId(Material.SOIL.getId(), true);
+ } else {
+ blockBelow.setTypeId(placeholder.getId(), true);
+ }
+ TownyRegenAPI.addPlaceholder(blockBelow);
}
- TownyRegenAPI.addPlaceholder(blockBelow);
}
+ block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), !NeedsPlaceholder.contains(state.getType()));
}
- block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), !NeedsPlaceholder.contains(state.getType()));
+ TownyRegenAPI.removePlaceholder(block);
+
+ } catch (Exception ex) {
+ ex.printStackTrace();
}
- TownyRegenAPI.removePlaceholder(block);
}
/**
View
9 src/plugin.yml
@@ -1,6 +1,6 @@
name: Towny
main: com.palmergames.bukkit.towny.Towny
-version: 0.81.0.7
+version: 0.81.0.8
author: Shade, Modified by FuzzeWuzze. Forked by ElgarL
website: http://code.google.com/a/eclipselabs.org/p/towny/
description: >
@@ -169,6 +169,13 @@ permissions:
towny.command.town.claim.*: true
towny.command.town.unclaim: true
towny.command.town.online: true
+
+ towny.command.town.claim.*:
+ description: User can access all town related commands.
+ default: false
+ children:
+ towny.command.town.claim.town: true
+ towny.command.town.claim.outpost: true
towny.command.town.set.*:
description: User can access all town set commands.

0 comments on commit 228973f

Please sign in to comment.
Something went wrong with that request. Please try again.