cn.nukkit.command.PluginCommand Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powernukkit Show documentation
Show all versions of powernukkit Show documentation
A Minecraft Bedrock Edition server software implementation made in Java from scratch which supports all new features.
package cn.nukkit.command;
import cn.nukkit.lang.TranslationContainer;
import cn.nukkit.plugin.Plugin;
/**
* @author MagicDroidX (Nukkit Project)
*/
public class PluginCommand extends Command implements PluginIdentifiableCommand {
private final T owningPlugin;
private CommandExecutor executor;
public PluginCommand(String name, T owner) {
super(name);
this.owningPlugin = owner;
this.executor = owner;
this.usageMessage = "";
}
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.owningPlugin.isEnabled()) {
return false;
}
if (!this.testPermission(sender)) {
return false;
}
boolean success = this.executor.onCommand(sender, this, commandLabel, args);
if (!success && !this.usageMessage.equals("")) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
}
return success;
}
public CommandExecutor getExecutor() {
return executor;
}
public void setExecutor(CommandExecutor executor) {
this.executor = (executor != null) ? executor : this.owningPlugin;
}
@Override
public T getPlugin() {
return this.owningPlugin;
}
}