Minecraft插件标志阅读

时间:2015-06-17 20:16:45

标签: java plugins minecraft

我在尝试获取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]签名并右键点击它时没有任何反应......

1 个答案:

答案 0 :(得分:1)

你需要这样做:

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

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