我只想为我的世界服务器创建简单的前缀插件,它在聊天框中显示每个玩家的点。
我使用的 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 方法递归地调用自身,而没有实际执行任何操作来打破无限循环!
您链接的页面准确地告诉您缺少什么。它说“在启用期间,您需要获取 PlayerPoints 插件实例并将该引用保存在某处,因为您将通过它使用 API。”
因此,使用他们提供的示例代码(为了简单起见,复制到此处):将这两个方法复制到您的插件类中(在您的情况下可能是 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;
}
关于java - Minecraft 插件前缀 (Java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38082011/