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.TitlerawCommand Maven / Gradle / Ivy
package cn.nukkit.command.defaults;
import cn.nukkit.Player;
import cn.nukkit.api.PowerNukkitXOnly;
import cn.nukkit.api.Since;
import cn.nukkit.command.CommandSender;
import cn.nukkit.command.data.CommandEnum;
import cn.nukkit.command.data.CommandParamType;
import cn.nukkit.command.data.CommandParameter;
import cn.nukkit.command.tree.ParamList;
import cn.nukkit.command.utils.CommandLogger;
import cn.nukkit.command.utils.RawText;
import cn.nukkit.utils.TextFormat;
import java.util.List;
import java.util.Map;
@PowerNukkitXOnly
@Since("1.6.0.0-PNX")
public class TitlerawCommand extends VanillaCommand {
public TitlerawCommand(String name) {
super(name, "commands.titleraw.description");
this.setPermission("nukkit.command.titleraw");
this.commandParameters.clear();
this.commandParameters.put("clear", new CommandParameter[]{
CommandParameter.newType("player", CommandParamType.TARGET),
CommandParameter.newEnum("clear", new CommandEnum("TitleClear", "clear"))
});
this.commandParameters.put("reset", new CommandParameter[]{
CommandParameter.newType("player", CommandParamType.TARGET),
CommandParameter.newEnum("reset", new CommandEnum("TitleReset", "reset"))
});
this.commandParameters.put("set", new CommandParameter[]{
CommandParameter.newType("player", CommandParamType.TARGET),
CommandParameter.newEnum("titleLocation", new CommandEnum("TitleSet", "title", "subtitle", "actionbar")),
CommandParameter.newType("titleJson", CommandParamType.RAWTEXT)
});
this.commandParameters.put("times", new CommandParameter[]{
CommandParameter.newType("player", CommandParamType.TARGET),
CommandParameter.newEnum("times", new CommandEnum("TitleTimes", "times")),
CommandParameter.newType("fadeIn", CommandParamType.INT),
CommandParameter.newType("stay", CommandParamType.INT),
CommandParameter.newType("fadeOut", CommandParamType.INT)
});
this.enableParamTree();
}
@Since("1.19.60-r1")
@Override
public int execute(CommandSender sender, String commandLabel, Map.Entry result, CommandLogger log) {
var list = result.getValue();
List players = list.getResult(0);
if (players.isEmpty()) {
log.addNoTargetMatch().output();
return 0;
}
switch (result.getKey()) {
case "clear" -> {
for (Player player : players) {
player.clearTitle();
log.addMessage(TextFormat.WHITE + "%nukkit.command.title.clear", player.getName());
}
log.output();
return 1;
}
case "reset" -> {
for (Player player : players) {
player.resetTitleSettings();
log.addMessage(TextFormat.WHITE + "%nukkit.command.title.reset", player.getName());
}
log.output();
return 1;
}
case "set" -> {
String titleLocation = list.getResult(1);
RawText rawText = list.getResult(2);
switch (titleLocation) {
case "title" -> {
for (Player player : players) {
player.setRawTextTitle(rawText);
log.addSuccess("commands.titleraw.success");
}
log.output();
}
case "subtitle" -> {
for (Player player : players) {
player.setRawTextSubTitle(rawText);
log.addSuccess("commands.titleraw.success");
}
log.output();
}
case "actionbar" -> {
for (Player player : players) {
player.setRawTextActionBar(rawText);
log.addSuccess("commands.titleraw.success");
}
log.output();
}
default -> {
log.addMessage("commands.generic.usage", "\n" + this.getCommandFormatTips());
return 0;
}
}
return 1;
}
case "times" -> {
int fadeIn = list.getResult(2);
int stay = list.getResult(3);
int fadeOut = list.getResult(4);
for (var player : players) {
log.addMessage(TextFormat.WHITE + "%nukkit.command.title.times.success", String.valueOf(fadeIn), String.valueOf(stay), String.valueOf(fadeOut), player.getName());
}
log.output();
return 1;
}
default -> {
return 0;
}
}
}
}