Don't make a new metadata value for every block every time.

This commit is contained in:
GJ 2013-02-23 00:29:25 -05:00
parent 7e1eeb66d6
commit 8d16c06739
3 changed files with 12 additions and 9 deletions

View File

@ -18,7 +18,6 @@ import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.AdvancedConfig;
@ -62,13 +61,14 @@ public class BlockListener implements Listener {
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
List<Block> blocks = event.getBlocks();
BlockFace direction = event.getDirection();
Block futureEmptyBlock = event.getBlock().getRelative(direction); // Block that would be air after piston is finished
for (Block b : blocks) {
if (mcMMO.placeStore.isTrue(b)) {
b.getRelative(direction).setMetadata("pistonTrack", new FixedMetadataValue(plugin, true));
b.getRelative(direction).setMetadata(mcMMO.blockMetadataKey, mcMMO.blockMetadata);
if (b.equals(futureEmptyBlock)) {
mcMMO.placeStore.setFalse(b);
}
@ -76,9 +76,9 @@ public class BlockListener implements Listener {
}
for (Block b : blocks) {
if (b.getRelative(direction).hasMetadata("pistonTrack")) {
if (b.getRelative(direction).hasMetadata(mcMMO.blockMetadataKey)) {
mcMMO.placeStore.setTrue(b.getRelative(direction));
b.getRelative(direction).removeMetadata("pistonTrack", plugin);
b.getRelative(direction).removeMetadata(mcMMO.blockMetadataKey, plugin);
}
}
}

View File

@ -301,10 +301,7 @@ public class EntityListener implements Listener {
*/
@EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onCreatureSpawn(CreatureSpawnEvent event) {
if (Misc.isSpawnerXPEnabled) {
return;
}
else if (event.getEntity() == null) {
if (Misc.isSpawnerXPEnabled || event.getEntity() == null) {
return;
}

View File

@ -94,6 +94,10 @@ public class mcMMO extends JavaPlugin {
public static FixedMetadataValue entityMetadata;
public final static String entityMetadataKey = "mcMMO: Spawned Entity";
// Block Metadata Values
public static FixedMetadataValue blockMetadata;
public final static String blockMetadataKey = "mcMMO: Piston Tracking";
/**
* Things to be run when the plugin is enabled.
*/
@ -102,7 +106,9 @@ public class mcMMO extends JavaPlugin {
try {
p = this;
getLogger().setFilter(new LogFilter(this));
entityMetadata = new FixedMetadataValue(mcMMO.p, true);
entityMetadata = new FixedMetadataValue(this, true);
blockMetadata = new FixedMetadataValue(this, true);
setupFilePaths();
setupSpout();
loadConfigFiles();