use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class TimingsCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
if (args.length != 1) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", usageMessage));
return true;
}
String mode = args[0].toLowerCase();
if (mode.equals("on")) {
Timings.setTimingsEnabled(true);
Timings.reset();
sender.sendMessage(new TranslationContainer("nukkit.command.timings.enable"));
return true;
} else if (mode.equals("off")) {
Timings.setTimingsEnabled(false);
sender.sendMessage(new TranslationContainer("nukkit.command.timings.disable"));
return true;
}
if (!Timings.isTimingsEnabled()) {
sender.sendMessage(new TranslationContainer("nukkit.command.timings.timingsDisabled"));
return true;
}
switch(mode) {
case "verbon":
sender.sendMessage(new TranslationContainer("nukkit.command.timings.verboseEnable"));
Timings.setVerboseEnabled(true);
break;
case "verboff":
sender.sendMessage(new TranslationContainer("nukkit.command.timings.verboseDisable"));
Timings.setVerboseEnabled(true);
break;
case "reset":
Timings.reset();
sender.sendMessage(new TranslationContainer("nukkit.command.timings.reset"));
break;
case "report":
case "paste":
TimingsExport.reportTimings(sender);
break;
}
return true;
}
use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class TitleCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
if (args.length < 2) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return false;
}
Player player = Server.getInstance().getPlayerExact(args[0]);
if (player == null) {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
return true;
}
if (args.length == 2) {
switch(args[1].toLowerCase()) {
case "clear":
player.clearTitle();
sender.sendMessage(new TranslationContainer("nukkit.command.title.clear", player.getName()));
break;
case "reset":
player.resetTitleSettings();
sender.sendMessage(new TranslationContainer("nukkit.command.title.reset", player.getName()));
break;
default:
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return false;
}
} else if (args.length == 3) {
switch(args[1].toLowerCase()) {
case "title":
player.sendTitle(args[2]);
sender.sendMessage(new TranslationContainer("nukkit.command.title.title", new String[] { TextFormat.clean(args[2]), player.getName() }));
break;
/*case "subtitle":
player.setSubtitle(args[2]);
sender.sendMessage(new TranslationContainer("nukkit.command.title.subtitle", new String[]{TextFormat.clean(args[2]), player.getName()}));
break;
case "actionbar":
player.sendActionBarTitle(args[2]);
sender.sendMessage(new TranslationContainer("nukkit.command.title.actionbar", new String[]{TextFormat.clean(args[2]), player.getName()}));
break;*/
default:
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return false;
}
} else if (args.length == 5) {
if (args[1].toLowerCase().equals("times")) {
try {
/*player.setTitleAnimationTimes(Integer.valueOf(args[2]), //fadeIn
Integer.valueOf(args[3]), //stay
Integer.valueOf(args[4])); //fadeOut*/
sender.sendMessage(new TranslationContainer("nukkit.command.title.times.success", new String[] { args[2], args[3], args[4], player.getName() }));
} catch (NumberFormatException exception) {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%nukkit.command.title.times.fail"));
}
} else {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return false;
}
} else {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return false;
}
return true;
}
use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class VersionCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
if (args.length == 0) {
sender.sendMessage(new TranslationContainer("nukkit.server.info.extended", new String[] { sender.getServer().getName(), sender.getServer().getNukkitVersion(), sender.getServer().getCodename(), sender.getServer().getApiVersion(), sender.getServer().getVersion(), String.valueOf(ProtocolInfo.CURRENT_PROTOCOL) }));
} else {
String pluginName = "";
for (String arg : args) pluginName += arg + " ";
pluginName = pluginName.trim();
final boolean[] found = { false };
final Plugin[] exactPlugin = { sender.getServer().getPluginManager().getPlugin(pluginName) };
if (exactPlugin[0] == null) {
pluginName = pluginName.toLowerCase();
final String finalPluginName = pluginName;
sender.getServer().getPluginManager().getPlugins().forEach((s, p) -> {
if (s.toLowerCase().contains(finalPluginName)) {
exactPlugin[0] = p;
found[0] = true;
}
});
} else {
found[0] = true;
}
if (found[0]) {
PluginDescription desc = exactPlugin[0].getDescription();
sender.sendMessage(TextFormat.DARK_GREEN + desc.getName() + TextFormat.WHITE + " version " + TextFormat.DARK_GREEN + desc.getVersion());
if (desc.getDescription() != null) {
sender.sendMessage(desc.getDescription());
}
if (desc.getWebsite() != null) {
sender.sendMessage("Website: " + desc.getWebsite());
}
List<String> authors = desc.getAuthors();
final String[] authorsString = { "" };
authors.forEach((s) -> authorsString[0] += s);
if (authors.size() == 1) {
sender.sendMessage("Author: " + authorsString[0]);
} else if (authors.size() >= 2) {
sender.sendMessage("Authors: " + authorsString[0]);
}
} else {
sender.sendMessage(new TranslationContainer("nukkit.command.version.noSuchPlugin"));
}
}
return true;
}
use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class WeatherCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
if (args.length == 0 || args.length > 2) {
sender.sendMessage(new TranslationContainer("commands.weather.usage", this.usageMessage));
return false;
}
String weather = args[0];
Level level;
int seconds;
if (args.length > 1) {
try {
seconds = Integer.parseInt(args[1]);
} catch (Exception e) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
}
} else {
seconds = 600 * 20;
}
if (sender instanceof Player) {
level = ((Player) sender).getLevel();
} else {
level = sender.getServer().getDefaultLevel();
}
switch(weather) {
case "clear":
level.setRaining(false);
level.setThundering(false);
level.setRainTime(seconds * 20);
level.setThunderTime(seconds * 20);
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.weather.clear"));
return true;
case "rain":
level.setRaining(true);
level.setRainTime(seconds * 20);
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.weather.rain"));
return true;
case "thunder":
level.setThundering(true);
level.setRainTime(seconds * 20);
level.setThunderTime(seconds * 20);
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.weather.thunder"));
return true;
default:
sender.sendMessage(new TranslationContainer("commands.weather.usage", this.usageMessage));
return false;
}
}
use of cn.nukkit.lang.TranslationContainer in project Nukkit by Nukkit.
the class SimpleCommandMap method dispatch.
@Override
public boolean dispatch(CommandSender sender, String cmdLine) {
ArrayList<String> parsed = parseArguments(cmdLine);
if (parsed.size() == 0) {
return false;
}
String sentCommandLabel = parsed.remove(0).toLowerCase();
String[] args = parsed.toArray(new String[parsed.size()]);
Command target = this.getCommand(sentCommandLabel);
if (target == null) {
return false;
}
target.timing.startTiming();
try {
target.execute(sender, sentCommandLabel, args);
} catch (Exception e) {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.exception"));
this.server.getLogger().critical(this.server.getLanguage().translateString("nukkit.command.exception", cmdLine, target.toString(), Utils.getExceptionMessage(e)));
MainLogger logger = sender.getServer().getLogger();
if (logger != null) {
logger.logException(e);
}
}
target.timing.stopTiming();
return true;
}
Aggregations