Minecraft 插件符号阅读

Minecraft plugin sign reading

我在尝试获取 minecraft 插件中的符号线值时遇到问题。这是我的代码:

package pl.maccraft.regssal;

import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;

public final class rgs extends JavaPlugin implements Listener {
    @EventHandler
    public void playerInteract(PlayerInteractEvent event){
        Player player = event.getPlayer();
        Action action = event.getAction();
    if(action.equals(Action.RIGHT_CLICK_BLOCK)){
        Block b = event.getClickedBlock();
        if (b.getType().equals(Material.SIGN) || b.getType().equals(Material.SIGN_POST) || b.getType().equals(Material.WALL_SIGN)){
            Sign sign = (Sign) b.getState();
            if (sign.getLine(0).equals("[sell]")){
                    sign.setLine(0, ChatColor.DARK_RED + "[sell]");
                    sign.setLine(1, player.getName());
                    sign.setLine(2, "0");
                    sign.setLine(3, ChatColor.DARK_RED + "a");
            }
        }
    }
}

控制台输出:

[22:08:50] [Server thread/INFO]: [RegsShop] Loading RegsShop v1.0
[22:08:51] [Server thread/INFO]: [RegsShop] Enabling RegsShop v1.0

当我在第一行用 [sell] 签名并右键单击它时,没有任何反应...

您需要这样做:

@Override
public void onEnable() {
    getServer().getPluginManager().registerEvents(this, this);
}

在您的主要 class 中(扩展 JavaPlugin)。有关更多信息,请查看 here.