Java Minecraft Bukkit推广插件

时间:2016-03-13 21:37:15

标签: java minecraft

这是我的代码:

package meg.zach.d;

import org.apache.logging.log4j.core.jmx.Server;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import net.md_5.bungee.api.ChatColor;

public class Main extends JavaPlugin {
    public void onEnable() {
        getLogger().info("Plugin Enabled");
    }

    public void onDisable() {

    }

    @SuppressWarnings("deprecation")
    public boolean onCommand(CommandSender sender, Command cmd, String label, String args[]) {
        Player p = (Player) sender;
        if (cmd.getName().equalsIgnoreCase("promote") && sender instanceof Player) {
            if (args[0] == "mod") {
                for (Player playerToPromote : Bukkit.getServer().getOnlinePlayers()) {
                    if (playerToPromote.getName().equalsIgnoreCase(args[1])) {
                        String modN = ChatColor.GRAY + "[Mod] ";
                        playerToPromote.setDisplayName(modN + playerToPromote.getDisplayName());
                        String modb = ChatColor.YELLOW + "has been promoted into a ";
                        String mod = ChatColor.GOLD + "Mod ";
                        Bukkit.getServer().broadcastMessage(playerToPromote + modb + mod);

                    }
                    else if(!(playerToPromote.isOnline())){
                        p.sendMessage(ChatColor.RED + "player not online");
                    }
                }

            }


        }
        return false;
    }

所以我的问题是,当我执行/推广和修改并命名时,它不会更改显示名称或任何内容,并且getOnlinePlayers由于某种原因而被弃用。 有谁知道如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

好吧,我已经重写了代码看起来像这样:

<div id="copyright">
    <p id="copyright-invert">
        Copyright &#169;
    <!-- function for year change  -->
        <script type="text/javascript">
            now=new Date();
            year=now.getFullYear(); 
        </script> 
        <script type="text/javascript">
            document.write(year);
        </script>
        | All Rights Reserved
        <br/>
          UPDATED: <span class="timestamp"></span>
    </p>
</div>
</body>
</html>

请记住,此代码未经过测试,但如果您稍微更改一下,它应该可以正常工作。

您还需要在plugin.yml中定义命令。您可以在此处查找如何创建plugin.yml:http://wiki.bukkit.org/Plugin_YAML

答案 1 :(得分:0)

我刚用它写过它,所以我不知道一切是否正确,但如果它不对,那就差不多了!因此,isOfflinePlayer()也可以是isOnlinePlayer() ...

public boolean onCommand(CommandSender sender, Command cmd, String label, String args[]) {
    Player p = (Player) sender;
    if (cmd.getName().equalsIgnoreCase("promote") && sender instanceof Player) {
        if (args[0] == "mod") {
            Player playerToPromote = Bukkit.getPlayer(args[1]);
            if (!playerToPromote.isOfflinePlayer()) {
                    String modN = ChatColor.GRAY + "[Mod] ";
                    playerToPromote.setDisplayName(modN + playerToPromote.getDisplayName());
                    String modb = ChatColor.YELLOW + "has been promoted into a ";
                    String mod = ChatColor.GOLD + "Mod ";
                    Bukkit.getServer().broadcastMessage(playerToPromote + modb + mod);
                    playerToPromote.update();
                } else {
                    p.sendMessage(ChatColor.RED + "player not online");
                }

        }


    }
    return false;
}

你必须在plugin.yml注册你的命令,我不知道update()方法是否真的存在......但是有了一个库存就像这样。 抱歉我的英语不好,如果它仍然无法正常处理我的答案;)