你可以这样做:
p.sendBlockChange(Location, Material, Byte);
- Location 是方块的位置
- 材质是您希望玩家看到的材质
- 字节是数据,所以在块
43:8,你可以使用8。如果没有,只需使用 0。
因此,您可以这样做以将块更新发送给所有玩家:
Location[] invisibleBlocks; //all Invisible locations
for(Player p : Bukkit.getOnlinePlayers()){ //get all online players
for(Location l : invisibleBlocks){ //get all invisible blocks
p.sendBlockChange(l, Material.AIR, 0); //send block change of AIR to the player
}
}
唯一的问题是,当玩家卸载/加载更改所在的区块时,块更改会被重置。因此,要解决此问题,您可以安排一个计时器:
Location[] invisibleBlocks; //set this to the locations of all of the blocks you want to make invisible
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
public void run(){
for(Player p : Bukkit.getOnlinePlayers()){ //get all online players
for(Location l : invisibleBlocks){ //get all invisible blocks
p.sendBlockChange(l, Material.AIR, 0); //send block change of AIR to the player
}
}
}
},100);//delay time is 5 seconds (5 seconds * 20 ticks per second)
然后您需要做的就是将萤石放在invisibleBlocks 位置,它会显示为空气,但(应该)仍会发光。
这样做的一个问题是,如果玩家试图走进街区,他们会走到一半,然后被传送回来。这是因为客户端认为那里没有方块,但服务器知道有,当玩家走进方块时,服务器会将他们传送回来,做出一种生涩的动作。
如果你把它放在玩家无法进入的地方,你应该很好!