All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
cn.nukkit.command.defaults.ExecuteCommandOld Maven / Gradle / Ivy
package cn.nukkit.command.defaults;
import cn.nukkit.api.PowerNukkitXOnly;
import cn.nukkit.api.Since;
import cn.nukkit.command.CommandSender;
import cn.nukkit.command.ExecutorCommandSender;
import cn.nukkit.command.data.CommandParamType;
import cn.nukkit.command.data.CommandParameter;
import cn.nukkit.command.tree.ParamList;
import cn.nukkit.command.tree.node.PositionNode;
import cn.nukkit.command.utils.CommandLogger;
import cn.nukkit.entity.Entity;
import cn.nukkit.level.Location;
import cn.nukkit.level.Position;
import java.util.List;
import java.util.Map;
@PowerNukkitXOnly
@Since("1.6.0.0-PNX")
public class ExecuteCommandOld extends VanillaCommand {
public ExecuteCommandOld(String name) {
super(name, "old execute command", "commands.execute.usage");
this.setPermission("nukkit.command.executeold");
this.commandParameters.clear();
this.commandParameters.put("default", new CommandParameter[]{
CommandParameter.newType("origin", CommandParamType.TARGET),
CommandParameter.newType("position", CommandParamType.POSITION),
CommandParameter.newType("command", CommandParamType.COMMAND)
});
this.commandParameters.put("detect", new CommandParameter[]{
CommandParameter.newType("origin", CommandParamType.TARGET),
CommandParameter.newType("position", CommandParamType.POSITION),
CommandParameter.newEnum("detect", new String[]{"detect"}),
CommandParameter.newType("detectPos", CommandParamType.POSITION),
CommandParameter.newType("block", CommandParamType.INT),
CommandParameter.newType("data", CommandParamType.INT),
CommandParameter.newType("command", CommandParamType.COMMAND)
});
this.enableParamTree();
}
@Since("1.19.60-r1")
@Override
public int execute(CommandSender sender, String commandLabel, Map.Entry result, CommandLogger log) {
int num = 0;
var list = result.getValue();
List entities = list.getResult(0);
if (entities.isEmpty()) {
log.addNoTargetMatch().output();
return 0;
}
switch (result.getKey()) {
case "default" -> {
String command = list.getResult(2);
for (Entity entity : entities) {
Position pos = ((PositionNode) list.get(1)).get(entity);
ExecutorCommandSender executeSender = new ExecutorCommandSender(sender, entity, Location.fromObject(pos));
int n = executeSender.getServer().executeCommand(executeSender, command);
if (n == 0) {
log.addError("commands.execute.failed", command, entity.getName());
} else num += n;
}
}
case "detect" -> {
int blockid = list.getResult(4);
int meta = list.getResult(5);
String command = list.getResult(6);
for (Entity entity : entities) {
Position pos = ((PositionNode) list.get(1)).get(entity);
Position detect = ((PositionNode) list.get(3)).get(pos);
if (detect.getLevelBlock().getId() == blockid && detect.getLevelBlock().getDamage() == meta) {
ExecutorCommandSender executeSender = new ExecutorCommandSender(sender, entity, Location.fromObject(pos));
int n = executeSender.getServer().executeCommand(executeSender, command);
if (n == 0) {
log.addError("commands.execute.failed", command, entity.getName());
} else num += n;
}
}
}
}
log.output();
return num;
}
}