本文整理匯總了Java中cn.nukkit.command.CommandSender.sendMessage方法的典型用法代碼示例。如果您正苦於以下問題:Java CommandSender.sendMessage方法的具體用法?Java CommandSender.sendMessage怎麽用?Java CommandSender.sendMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cn.nukkit.command.CommandSender
的用法示例。
在下文中一共展示了CommandSender.sendMessage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: execute
import cn.nukkit.command.CommandSender; //導入方法依賴的package包/類
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
if(!this.testPermission(sender)) {
return true;
}
if(args.length >= 1){
String invite = args[0];
if(this.plugin.getShareSetting().containsKey(sender.getName())){
this.plugin.getShareSetting().remove(sender.getName());
sender.sendMessage(TextFormat.GRAY+"[ChestLocker] 你已退出設置箱子共享狀態");
}else{
this.plugin.getShareSetting().put(sender.getName(),invite);
sender.sendMessage(TextFormat.YELLOW+"[ChestLocker] 你希望與"+invite+"一起分享箱子嗎,確認請點擊想要分享的箱子,取消請重新輸入此命令");
}
}else if (args.length == 0){
if(this.plugin.getShareSetting().containsKey(sender.getName())){
this.plugin.getShareSetting().remove(sender.getName());
sender.sendMessage(TextFormat.GRAY+"[ChestLocker] 你已退出設置箱子共享狀態");
}else{
sender.sendMessage(TextFormat.YELLOW+"[ChestLocker] "+this.getUsage());
}
}
return true;
}
示例2: execute
import cn.nukkit.command.CommandSender; //導入方法依賴的package包/類
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
long seed;
if (sender instanceof Player) {
seed = ((Player) sender).getLevel().getSeed();
} else {
seed = sender.getServer().getDefaultLevel().getSeed();
}
sender.sendMessage(new TranslationContainer("commands.seed.success", String.valueOf(seed)));
return true;
}
示例3: execute
import cn.nukkit.command.CommandSender; //導入方法依賴的package包/類
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
String online = "";
int onlineCount = 0;
for (Player player : sender.getServer().getOnlinePlayers().values()) {
if (player.isOnline() && (!(sender instanceof Player) || ((Player) sender).canSee(player))) {
online += player.getDisplayName() + ", ";
++onlineCount;
}
}
if (online.length() > 0) {
online = online.substring(0, online.length() - 2);
}
sender.sendMessage(new TranslationContainer("commands.players.list",
new String[]{String.valueOf(onlineCount), String.valueOf(sender.getServer().getMaxPlayers())}));
sender.sendMessage(online);
return true;
}
示例4: execute
import cn.nukkit.command.CommandSender; //導入方法依賴的package包/類
@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", this.usageMessage));
return false;
}
int difficulty = Server.getDifficultyFromString(args[0]);
if (sender.getServer().isHardcore()) {
difficulty = 3;
}
if (difficulty != -1) {
sender.getServer().setPropertyInt("difficulty", difficulty);
SetDifficultyPacket pk = new SetDifficultyPacket();
pk.difficulty = sender.getServer().getDifficulty();
Server.broadcastPacket(new ArrayList<>(sender.getServer().getOnlinePlayers().values()), pk);
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.difficulty.success", String.valueOf(difficulty)));
} else {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return false;
}
return true;
}
示例5: execute
import cn.nukkit.command.CommandSender; //導入方法依賴的package包/類
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
if (args.length == 0) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return false;
}
String name = args[0];
String reason = "";
for (int i = 1; i < args.length; i++) {
reason += args[i] + " ";
}
if (reason.length() > 0) {
reason = reason.substring(0, reason.length() - 1);
}
Player player = sender.getServer().getPlayer(name);
if (player != null) {
player.kick(PlayerKickEvent.Reason.KICKED_BY_ADMIN, reason);
if (reason.length() >= 1) {
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.kick.success.reason", new String[]{player.getName(), reason})
);
} else {
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.kick.success", player.getName()));
}
} else {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
}
return true;
}
示例6: execute
import cn.nukkit.command.CommandSender; //導入方法依賴的package包/類
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
if (args.length == 0) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return false;
}
String senderString;
if (sender instanceof Player) {
senderString = ((Player) sender).getDisplayName();
} else if (sender instanceof ConsoleCommandSender) {
senderString = "Server";
} else {
senderString = sender.getName();
}
String msg = "";
for (String arg : args) {
msg += arg + " ";
}
if (msg.length() > 0) {
msg = msg.substring(0, msg.length() - 1);
}
sender.getServer().broadcastMessage(new TranslationContainer(
TextFormat.LIGHT_PURPLE + "%chat.type.announcement",
new String[]{senderString, TextFormat.LIGHT_PURPLE + msg}
));
return true;
}
示例7: onCommand
import cn.nukkit.command.CommandSender; //導入方法依賴的package包/類
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!this.testPermission(sender)) {
//sender.sendMessage(this.getPlugin().translateMessage("has-no-permission"));
return true;
}
if (args.length < 1) {
sender.sendMessage(this.getPlugin().translateMessage("see-bank-format-error", "cmd", this.getName()));
return true;
}
Player p = Utils.getPlayer(args[0]);
String name;
if (p == null) {
name = args[0];
} else {
name = p.getName();
}
if (Objects.equals(name, "")) {
sender.sendMessage(this.getPlugin().translateMessage("see-bank-format-error", "cmd", this.getName()));
return true;
}
sender.sendMessage(this.getPlugin().translateMessage("see-bank-success",
"player", name,
"amount", Money.getInstance().getBank(name)
));
return false;
}
示例8: execute
import cn.nukkit.command.CommandSender; //導入方法依賴的package包/類
@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 true;
}
Player player = sender.getServer().getPlayer(args[0]);
if (player == null) {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
return true;
}
int enchantId;
int enchantLevel;
try {
enchantId = getIdByName(args[1]);
enchantLevel = args.length == 3 ? Integer.parseInt(args[2]) : 1;
} catch (NumberFormatException e) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
}
Enchantment enchantment = Enchantment.getEnchantment(enchantId);
if (enchantment == null) {
sender.sendMessage(new TranslationContainer("commands.enchant.notFound", String.valueOf(enchantId)));
return true;
}
enchantment.setLevel(enchantLevel);
Item item = player.getInventory().getItemInHand();
if (item.getId() <= 0) {
sender.sendMessage(new TranslationContainer("commands.enchant.noItem"));
return true;
}
item.addEnchantment(enchantment);
player.getInventory().setItemInHand(item);
Command.broadcastCommandMessage(sender, new TranslationContainer("%commands.enchant.success"));
return true;
}
示例9: execute
import cn.nukkit.command.CommandSender; //導入方法依賴的package包/類
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
if (args.length == 0) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return false;
}
String name;
if (sender instanceof Player) {
name = ((Player) sender).getDisplayName();
} else {
name = sender.getName();
}
String msg = "";
for (String arg : args) {
msg += arg + " ";
}
if (msg.length() > 0) {
msg = msg.substring(0, msg.length() - 1);
}
sender.getServer().broadcastMessage(new TranslationContainer("chat.type.emote", new String[]{name, TextFormat.WHITE + msg}));
return true;
}
示例10: badPerm
import cn.nukkit.command.CommandSender; //導入方法依賴的package包/類
private boolean badPerm(CommandSender sender, String perm) {
if (!sender.hasPermission("nukkit.command.whitelist" + perm)) {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.permission"));
return true;
}
return false;
}
示例11: execute
import cn.nukkit.command.CommandSender; //導入方法依賴的package包/類
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
String name = sender.getName().toLowerCase();
if (players.contains(name)) {
players.remove(name);
sender.sendMessage(TextFormat.DARK_AQUA + "서버 정보 보기 비활성화");
} else {
players.add(name);
sender.sendMessage(TextFormat.DARK_AQUA + "서버 정보 보기 활성화");
}
return true;
}
示例12: onCommand
import cn.nukkit.command.CommandSender; //導入方法依賴的package包/類
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!this.testPermission(sender)) {
//sender.sendMessage(this.getPlugin().translateMessage("has-no-permission"));
return true;
}
if (args.length < 1) {
sender.sendMessage(this.getPlugin().translateMessage("see-money-format-error", "cmd", this.getName()));
return true;
}
Player p = Utils.getPlayer(args[0]);
String name;
if (p == null) {
name = args[0];
} else {
name = p.getName();
}
if (Objects.equals(name, "")) {
sender.sendMessage(this.getPlugin().translateMessage("see-money-format-error", "cmd", this.getName()));
return true;
}
sender.sendMessage(this.getPlugin().translateMessage("see-money-success",
"player", name,
"amount", Money.getInstance().getMoney(name),
"type", Money.getInstance().getCurrency1()
));
return false;
}
示例13: execute
import cn.nukkit.command.CommandSender; //導入方法依賴的package包/類
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
Server server = sender.getServer();
sender.sendMessage(TextFormat.GREEN + "---- " + TextFormat.WHITE + "Server status" + TextFormat.GREEN + " ----");
long time = (System.currentTimeMillis() - Nukkit.START_TIME) / 1000;
int seconds = NukkitMath.floorDouble(time % 60);
int minutes = NukkitMath.floorDouble((time % 3600) / 60);
int hours = NukkitMath.floorDouble(time % (3600 * 24) / 3600);
int days = NukkitMath.floorDouble(time / (3600 * 24));
String upTimeString = TextFormat.RED + "" + days + TextFormat.GOLD + " days " +
TextFormat.RED + hours + TextFormat.GOLD + " hours " +
TextFormat.RED + minutes + TextFormat.GOLD + " minutes " +
TextFormat.RED + seconds + TextFormat.GOLD + " seconds";
sender.sendMessage(TextFormat.GOLD + "Uptime: " + upTimeString);
TextFormat tpsColor = TextFormat.GREEN;
float tps = server.getTicksPerSecond();
if (tps < 17) {
tpsColor = TextFormat.GOLD;
} else if (tps < 12) {
tpsColor = TextFormat.RED;
}
sender.sendMessage(TextFormat.GOLD + "Current TPS: " + tpsColor + NukkitMath.round(tps, 2));
sender.sendMessage(TextFormat.GOLD + "Load: " + tpsColor + server.getTickUsage() + "%");
sender.sendMessage(TextFormat.GOLD + "Network upload: " + TextFormat.GREEN + NukkitMath.round((server.getNetwork().getUpload() / 1024 * 1000), 2) + " kB/s");
sender.sendMessage(TextFormat.GOLD + "Network download: " + TextFormat.GREEN + NukkitMath.round((server.getNetwork().getDownload() / 1024 * 1000), 2) + " kB/s");
sender.sendMessage(TextFormat.GOLD + "Thread count: " + TextFormat.GREEN + Thread.getAllStackTraces().size());
Runtime runtime = Runtime.getRuntime();
double totalMB = NukkitMath.round(((double) runtime.totalMemory()) / 1024 / 1024, 2);
double usedMB = NukkitMath.round((double) (runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024, 2);
double maxMB = NukkitMath.round(((double) runtime.maxMemory()) / 1024 / 1024, 2);
double usage = usedMB / maxMB * 100;
TextFormat usageColor = TextFormat.GREEN;
if (usage > 85) {
usageColor = TextFormat.GOLD;
}
sender.sendMessage(TextFormat.GOLD + "Used memory: " + usageColor + usedMB + " MB. (" + NukkitMath.round(usage, 2) + "%)");
sender.sendMessage(TextFormat.GOLD + "Total memory: " + TextFormat.RED + totalMB + " MB.");
sender.sendMessage(TextFormat.GOLD + "Maximum VM memory: " + TextFormat.RED + maxMB + " MB.");
sender.sendMessage(TextFormat.GOLD + "Available processors: " + TextFormat.GREEN + runtime.availableProcessors());
TextFormat playerColor = TextFormat.GREEN;
if (((float) server.getOnlinePlayers().size() / (float) server.getMaxPlayers()) > 0.85) {
playerColor = TextFormat.GOLD;
}
sender.sendMessage(TextFormat.GOLD + "Players: " + playerColor + server.getOnlinePlayers().size() + TextFormat.GREEN + " online, " +
TextFormat.RED + server.getMaxPlayers() + TextFormat.GREEN + " max. ");
for (Level level : server.getLevels().values()) {
sender.sendMessage(
TextFormat.GOLD + "World \"" + level.getFolderName() + "\"" + (!Objects.equals(level.getFolderName(), level.getName()) ? " (" + level.getName() + ")" : "") + ": " +
TextFormat.RED + level.getChunks().size() + TextFormat.GREEN + " chunks, " +
TextFormat.RED + level.getEntities().length + TextFormat.GREEN + " entities, " +
TextFormat.RED + level.getBlockEntities().size() + TextFormat.GREEN + " blockEntities." +
" Time " + ((level.getTickRate() > 1 || level.getTickRateTime() > 40) ? TextFormat.RED : TextFormat.YELLOW) + NukkitMath.round(level.getTickRateTime(), 2) + "ms" +
(level.getTickRate() > 1 ? " (tick rate " + level.getTickRate() + ")" : "")
);
}
return true;
}
示例14: execute
import cn.nukkit.command.CommandSender; //導入方法依賴的package包/類
@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;
}
}
示例15: execute
import cn.nukkit.command.CommandSender; //導入方法依賴的package包/類
@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;
}