Minecraft 插件前缀 (Java)

Minecraft Plugin Prefix (Java)

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

我使用的 API = PlayerPoints & Spigot 1.9.4 阴影。 关于 PlayerPoints API : Click 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 的错误日志:

The method look(String) from the type PlayerPointsAPI is deprecated

这是另一条注意事项: 在 PlayerpointsAPI 页面中提到使用:

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

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

有人知道怎么回事吗?

谢谢你

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

您链接的页面准确地告诉了您缺少的内容。它说 "During enable, you need to grab the PlayerPoints plugin instance and save that reference somewhere as you will be using the API through it."

因此,使用他们提供的示例代码(为简单起见复制到此处):将这两个方法复制到您的插件 class(在您的情况下可能是 Main.java)并更改 getPlayerPoints( ) 方法在你的侦听器中到 plugin.getPlayerPoints()。或者,如果您的侦听器中的其他任何地方都没有使用该插件,您可以只在构造函数中引用 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;
}