【问题标题】:Minecraft Plugin Prefix (Java)Minecraft 插件前缀 (Java)
【发布时间】:2017-01-11 01:01:44
【问题描述】:

我只是想为我的世界服务器创建一个简单的前缀插件,它在聊天框中显示每个玩家点。

我使用的 API = PlayerPoints & Spigot 1.9.4 阴影。 关于PlayerPoints APIClick here

控制台显示问题出现在PlayerListener.java

package points.prefix;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.black_ixx.playerpoints.PlayerPoints;


public class PlayerListener implements Listener {

Main plugin;
public PlayerListener(Main instance){
     this.plugin = instance;
}  

public PlayerPoints getPlayerPoints() {
    return getPlayerPoints();
}

//OnPlayer Join
@EventHandler
public void playerjoin(PlayerJoinEvent e){
    Player p = e.getPlayer();
    String pname = p.getName();
    int points = getPlayerPoints().getAPI().look("Player");

    //Begin
    if (p.hasPermission("prefix.point")){
        String member = "" + ChatColor.WHITE + "[" + ChatColor.GREEN + points + ChatColor.WHITE + "]" + ChatColor.RESET + ChatColor.WHITE + pname + ChatColor.RESET + "";
        p.setDisplayName(member);
    }
} }

来自 spigot 控制台的错误日志:

points.prefix.PlayerListener.getPlayerPoints(PlayerListener.java:19) ~[?:?] [20:57:40]

来自 Eclipse 的错误日志:

PlayerPointsAPI 类型的方法look(String) 已弃用

这里还有一个注意事项: 在PlayerpointsAPI页面中提到使用:

int balance = playerPoints.getAPI().look("Player");

为了显示平衡!但它不起作用!

有人知道怎么回事吗?

谢谢你。

【问题讨论】:

    标签: java plugins minecraft prefix


    【解决方案1】:

    以后请让人们知道你的错误是什么以及它在哪一行。在这种情况下,您会遇到堆栈溢出错误,因为您的 getPlayerPoints 方法会递归调用自身,而实际上没有做任何事情来跳出无限循环!

    您链接的页面确切地告诉您您缺少什么。它说“在启用期间,您需要获取 PlayerPoints 插件实例并将该引用保存在某处,因为您将通过它使用 API。”

    所以,使用他们提供的示例代码(为简单起见,复制到此处):将这两个方法复制到您的插件类(在您的情况下可能是 Main.java)并将您的侦听器中的 getPlayerPoints() 方法更改为 @987654321 @。或者,如果插件没有在侦听器中的其他任何地方使用,您可以只在构造函数中引用 playerPoints 实例,而不是引用插件。

    private PlayerPoints playerPoints;
    
    /**
     * Validate that we have access to PlayerPoints
     *
     * @return True if we have PlayerPoints, else false.
     */
    private boolean hookPlayerPoints() {
        final Plugin plugin = this.getServer().getPluginManager().getPlugin("PlayerPoints");
        playerPoints = PlayerPoints.class.cast(plugin);
        return playerPoints != null; 
    }
    
    /**
     * Accessor for other parts of your plugin to retrieve PlayerPoints.
     *
     * @return PlayerPoints plugin instance
     */
    public PlayerPoints getPlayerPoints() {
        return playerPoints;
    }
    

    【讨论】:

    • 我的问题在你回答之前就解决了!你的回答也是对的。不仅如此,我忘了把我的 hookplayerpoints 放在 OnEnable 上!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多