mirror of
				https://github.com/mcMMO-Dev/mcMMO.git
				synced 2025-11-04 11:03:43 +01:00 
			
		
		
		
	Don't make a new metadata value for every block every time.
This commit is contained in:
		@@ -18,7 +18,6 @@ import org.bukkit.event.block.BlockPistonExtendEvent;
 | 
				
			|||||||
import org.bukkit.event.block.BlockPistonRetractEvent;
 | 
					import org.bukkit.event.block.BlockPistonRetractEvent;
 | 
				
			||||||
import org.bukkit.event.block.BlockPlaceEvent;
 | 
					import org.bukkit.event.block.BlockPlaceEvent;
 | 
				
			||||||
import org.bukkit.inventory.ItemStack;
 | 
					import org.bukkit.inventory.ItemStack;
 | 
				
			||||||
import org.bukkit.metadata.FixedMetadataValue;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.gmail.nossr50.mcMMO;
 | 
					import com.gmail.nossr50.mcMMO;
 | 
				
			||||||
import com.gmail.nossr50.config.AdvancedConfig;
 | 
					import com.gmail.nossr50.config.AdvancedConfig;
 | 
				
			||||||
@@ -62,13 +61,14 @@ public class BlockListener implements Listener {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    @EventHandler(priority = EventPriority.MONITOR)
 | 
					    @EventHandler(priority = EventPriority.MONITOR)
 | 
				
			||||||
    public void onBlockPistonExtend(BlockPistonExtendEvent event) {
 | 
					    public void onBlockPistonExtend(BlockPistonExtendEvent event) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        List<Block> blocks = event.getBlocks();
 | 
					        List<Block> blocks = event.getBlocks();
 | 
				
			||||||
        BlockFace direction = event.getDirection();
 | 
					        BlockFace direction = event.getDirection();
 | 
				
			||||||
        Block futureEmptyBlock = event.getBlock().getRelative(direction); // Block that would be air after piston is finished
 | 
					        Block futureEmptyBlock = event.getBlock().getRelative(direction); // Block that would be air after piston is finished
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (Block b : blocks) {
 | 
					        for (Block b : blocks) {
 | 
				
			||||||
            if (mcMMO.placeStore.isTrue(b)) {
 | 
					            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)) {
 | 
					                if (b.equals(futureEmptyBlock)) {
 | 
				
			||||||
                    mcMMO.placeStore.setFalse(b);
 | 
					                    mcMMO.placeStore.setFalse(b);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@@ -76,9 +76,9 @@ public class BlockListener implements Listener {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (Block b : blocks) {
 | 
					        for (Block b : blocks) {
 | 
				
			||||||
            if (b.getRelative(direction).hasMetadata("pistonTrack")) {
 | 
					            if (b.getRelative(direction).hasMetadata(mcMMO.blockMetadataKey)) {
 | 
				
			||||||
                mcMMO.placeStore.setTrue(b.getRelative(direction));
 | 
					                mcMMO.placeStore.setTrue(b.getRelative(direction));
 | 
				
			||||||
                b.getRelative(direction).removeMetadata("pistonTrack", plugin);
 | 
					                b.getRelative(direction).removeMetadata(mcMMO.blockMetadataKey, plugin);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -301,10 +301,7 @@ public class EntityListener implements Listener {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    @EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = true)
 | 
					    @EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = true)
 | 
				
			||||||
    public void onCreatureSpawn(CreatureSpawnEvent event) {
 | 
					    public void onCreatureSpawn(CreatureSpawnEvent event) {
 | 
				
			||||||
        if (Misc.isSpawnerXPEnabled) {
 | 
					        if (Misc.isSpawnerXPEnabled || event.getEntity() == null) {
 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (event.getEntity() == null) {
 | 
					 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -94,6 +94,10 @@ public class mcMMO extends JavaPlugin {
 | 
				
			|||||||
    public static FixedMetadataValue entityMetadata;
 | 
					    public static FixedMetadataValue entityMetadata;
 | 
				
			||||||
    public final static String entityMetadataKey = "mcMMO: Spawned Entity";
 | 
					    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.
 | 
					     * Things to be run when the plugin is enabled.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
@@ -102,7 +106,9 @@ public class mcMMO extends JavaPlugin {
 | 
				
			|||||||
        try {
 | 
					        try {
 | 
				
			||||||
            p = this;
 | 
					            p = this;
 | 
				
			||||||
            getLogger().setFilter(new LogFilter(this));
 | 
					            getLogger().setFilter(new LogFilter(this));
 | 
				
			||||||
            entityMetadata = new FixedMetadataValue(mcMMO.p, true);
 | 
					            entityMetadata = new FixedMetadataValue(this, true);
 | 
				
			||||||
 | 
					            blockMetadata = new FixedMetadataValue(this, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            setupFilePaths();
 | 
					            setupFilePaths();
 | 
				
			||||||
            setupSpout();
 | 
					            setupSpout();
 | 
				
			||||||
            loadConfigFiles();
 | 
					            loadConfigFiles();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user