minecraft player.sendMessage command plugin not working

huangapple go评论86阅读模式
英文:

minecraft player.sendMessage command plugin not working

问题

package com.legroom.applyplugin.Commands;

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

public class commands implements CommandExecutor {

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

        Player player = (Player) sender;
        if (sender == null) {
        }

        if (cmd.getName().equalsIgnoreCase("famous")) {
            player.sendMessage("§7§m----------------------------");
            player.sendMessage("§3» §3Requirements:");
            player.sendMessage("§3» §f500+ Subscribers");
            player.sendMessage("§3» §f1+ vid on the server");
            player.sendMessage("§3» §fReasonable views/likes");
            player.sendMessage("");
            player.sendMessage("§3» To apply, use:");
            player.sendMessage("§3    » §fMedia.nivina.cc");
            player.sendMessage("");
            player.sendMessage("§7§m----------------------------");

            if (cmd.getName().equalsIgnoreCase("appeal")) {
                player.sendMessage("§7§m----------------------------");
                player.sendMessage("");
                player.sendMessage("§3» To appeal, use:");
                player.sendMessage("§3     » §fDiscord.nivina.cc");
                player.sendMessage("");
                player.sendMessage("§7§m----------------------------");

                if (cmd.getName().equalsIgnoreCase("apply")) {
                    player.sendMessage("§7§m----------------------------");
                    player.sendMessage("");
                    player.sendMessage("§3» To apply, use:");
                    player.sendMessage("§3    » §fStaff.nivina.cc");
                    player.sendMessage("§3    » §fMedia.nivina.cc");
                    player.sendMessage("");
                    player.sendMessage("§7§m----------------------------");

                    if (cmd.getName().equalsIgnoreCase("youtube")) {
                        player.sendMessage("§7§m----------------------------");
                        player.sendMessage("§3» §3Requirements:");
                        player.sendMessage("§3 » §f200+ Subscribers");
                        player.sendMessage("   » §f1+ vid on the server");
                        player.sendMessage("§3 » §fReasonable views/likes");
                        player.sendMessage("");
                        player.sendMessage("§3» To apply, use:");
                        player.sendMessage("§3» §fMedia.nivina.cc");
                        player.sendMessage("");
                        player.sendMessage("§7§m----------------------------");
                    }
                    return true;
                }
                return true;
            }
            return true;
        }
        return true;
    }
}
英文:

I'm new to coding and I am making a Minecraft command plugin for my mate, the plugin sends a message to the player when they use the command. I can't seem to get all of them working, only the first command will work on the server, I've tried everything I know like if-else, etc can someone help, please?

package com.legroom.applyplugin.Commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class commands implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player player = (Player) sender;
if (sender == null) {
}
if
(cmd.getName().equalsIgnoreCase("famous")) {
player.sendMessage("§7§m----------------------------");
player.sendMessage("§3» §3Requirements:");
player.sendMessage("§3» §f500+ Subscribers");
player.sendMessage("§3» §f1+ vid on the server");
player.sendMessage("§3» §fReasonable views/likes");
player.sendMessage("");
player.sendMessage("§3» To apply, use:");
player.sendMessage("§3    » §fMedia.nivina.cc");
player.sendMessage("");
player.sendMessage("§m----------------------------");
if
(cmd.getName().equalsIgnoreCase("appeal")) {
player.sendMessage("§7§m----------------------------");
player.sendMessage("");
player.sendMessage("§3» To appeal, use:");
player.sendMessage("§3     »§fDiscord.nivina.cc");
player.sendMessage("");
player.sendMessage("§7§m----------------------------");
if
(cmd.getName().equalsIgnoreCase("apply")) {
player.sendMessage("§7§m----------------------------");
player.sendMessage("");
player.sendMessage("§3» To apply, use:");
player.sendMessage("§3    » §fStaff.nivina.cc");
player.sendMessage("§3    » §fMedia.nivina.cc");
player.sendMessage("");
player.sendMessage("§7§m----------------------------");
if
(cmd.getName().equalsIgnoreCase("youtube")) {
player.sendMessage("§7§m----------------------------");
player.sendMessage("§3» §3Requirements:");
player.sendMessage("§3 » §f200+ Subscribers");
player.sendMessage("   » §f1+ vid on the server");
player.sendMessage("§3 » §fReasonable views/likes");
player.sendMessage("");
player.sendMessage("§3» To apply, use:");
player.sendMessage("§3» §fMedia.nivina.cc");
player.sendMessage("");
player.sendMessage("§m----------------------------");
}
return true;
}
return true;
}
return true;
}
return true;
}
}
'''

答案1

得分: 0

你正在嵌套你的 if 语句:

if (condition) {
   if (someOtherConditionThatConflictsWithFirstCondition) {
     // 永远不会执行
   }
}

第二个 if 语句位于第一个 if 语句的花括号内部,只有在第一个条件为真时才会执行。但是你的条件是对同一个字符串进行等值比较,因此如果第一个条件评估为 true,第二个条件就无法评估为 true

你需要做的是将它们放在一起:

if (condition) {
}
if (someOtherCondition) {
}
if (thirdCondition) {
}

或者选择另一种写法:

if (condition) {
}
else if (someOtherCondition) {
}
else if (thirdCondition) {
}
英文:

You are nesting your if-statements:

if (condition) {
if (someOtherConditionThatConflictsWithFirstCondition) {
// Never reached
}
}

The second if-statement, because it is contained within the curly braces of the first, is only reached if the first condition evaluates to true. But your conditions are equals-operations on the same String, so if the first condition evaluates to true, the second cannot evaluate to true.

What you need to do instead is place them after one another:

if (condition) {
}
if (someOtherCondition) {
}
if (thirdCondition) {
}

Or alternatively:

if (condition) {
}
else if (someOtherCondition) {
}
else if (thirdCondition) {
}

huangapple
  • 本文由 发表于 2020年10月27日 16:05:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/64550306.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定