minecraft插件无法识别内容

时间:2019-02-14 13:44:55

标签: java minecraft bukkit

因此,即时通讯创建了一个应该冻结我的简单冻结插件。不知何故它无法工作,因为它无法识别我的命令。该插件应该通过将编写插件的播放器添加到toggleList上来启用。 我有3个班级。

main class (Freeze.java)

package net.parinacraft.freeze;

    import org.bukkit.material.Command;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    import java.util.ArrayList;
    import java.util.List;
    import java.util.UUID;
    import net.parinacraft.freeze.player.commands.komento;
    import net.parinacraft.freeze.komento;

    public class Freeze extends JavaPlugin {
        public static List<UUID> toggleList = new ArrayList<UUID>();

        @Override
        public void onEnable(){
            registerCommands();
            registerEvents();
        }

        public void registerCommands() {
            getCommand("freeze").setExecutor(new komento());
        }

        public void registerEvents(){
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(new Toggle(), this);
        }
    }

我认为该命令的第二类(komento.java)

    package net.parinacraft.freeze;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.material.Command;

public class komento implements CommandExecutor {

    @Override
    public boolean onCommand(CommandSender sender, Command Freeze, String label, String[] args){
        if(!(sender instanceof Player)){
            sender.sendMessage(ChatColor.RED + "Sinun pitää olla pelaaja käyttääkseen tätä komentoa");
            return true;
        }
        Player player = (Player) sender;
        if(!Freeze.toggleList.contains(player.getUniqueId())){
            player.sendMessage(ChatColor.GREEN + "sinut on jäädytetty tutkinnan ajaksi");
            Freeze.toggleList.add(player.getUniqueId());
        } else{
            player.sendMessage(ChatColor.RED +"Et ole enään jäädytetty");
            Freeze.toggleList.remove(player.getUniqueId());
        }
        return true;
    }

}

然后是我的第三堂课,用于打开/关闭命令 (Toggle.java)

package net.parinacraft.freeze;


import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;

import package net.parinacraft.;


public class Toggle implements Listener {
    @EventHandler
    public void onPlayerMove(PlayerMoveEvent evt) {
        Player player = evt.getPlayer();
        if (Freeze.togglelist.contains(player.getUniqueId())){
            Location back = new Location(evt.getFrom().getWorld(), evt.getFrom().getX(), evt.getFrom().getY(), evt.getFrom().getZ());
            evt.getPlayer().teleport(back);
        }
    }
}

我还应该添加到plugin.yml吗?

1 个答案:

答案 0 :(得分:2)

因为您没有发布plugin.yml文件,我想您在其中缺少冻结命令的定义。

典型的plugin.yml文件包含commands部分,其中定义了所有插件命令。

name: Inferno
version: 1.4.1
description: This plugin is so 31337. You can set yourself on fire.
author: CaptainInflamo
authors: [Cogito, verrier, EvilSeph] 
website: http://forums.bukkit.org/threads/MyPlugin.31337/

main: com.captaininflamo.bukkit.inferno.Inferno
database: false
depend: [NewFire, FlameWire]

commands:
  flagrate:
    description: Set yourself on fire.
    aliases: [combust_me, combustMe]
    permission: inferno.flagrate
    usage: Syntax error! Simply type /&lt;command&gt; to ignite yourself.

在您的情况下,您可能应该添加:

commands:
  freeze:
    description: Freeze yourself.
    usage: Syntax error! Simply type /freeze to freeze yourself.

您可以在以下位置了解有关plugin.yml的信息: