英文:
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) {
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论