use of cn.nukkit.command.CommandSender in project Nukkit by Nukkit.
the class TeleportCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
if (args.length < 1 || args.length > 6) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
}
CommandSender target;
CommandSender origin = sender;
if (args.length == 1 || args.length == 3) {
if (sender instanceof Player) {
target = sender;
} else {
sender.sendMessage(new TranslationContainer("commands.generic.ingame"));
return true;
}
if (args.length == 1) {
target = sender.getServer().getPlayer(args[0]);
if (target == null) {
sender.sendMessage(TextFormat.RED + "Can't find player " + args[0]);
return true;
}
}
} else {
target = sender.getServer().getPlayer(args[0]);
if (target == null) {
sender.sendMessage(TextFormat.RED + "Can't find player " + args[0]);
return true;
}
if (args.length == 2) {
origin = target;
target = sender.getServer().getPlayer(args[1]);
if (target == null) {
sender.sendMessage(TextFormat.RED + "Can't find player " + args[1]);
return true;
}
}
}
if (args.length < 3) {
((Player) origin).teleport((Player) target, PlayerTeleportEvent.TeleportCause.COMMAND);
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.tp.success", new String[] { origin.getName(), target.getName() }));
return true;
} else if (((Player) target).getLevel() != null) {
int pos;
if (args.length == 4 || args.length == 6) {
pos = 1;
} else {
pos = 0;
}
double x;
double y;
double z;
double yaw;
double pitch;
try {
x = Double.parseDouble(args[pos++]);
y = Double.parseDouble(args[pos++]);
z = Double.parseDouble(args[pos++]);
yaw = ((Player) target).getYaw();
pitch = ((Player) target).getPitch();
} catch (NumberFormatException e1) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
}
if (y < 0)
y = 0;
if (y > 256)
y = 256;
if (args.length == 6 || (args.length == 5 && pos == 3)) {
yaw = Integer.parseInt(args[pos++]);
pitch = Integer.parseInt(args[pos++]);
}
((Player) target).teleport(new Location(x, y, z, yaw, pitch, ((Player) target).getLevel()), PlayerTeleportEvent.TeleportCause.COMMAND);
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.tp.success.coordinates", new String[] { target.getName(), String.valueOf(NukkitMath.round(x, 2)), String.valueOf(NukkitMath.round(y, 2)), String.valueOf(NukkitMath.round(z, 2)) }));
return true;
}
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
}
use of cn.nukkit.command.CommandSender in project LuckPerms by lucko.
the class NukkitCommandExecutor method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Sender lpSender = this.plugin.getSenderFactory().wrap(sender);
onCommand(lpSender, label, new ArrayList<>(Arrays.asList(args)));
return true;
}
use of cn.nukkit.command.CommandSender in project Nukkit by Nukkit.
the class TimingsExport method reportTimings.
/**
* Builds a JSON timings report and sends it to Aikar's viewer
*
* @param sender Sender that issued the command
*/
public static void reportTimings(CommandSender sender) {
JsonObject out = new JsonObject();
out.addProperty("version", Server.getInstance().getVersion());
out.addProperty("maxplayers", Server.getInstance().getMaxPlayers());
out.addProperty("start", TimingsManager.timingStart / 1000);
out.addProperty("end", System.currentTimeMillis() / 1000);
out.addProperty("sampletime", (System.currentTimeMillis() - TimingsManager.timingStart) / 1000);
if (!Timings.isPrivacy()) {
out.addProperty("server", Server.getInstance().getName());
out.addProperty("motd", Server.getInstance().getMotd());
// In MCPE we have permanent offline mode.
out.addProperty("online-mode", false);
// "data:image/png;base64,"
out.addProperty("icon", "");
}
final Runtime runtime = Runtime.getRuntime();
RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
JsonObject system = new JsonObject();
system.addProperty("timingcost", getCost());
system.addProperty("name", System.getProperty("os.name"));
system.addProperty("version", System.getProperty("os.version"));
system.addProperty("jvmversion", System.getProperty("java.version"));
system.addProperty("arch", System.getProperty("os.arch"));
system.addProperty("maxmem", runtime.maxMemory());
system.addProperty("cpu", runtime.availableProcessors());
system.addProperty("runtime", ManagementFactory.getRuntimeMXBean().getUptime());
system.addProperty("flags", String.join(" ", runtimeBean.getInputArguments()));
system.add("gc", JsonUtil.mapToObject(ManagementFactory.getGarbageCollectorMXBeans(), (input) -> new JsonUtil.JSONPair(input.getName(), JsonUtil.toArray(input.getCollectionCount(), input.getCollectionTime()))));
out.add("system", system);
TimingsHistory[] history = HISTORY.toArray(new TimingsHistory[HISTORY.size() + 1]);
// Current snapshot
history[HISTORY.size()] = new TimingsHistory();
JsonObject timings = new JsonObject();
for (TimingIdentifier.TimingGroup group : TimingIdentifier.GROUP_MAP.values()) {
for (Timing id : group.timings.stream().toArray(Timing[]::new)) {
if (!id.timed && !id.isSpecial()) {
continue;
}
timings.add(String.valueOf(id.id), JsonUtil.toArray(group.id, id.name));
}
}
JsonObject idmap = new JsonObject();
idmap.add("groups", JsonUtil.mapToObject(TimingIdentifier.GROUP_MAP.values(), (group) -> new JsonUtil.JSONPair(group.id, group.name)));
idmap.add("handlers", timings);
idmap.add("worlds", JsonUtil.mapToObject(TimingsHistory.levelMap.entrySet(), (entry) -> new JsonUtil.JSONPair(entry.getValue(), entry.getKey())));
idmap.add("tileentity", JsonUtil.mapToObject(TimingsHistory.blockEntityMap.entrySet(), (entry) -> new JsonUtil.JSONPair(entry.getKey(), entry.getValue())));
idmap.add("entity", JsonUtil.mapToObject(TimingsHistory.entityMap.entrySet(), (entry) -> new JsonUtil.JSONPair(entry.getKey(), entry.getValue())));
out.add("idmap", idmap);
// Information about loaded plugins
out.add("plugins", JsonUtil.mapToObject(Server.getInstance().getPluginManager().getPlugins().values(), (plugin) -> {
JsonObject jsonPlugin = new JsonObject();
jsonPlugin.addProperty("version", plugin.getDescription().getVersion());
// Sounds legit
jsonPlugin.addProperty("description", plugin.getDescription().getDescription());
jsonPlugin.addProperty("website", plugin.getDescription().getWebsite());
jsonPlugin.addProperty("authors", String.join(", ", plugin.getDescription().getAuthors()));
return new JsonUtil.JSONPair(plugin.getName(), jsonPlugin);
}));
// Information on the users Config
JsonObject config = new JsonObject();
if (!Timings.getIgnoredConfigSections().contains("all")) {
JsonObject nukkit = JsonUtil.toObject(Server.getInstance().getConfig().getRootSection());
Timings.getIgnoredConfigSections().forEach(nukkit::remove);
config.add("nukkit", nukkit);
} else {
config.add("nukkit", null);
}
out.add("config", config);
new TimingsExport(sender, out, history).start();
}
use of cn.nukkit.command.CommandSender in project Nukkit by Nukkit.
the class GamemodeCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (args.length == 0) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return false;
}
int gameMode = Server.getGamemodeFromString(args[0]);
if (gameMode == -1) {
sender.sendMessage("Unknown game mode");
return true;
}
CommandSender target = sender;
if (args.length > 1) {
if (sender.hasPermission("nukkit.command.gamemode.other")) {
target = sender.getServer().getPlayer(args[1]);
if (target == null) {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
return true;
}
} else {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));
return true;
}
} else if (!(sender instanceof Player)) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
}
if ((gameMode == 0 && !sender.hasPermission("nukkit.command.gamemode.survival")) || (gameMode == 1 && !sender.hasPermission("nukkit.command.gamemode.creative")) || (gameMode == 2 && !sender.hasPermission("nukkit.command.gamemode.adventure")) || (gameMode == 3 && !sender.hasPermission("nukkit.command.gamemode.spectator"))) {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));
return true;
}
if (!((Player) target).setGamemode(gameMode)) {
sender.sendMessage("Game mode update for " + target.getName() + " failed");
} else {
if (target.equals(sender)) {
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.gamemode.success.self", Server.getGamemodeString(gameMode)));
} else {
target.sendMessage(new TranslationContainer("gameMode.changed"));
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.gamemode.success.other", new String[] { target.getName(), Server.getGamemodeString(gameMode) }));
}
}
return true;
}
Aggregations