java - bukkit 插件《我的世界》箱子用列表中的 int 填充并从类构建

标签 java plugins bukkit

我有一个列表

private List<ChestPoint> chestpoints = new ArrayList<>();

和 ChestPoint.java

int x;
int y;
int z;
String findhardness;
String arena;

并且想要设置箱子并填充它们

if(cmd.getName().equalsIgnoreCase("buildfillchests")) {
    ItemStack itemsforchest = new ItemStack(Material.CHEST, 1728);
    if(args.length == 1){
        for(ChestPoint cp : chestpoints){
            Location chestloc = null;
            if(cp.arena == null ? args[0] == null : cp.arena.equals(args[0])){
                chestloc.setX(cp.x);
                chestloc.setY(cp.y);
                chestloc.setZ(cp.z);
                if(chestloc.getBlock().getType() == Material.AIR){
                    chestloc.getBlock().setType(Material.CHEST);
                    Inventory chestinv = ((Chest) chestloc.getBlock().getState()).getInventory();
                    chestinv.addItem(itemsforchest);
                }
            }
        }
    } else {
        if(args.length == 3 && "by".equals(args[0]) && "all".equals(args[1]) && "chests".equals(args[2])){
            for(ChestPoint cp : chestpoints){
                Location chestloc = null;
                chestloc.setX(cp.x);
                chestloc.setY(cp.y);
                chestloc.setZ(cp.z);
                if(chestloc.getBlock().getType() == Material.AIR){
                    chestloc.getBlock().setType(Material.CHEST);
                    Inventory chestinv = ((Chest) chestloc.getBlock().getState()).getInventory();
                    chestinv.addItem(itemsforchest);
                }
            }
        } else {
            sender.sendMessage(ChatColor.RED + "Es funktioniert nur /buildfillchests <arena> oder /buildfillchests by all chests");
    }
}

这不行! 我想在列表中所有设置的胸部点上建立胸部并用胸部填充胸部!但在我的日志文件中没有记录错误! 有人能发现我的错误吗?

最佳答案

您必须调用 BlockState.update() 方法才能将 BlockState 应用回实际的 block 。

http://jd.bukkit.org/beta/doxygen/d9/d1c/interfaceorg_1_1bukkit_1_1block_1_1BlockState.html#a0734c83720823a6eb2247aaf4b60ec0e

关于java - bukkit 插件《我的世界》箱子用列表中的 int 填充并从类构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22382341/

相关文章:

ruby-on-rails - 从命令行调试/执行 Discourse 插件

Java Spigot 设置 vector 相对于玩家位置的方向

java - (Java) SQL 查询根本不返回任何内容

Java(Bukkit)如何在没有这个的情况下访问Config?

如果id已经存在,Java更新mysql行

java - 攻击 XMPP : Can't login to openfire server: "SASLErrorException: SASLError using DIGEST-MD5: not-authorized"

java - 如何将JTextArea行数的值转换为Dimension height_JAVA

java - 当InputStream定期接收数据时,它的消息如何永远不会为空?

javascript - 使用类和原型(prototype)编写 jQuery 插件

Java 浏览器插件或手动安装 Java