Bukkit Java error: The method PlayerJoin(OnStartup) is undefined for the type OnStartup
Bukkit Java error: The method PlayerJoin(OnStartup) is undefined for the type OnStartup
所以,我最近开始学习 Java 和 BukkitAPI。我创建了一个配置文件,并为播放器事件创建了一个 class,但是我无法在主 class 中注册这些事件。我收到一个错误 "The method PlayerJoin(OnStartup) is undefined for the type OnStartup",唯一的解决方法是创建一个方法。这是我的代码:
OnStartup(主要class):
package ml.zonia.plugin;
import java.io.File;
import java.util.logging.Logger;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import ml.zonia.plugin.commands.Potion;
import ml.zonia.plugin.event.PlayerJoin;
public class OnStartup extends JavaPlugin implements Listener {
public void onEnable() {
registerEvents();
registerConfig();
PluginDescriptionFile pdfFile = getDescription();
Logger logger = getLogger();
getServer().getPluginManager().registerEvents(this, this);
getCommand("zonia").setExecutor(new Potion());
logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " has been enabled.");
}
public void registerEvents() {
PluginManager pm = getServer().getPluginManager();
//here is the error on PlayerJoin:The method PlayerJoin(OnStartup) is undefined for the type OnStartup
pm.registerEvents(PlayerJoin(this), this);
}
private void registerConfig() {
getConfig().options().copyDefaults(true);
saveConfig();
}
public void onDisable() {
PluginDescriptionFile pdfFile = getDescription();
Logger logger = getLogger();
logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " has been disabled.");
saveConfig();
}
}
药水Class(以防万一):
package ml.zonia.plugin.commands;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
public class Potion implements CommandExecutor, Listener {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (label.equalsIgnoreCase("zonia"))
;
if (!(sender instanceof Player)) {
sender.sendMessage("You must be in-game to execute this command.");
return false;
}
Player player = (Player) sender;
player.sendMessage(ChatColor.DARK_AQUA + "ZoniaCore, made by Patrick S.");
return true;
}
}
玩家加入:
package ml.zonia.plugin.event;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import ml.zonia.plugin.OnStartup;
public class PlayerJoin implements Listener {
private OnStartup plugin;
public PlayerJoin(OnStartup pl) {
plugin = pl;
}
@EventHandler
public void onJoin(PlayerJoinEvent pje) {
int PlayerSpeed;
PlayerSpeed = plugin.getConfig().getInt("PlayerSpeed");
if (!pje.getPlayer().hasPermission("zonia.effects.remove"))
;
pje.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, PlayerSpeed));
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent pme) {
double SpawnX, SpawnY, SpawnZ;
SpawnX = plugin.getConfig().getDouble("SpawnX");
SpawnY = plugin.getConfig().getDouble("SpawnY");
SpawnZ = plugin.getConfig().getDouble("SpawnZ");
if ((int) pme.getPlayer().getLocation().getY() == 20) {
pme.getPlayer().teleport(new Location(Bukkit.getWorld("world"), SpawnX, SpawnY, SpawnZ));
}
}
}
在 eclipse 中,配置 yml 如下所示:
################################
# #
# ZoniaCore-Hub Config #
# Version 1.0 #
# #
################################
#Sets the player's speed.
PlayerSpeed: 17
#sets X, Y, and Z of spawn.
SpawnX: -67.5
SpawnY: 156
SpawnZ: 4.5
#sets how much the player has to fall
#to be teleported back to spawn.
TeleportY: 50
但是当它在插件下的plugins文件夹中生成时,它生成的配置是这样的,我似乎无法对其进行任何更改。:
#
# #
# ZoniaCore-Hub Config #
# Version 1.0 #
# #
PlayerSpeed: 6
SpawnX: -67.5
SpawnY: 156
SpawnZ: 4.5
TeleportY: 50
你的意思可能是:
pm.registerEvents(new PlayerJoin(this), this);
我没有看到 PlayerJoin 函数,只有构造函数。顺便说一句,函数名以大写字母开头是一种不好的做法,除非它是构造函数。
所以,我最近开始学习 Java 和 BukkitAPI。我创建了一个配置文件,并为播放器事件创建了一个 class,但是我无法在主 class 中注册这些事件。我收到一个错误 "The method PlayerJoin(OnStartup) is undefined for the type OnStartup",唯一的解决方法是创建一个方法。这是我的代码:
OnStartup(主要class):
package ml.zonia.plugin;
import java.io.File;
import java.util.logging.Logger;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import ml.zonia.plugin.commands.Potion;
import ml.zonia.plugin.event.PlayerJoin;
public class OnStartup extends JavaPlugin implements Listener {
public void onEnable() {
registerEvents();
registerConfig();
PluginDescriptionFile pdfFile = getDescription();
Logger logger = getLogger();
getServer().getPluginManager().registerEvents(this, this);
getCommand("zonia").setExecutor(new Potion());
logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " has been enabled.");
}
public void registerEvents() {
PluginManager pm = getServer().getPluginManager();
//here is the error on PlayerJoin:The method PlayerJoin(OnStartup) is undefined for the type OnStartup
pm.registerEvents(PlayerJoin(this), this);
}
private void registerConfig() {
getConfig().options().copyDefaults(true);
saveConfig();
}
public void onDisable() {
PluginDescriptionFile pdfFile = getDescription();
Logger logger = getLogger();
logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " has been disabled.");
saveConfig();
}
}
药水Class(以防万一):
package ml.zonia.plugin.commands;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
public class Potion implements CommandExecutor, Listener {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (label.equalsIgnoreCase("zonia"))
;
if (!(sender instanceof Player)) {
sender.sendMessage("You must be in-game to execute this command.");
return false;
}
Player player = (Player) sender;
player.sendMessage(ChatColor.DARK_AQUA + "ZoniaCore, made by Patrick S.");
return true;
}
}
玩家加入:
package ml.zonia.plugin.event;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import ml.zonia.plugin.OnStartup;
public class PlayerJoin implements Listener {
private OnStartup plugin;
public PlayerJoin(OnStartup pl) {
plugin = pl;
}
@EventHandler
public void onJoin(PlayerJoinEvent pje) {
int PlayerSpeed;
PlayerSpeed = plugin.getConfig().getInt("PlayerSpeed");
if (!pje.getPlayer().hasPermission("zonia.effects.remove"))
;
pje.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, PlayerSpeed));
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent pme) {
double SpawnX, SpawnY, SpawnZ;
SpawnX = plugin.getConfig().getDouble("SpawnX");
SpawnY = plugin.getConfig().getDouble("SpawnY");
SpawnZ = plugin.getConfig().getDouble("SpawnZ");
if ((int) pme.getPlayer().getLocation().getY() == 20) {
pme.getPlayer().teleport(new Location(Bukkit.getWorld("world"), SpawnX, SpawnY, SpawnZ));
}
}
}
在 eclipse 中,配置 yml 如下所示:
################################
# #
# ZoniaCore-Hub Config #
# Version 1.0 #
# #
################################
#Sets the player's speed.
PlayerSpeed: 17
#sets X, Y, and Z of spawn.
SpawnX: -67.5
SpawnY: 156
SpawnZ: 4.5
#sets how much the player has to fall
#to be teleported back to spawn.
TeleportY: 50
但是当它在插件下的plugins文件夹中生成时,它生成的配置是这样的,我似乎无法对其进行任何更改。:
#
# #
# ZoniaCore-Hub Config #
# Version 1.0 #
# #
PlayerSpeed: 6
SpawnX: -67.5
SpawnY: 156
SpawnZ: 4.5
TeleportY: 50
你的意思可能是:
pm.registerEvents(new PlayerJoin(this), this);
我没有看到 PlayerJoin 函数,只有构造函数。顺便说一句,函数名以大写字母开头是一种不好的做法,除非它是构造函数。