當前位置: 首頁>>代碼示例>>Java>>正文


Java CommandSender.sendMessage方法代碼示例

本文整理匯總了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;
}
 
開發者ID:zzz1999,項目名稱:ChestLocker,代碼行數:27,代碼來源:ChestShare.java

示例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;
}
 
開發者ID:CoreXDevelopment,項目名稱:CoreX,代碼行數:18,代碼來源:SeedCommand.java

示例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;
}
 
開發者ID:Rsplwe,項目名稱:Nukkit-Java9,代碼行數:24,代碼來源:ListCommand.java

示例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;
}
 
開發者ID:Rsplwe,項目名稱:Nukkit-Java9,代碼行數:34,代碼來源:DifficultyCommand.java

示例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;
}
 
開發者ID:JupiterDevelopmentTeam,項目名稱:Jupiter,代碼行數:37,代碼來源:KickCommand.java

示例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;
}
 
開發者ID:FrontierDevs,項目名稱:Jenisys3,代碼行數:36,代碼來源:SayCommand.java

示例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;
}
 
開發者ID:Him188,項目名稱:Money,代碼行數:32,代碼來源:SeeBankCommand.java

示例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;
}
 
開發者ID:FrontierDevs,項目名稱:Jenisys3,代碼行數:40,代碼來源:EnchantCommand.java

示例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;
}
 
開發者ID:JupiterDevelopmentTeam,項目名稱:Jupiter,代碼行數:33,代碼來源:MeCommand.java

示例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;
}
 
開發者ID:JupiterDevelopmentTeam,項目名稱:Jupiter,代碼行數:10,代碼來源:WhitelistCommand.java

示例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;
}
 
開發者ID:organization,項目名稱:ShowServerStatus,代碼行數:13,代碼來源:ServerInfoCommand.java

示例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;
}
 
開發者ID:Him188,項目名稱:Money,代碼行數:33,代碼來源:SeeMoney1Command.java

示例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;
}
 
開發者ID:FrontierDevs,項目名稱:Jenisys3,代碼行數:81,代碼來源:StatusCommand.java

示例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;
    }

}
 
開發者ID:Rsplwe,項目名稱:Nukkit-Java9,代碼行數:59,代碼來源:WeatherCommand.java

示例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;
}
 
開發者ID:FrontierDevs,項目名稱:Jenisys3,代碼行數:71,代碼來源:TitleCommand.java


注:本文中的cn.nukkit.command.CommandSender.sendMessage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。