Bukkit Java错误:OnStartup类型未定义PlayerJoin(OnStartup)方法

时间:2016-01-29 00:53:03

标签: java minecraft bukkit

所以,我最近开始学习Java和BukkitAPI。我创建了一个配置文件,然后为播放器事件创建了一个类,但是我无法在主类中注册事件。我收到一个错误“方法PlayerJoin(OnStartup)未定义类型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;

}

}

PlayerJoin:

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

1 个答案:

答案 0 :(得分:1)

你可能意味着:

pm.registerEvents(new PlayerJoin(this), this);

我没有看到PlayerJoin函数,只看到构造函数。顺便说一下,用大写字母开始一个函数名是不好的做法,除非它是构造函数。