如何将一个块转换成它的 class -Canarymod
How to convert a block into its class -Canarymod
我一直在编写一个插件,当有人右键单击上面有特定文字的标志时,可以让他们向上移动,但要找到我需要将方块 class 转换为标志 class 并使用 getTextOnLine();
函数这里是我的 Java 代码
public class CowShooter 扩展 EZPlugin 实现 PluginListener {
@Override
public boolean enable() {
Canary.hooks().registerListener(this, this);
return super.enable(); // Call parent class's version too.
}
@HookHandler
public void SignChangeHook(BlockRightClickHook event) {
Player player = event.getPlayer();
Block block = event.getBlockClicked();
if (block.getType() == BlockType.SignPost || block.getType() == BlockType.WallSign) {
错误代码
Sign sign = event.getBlockClicked();
if (sign.getTextOnLine(1) == "TP") {
Location loc = player.getLocation();
int playerX = (int) loc.getX();
int playerY = (int) loc.getY();
int playerZ = (int) loc.getZ();
loc.setY(playerY+10);
player.teleportTo(loc);
}
}
}
}
这是源代码所在的文件夹Source code for canarymod
获取方块的坐标并设置在符号中class
Location loc = player.getLocation();
loc.setX(event.getBlockClicked().getX());
loc.setZ(event.getBlockClicked().getZ());
loc.setY(event.getBlockClicked().getY());
World world = loc.getWorld();
Sign sign = (Sign)world.getTileEntity(world.getBlockAt(loc));
我一直在编写一个插件,当有人右键单击上面有特定文字的标志时,可以让他们向上移动,但要找到我需要将方块 class 转换为标志 class 并使用 getTextOnLine();
函数这里是我的 Java 代码
public class CowShooter 扩展 EZPlugin 实现 PluginListener {
@Override
public boolean enable() {
Canary.hooks().registerListener(this, this);
return super.enable(); // Call parent class's version too.
}
@HookHandler
public void SignChangeHook(BlockRightClickHook event) {
Player player = event.getPlayer();
Block block = event.getBlockClicked();
if (block.getType() == BlockType.SignPost || block.getType() == BlockType.WallSign) {
错误代码
Sign sign = event.getBlockClicked();
if (sign.getTextOnLine(1) == "TP") {
Location loc = player.getLocation();
int playerX = (int) loc.getX();
int playerY = (int) loc.getY();
int playerZ = (int) loc.getZ();
loc.setY(playerY+10);
player.teleportTo(loc);
}
}
}
}
这是源代码所在的文件夹Source code for canarymod
获取方块的坐标并设置在符号中class
Location loc = player.getLocation();
loc.setX(event.getBlockClicked().getX());
loc.setZ(event.getBlockClicked().getZ());
loc.setY(event.getBlockClicked().getY());
World world = loc.getWorld();
Sign sign = (Sign)world.getTileEntity(world.getBlockAt(loc));