gpt4 book ai didi

java - Bukkit Java错误: The method PlayerJoin(OnStartup) is undefined for the type OnStartup

转载 作者:行者123 更新时间:2023-12-01 10:31:13 25 4
gpt4 key购买 nike

所以,我最近开始学习Java和BukkitAPI。我创建了一个配置文件,并为玩家事件创建了一个类,但随后我无法在主类中注册事件。我收到错误“对于 OnStartup 类型,未定义方法 PlayerJoin(OnStartup)”,唯一的修复方法是创建一个方法。这是我的代码:

OnStartup(主类):

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();
}

}

药剂类(以防万一):

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 - Bukkit Java错误: The method PlayerJoin(OnStartup) is undefined for the type OnStartup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35075052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com