替换标志后面的块

时间:2017-04-30 12:21:29

标签: java eclipse plugins minecraft bukkit

最近我开始研究一个新的插件,我在找到如何更换标志附加的块时遇到问题。我尝试了一些来自互联网的方法没有工作 我怎么能做这样的事情? (我有对象“类型:签名:签名”女巫是我要替换他背后的块的标志)

非常感谢你阅读

固定编辑: 主方法内部的某处:

e.getPlayer().sendMessage("DETECTED");
                Block sb = sign.getBlock();// "sign " is type Sign imported from org.bukkit.block.Sign
            Block b =  RedstoneSign.getblock(sb);
            b.setType(Material.REDSTONE_BLOCK);

主要方法导入:

    import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;

getblock方法:

public static Block getblock (Block b){

    if (b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST)
    { 
        Sign s = (Sign) b.getState().getData();//in this case "s" is type "Sign" imported from org.bukkit.material.Sign
        return b.getRelative(s.getAttachedFace());
    }
    else {
        return null;
    }
}

getblock imports:

 import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.material.Sign;

1 个答案:

答案 0 :(得分:2)

 Sign s = (Sign) block.getState().getData();
 Block attachedBlock = b.getRelative(s.getAttachedFace());
 attachedBlock.setType(Material.DIRT);

导入必须为org.bukkit.material.Sign NOT org.bukkit.block.Sign