Be careful when registering commands. It shouldn't break the plugin.
Found an error report in the wild suggesting that getCommand() might occationally fail (if plugin.yml isn't loaded properly, maybe) and return NULL instead. Since the commands are only for administrators and plugin authors, we'll simply ignore it if this occurs.
Dieser Commit ist enthalten in:
Ursprung
d53b6dbee1
Commit
03ad9be078
@ -23,6 +23,8 @@ import java.util.logging.LogRecord;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.PluginCommand;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
@ -187,8 +189,8 @@ public class ProtocolLibrary extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set up command handlers
|
// Set up command handlers
|
||||||
getCommand(CommandProtocol.NAME).setExecutor(commandProtocol);
|
registerCommand(CommandProtocol.NAME, commandProtocol);
|
||||||
getCommand(CommandPacket.NAME).setExecutor(commandPacket);
|
registerCommand(CommandPacket.NAME, commandPacket);
|
||||||
|
|
||||||
// Notify server managers of incompatible plugins
|
// Notify server managers of incompatible plugins
|
||||||
checkForIncompatibility(manager);
|
checkForIncompatibility(manager);
|
||||||
@ -218,6 +220,24 @@ public class ProtocolLibrary extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerCommand(String name, CommandExecutor executor) {
|
||||||
|
try {
|
||||||
|
if (executor == null)
|
||||||
|
throw new RuntimeException("Executor was NULL.");
|
||||||
|
|
||||||
|
PluginCommand command = getCommand(name);
|
||||||
|
|
||||||
|
// Try to load the command
|
||||||
|
if (command != null)
|
||||||
|
command.setExecutor(executor);
|
||||||
|
else
|
||||||
|
throw new RuntimeException("plugin.yml might be corrupt.");
|
||||||
|
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
reporter.reportWarning(this, "Cannot register command " + name + ": " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disable the current plugin.
|
* Disable the current plugin.
|
||||||
*/
|
*/
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren