Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.turt2live.bukkit.testing.b855;
- import java.util.ArrayList;
- import java.util.List;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Material;
- import org.bukkit.block.Block;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.material.Step;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin implements Listener{
- // Borrow the list of applicable materials
- private static final List<Material> textures = new ArrayList<Material>();
- static {
- textures.add(Material.STONE);
- textures.add(Material.SANDSTONE);
- textures.add(Material.WOOD);
- textures.add(Material.COBBLESTONE);
- textures.add(Material.BRICK);
- textures.add(Material.SMOOTH_BRICK);
- textures.add(Material.NETHER_BRICK); // From PR
- textures.add(Material.QUARTZ_BLOCK); // From PR
- }
- public void onEnable(){
- this.getServer().getPluginManager().registerEvents(this, this);
- }
- /*
- * To activate this PR testing simply interact with a STEP or DOUBLE_STEP.
- * This will go through the list of materials (known to work with steps) and
- * set the STEP (or DOUBLE_STEP) to that material.
- */
- int index = 0;
- @EventHandler
- public void onInteract(PlayerInteractEvent event){
- if(event.getClickedBlock()!=null){
- Block block = event.getClickedBlock();
- if(block.getType()==Material.STEP||block.getType()==Material.DOUBLE_STEP){
- // Clone the BlockState. This is required as without the clone it does not update
- // This happens without this PR as well.
- Step data = (Step) block.getState().getData().clone();
- data.setMaterial(textures.get(index)); // Get the applicable next texture
- block.setData(data.getData()); // Update the block's data to our changed (cloned) data.
- boolean updated = block.getState().update(true); // Force an update
- if(!updated){
- Bukkit.broadcastMessage(ChatColor.RED+"NOT UPDATED"); // Should never happen (in this test)
- }
- // <what we set it to> <what the block says it is> <what the block state says it is>
- Bukkit.broadcastMessage("TEXTURE: "+textures.get(index).name() +" REPORTED: "+data.getMaterial().name()+" || "+((Step)block.getState().getData()).getMaterial().name());
- index++;
- if(index==textures.size()){
- index=0;
- Bukkit.broadcastMessage("----"); // To show we iterated all of the possibilities
- }
- event.setCancelled(true); // To avoid creative left clicking and such
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment