当玩家单击标志时,我试图将标志上的文本作为字符串获取。随着《我的世界》中允许在两侧编辑标志的新变化,许多旧的方法已被弃用。对于新标志,您首先必须在阅读标志行之前使用 getSide() 。不幸的是,PlayerInteract 事件似乎没有提供返回 SignSide 的方法,最接近的是 BlockFace。
我当前的代码如下所示:
@EventHandler(ignoreCancelled = true)
void onPlayerInteract(PlayerInteractEvent event) {
//Check that the player clicked a block
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
//Check that the block is a sign
Block block = event.getClickedBlock();
if (block == null) {
return;
}
if (!(block.getState() instanceof Sign)) {
return;
}
//Here is where I need to get the clicked face of the sign, and return a given
//line on the sign as a String
}
如果有人可以提供有关如何完成此操作的更多信息,我们将不胜感激。
我自己回答这个问题,因为该功能现已添加到 spigot 中。请参阅此处了解更多信息: