cn.nukkit.command.CommandSender Java Examples

The following examples show how to use cn.nukkit.command.CommandSender. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SaveCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.save.start"));

    for (Player player : sender.getServer().getOnlinePlayers().values()) {
        player.save();
    }

    for (Level level : sender.getServer().getLevels().values()) {
        level.save(true);
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.save.success"));
    return true;
}
 
Example #2
Source File: DefaultGamemodeCommand.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@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", new String[]{this.usageMessage}));
        return false;
    }
    int gameMode = Server.getGamemodeFromString(args[0]);
    if (gameMode != -1) {
        sender.getServer().setPropertyInt("gamemode", gameMode);
        sender.sendMessage(new TranslationContainer("commands.defaultgamemode.success", new String[]{Server.getGamemodeString(gameMode)}));
    } else {
        sender.sendMessage("Unknown game mode"); //
    }
    return true;
}
 
Example #3
Source File: SetLangCommand.java    From EconomyAPI with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
	if(!this.plugin.isEnabled()) return false;
	if(!sender.hasPermission("economyapi.command.setlang")){
		sender.sendMessage(TextFormat.RED + "You don't have permission to use this command.");
		return false;
	}
	
	if(args.length < 1){
		sender.sendMessage(TextFormat.RED + "Usage: " + this.getUsage());
		return true;
	}
	String lang = args[0];
	
	// TODO
	return true;
}
 
Example #4
Source File: SaveCommand.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.save.start"));

    for (Player player : sender.getServer().getOnlinePlayers().values()) {
        player.save();
    }

    for (Level level : sender.getServer().getLevels().values()) {
        level.save(true);
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.save.success"));
    return true;
}
 
Example #5
Source File: RealNameCommand.java    From EssentialsNK with GNU General Public License v3.0 6 votes vote down vote up
public boolean execute(CommandSender sender, String label, String[] args) {
    if (!this.testPermission(sender)) {
        return false;
    }
    if (args.length != 1) {
        this.sendUsage(sender);
        return false;
    }
    Player player = api.getServer().getPlayer(args[0]);
    if (player == null) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.generic.player.notfound", args[0]));
        return false;
    }
    sender.sendMessage(Language.translate("commands.realname.success", player.getDisplayName(), player.getName()));
    return true;
}
 
Example #6
Source File: MuteCommand.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {

    if (!this.testPermission(sender)) {
        return true;
    }

    if(sender instanceof ConsoleCommandSender){
    	sender.sendMessage(TextFormat.RED + "コンソールはミュートできません。");
    	return true;
    }

    Player p = (Player)sender;

    if(p.mute){
    	p.setMute(false);
    	p.sendImportantMessage(TextFormat.GREEN + "ミュートを解除しました。");
    	return true;
    }else{
    	p.setMute(true);
    	p.sendImportantMessage(TextFormat.RED + "ミュートを有効にしました。");
    	return true;
    }
}
 
Example #7
Source File: BackCommand.java    From EssentialsNK with GNU General Public License v3.0 6 votes vote down vote up
public boolean execute(CommandSender sender, String label, String[] args) {
    if (!this.testPermission(sender)) {
        return false;
    }
    if (!this.testIngame(sender)) {
        return false;
    }
    if (args.length != 0) {
        this.sendUsage(sender);
        return false;
    }
    Player player = (Player) sender;
    Location pos = api.getLastLocation(player);
    if (pos == null) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.back.notavalible"));
        return false;
    }
    player.teleport(pos);
    sender.sendMessage(Language.translate("commands.generic.teleporting"));
    return true;
}
 
Example #8
Source File: PardonIpCommand.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@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;
    }

    String value = args[0];

    if (Pattern.matches("^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$", value)) {
        sender.getServer().getIPBans().remove(value);

        Command.broadcastCommandMessage(sender, new TranslationContainer("commands.unbanip.success", value));
    } else {

        sender.sendMessage(new TranslationContainer("commands.unbanip.invalid"));
    }

    return true;
}
 
Example #9
Source File: DefaultGamemodeCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@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", new String[]{this.usageMessage}));
        return false;
    }
    int gameMode = Server.getGamemodeFromString(args[0]);
    if (gameMode != -1) {
        sender.getServer().setPropertyInt("gamemode", gameMode);
        sender.sendMessage(new TranslationContainer("commands.defaultgamemode.success", new String[]{Server.getGamemodeString(gameMode)}));
    } else {
        sender.sendMessage("Unknown game mode"); //
    }
    return true;
}
 
Example #10
Source File: PlayerChatEvent.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public PlayerChatEvent(Player player, String message, String format, Set<CommandSender> recipients) {
    this.player = player;
    this.message = message;

    this.format = format;

    if (recipients == null) {
        for (Permissible permissible : Server.getInstance().getPluginManager().getPermissionSubscriptions(Server.BROADCAST_CHANNEL_USERS)) {
            if (permissible instanceof CommandSender) {
                this.recipients.add((CommandSender) permissible);
            }
        }

    } else {
        this.recipients = recipients;
    }
}
 
Example #11
Source File: DefaultGamemodeCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@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", new String[]{this.usageMessage}));
        return false;
    }
    int gameMode = Server.getGamemodeFromString(args[0]);
    if (gameMode != -1) {
        sender.getServer().setPropertyInt("gamemode", gameMode);
        sender.sendMessage(new TranslationContainer("commands.defaultgamemode.success", new String[]{Server.getGamemodeString(gameMode)}));
    } else {
        sender.sendMessage("Unknown game mode"); //
    }
    return true;
}
 
Example #12
Source File: Server.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public int broadcastImportantMessage(String message, String permissions) {
    Set<CommandSender> recipients = new HashSet<>();

    for (String permission : permissions.split(";")) {
        for (Permissible permissible : this.pluginManager.getPermissionSubscriptions(permission)) {
            if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
                recipients.add((CommandSender) permissible);
            }
        }
    }

    for (CommandSender recipient : recipients) {
        recipient.sendImportantMessage(message);
    }

    return recipients.size();
}
 
Example #13
Source File: NukkitPlatformListener.java    From LuckPerms with MIT License 6 votes vote down vote up
private void handleCommand(CommandSender sender, String s, Cancellable event) {
    if (s.isEmpty()) {
        return;
    }

    if (this.plugin.getConfiguration().get(ConfigKeys.OPS_ENABLED)) {
        return;
    }

    if (s.charAt(0) == '/') {
        s = s.substring(1);
    }

    if (s.contains(":")) {
        s = s.substring(s.indexOf(':') + 1);
    }

    if (s.equals("op") || s.startsWith("op ") || s.equals("deop") || s.startsWith("deop ")) {
        event.setCancelled(true);
        sender.sendMessage(Message.OP_DISABLED.asString(this.plugin.getLocaleManager()));
    }
}
 
Example #14
Source File: SeedCommand.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example #15
Source File: TopCommand.java    From EssentialsNK with GNU General Public License v3.0 6 votes vote down vote up
public boolean execute(CommandSender sender, String label, String[] args) {
    if (!this.testPermission(sender)) {
        return false;
    }
    if (!this.testIngame(sender)) {
        return false;
    }
    if (args.length != 0) {
        this.sendUsage(sender);
        return false;
    }
    Player player = (Player) sender;
    sender.sendMessage(Language.translate("commands.generic.teleporting"));
    player.teleport(api.getHighestStandablePositionAt(player));
    return true;
}
 
Example #16
Source File: SetLangCommand.java    From EconomyAPI with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
	if(!this.plugin.isEnabled()) return false;
	if(!sender.hasPermission("economyapi.command.setlang")){
		sender.sendMessage(TextFormat.RED + "You don't have permission to use this command.");
		return false;
	}
	
	if(args.length < 1){
		sender.sendMessage(TextFormat.RED + "Usage: " + this.getUsage());
		return true;
	}
	String lang = args[0];
	
	// TODO
	return true;
}
 
Example #17
Source File: KickCommand.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example #18
Source File: NukkitCommandSender.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public NukkitCommandSender(NukkitWorldEdit plugin, CommandSender sender) {
    checkNotNull(plugin);
    checkNotNull(sender);
    checkArgument(!(sender instanceof Player), "Cannot wrap a player");

    this.plugin = plugin;
    this.sender = sender;
}
 
Example #19
Source File: PingCommand.java    From EssentialsNK with GNU General Public License v3.0 5 votes vote down vote up
public boolean execute(CommandSender sender, String label, String[] args) {
    if (!this.testPermission(sender)) {
        return false;
    }
    sender.sendMessage("Pong!");
    return true;
}
 
Example #20
Source File: SaveOffCommand.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    sender.getServer().setAutoSave(false);
    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.save.disabled"));
    return true;
}
 
Example #21
Source File: StopCommand.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    Command.broadcastCommandMessage(sender, new TranslationContainer("commands.stop.start"));

    sender.getServer().shutdown();

    return true;
}
 
Example #22
Source File: NukkitWorldEdit.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public Actor wrapCommandSender(CommandSender sender) {
    if (sender instanceof Player) {
        return wrapPlayer((Player) sender);
    }

    return new NukkitCommandSender(this, sender);
}
 
Example #23
Source File: MakePluginCommand.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {

    if (!this.testPermission(sender)) {
        return true;
    }

    try{if(args[0] != null){}}
    catch(ArrayIndexOutOfBoundsException e){
        sender.sendMessage(TextFormat.RED + "ファイル名を入力してください。(またはlist)");
        return false;
    }

    if(args[0].equals("list")){
        File dir = new File(sender.getServer().getDataPath() + "makeOrder/");
        File[] files = dir.listFiles();
        sender.sendMessage(TextFormat.AQUA + "オーダーフォルダ一覧の表示:");
        for (int i = 0; i < files.length; i++) {
            File file = files[i];
            sender.sendMessage((i + 1) + ": " + TextFormat.GREEN +  file.getName());
        }
        return true;
    }

    sender.sendMessage(TextFormat.AQUA + "プラグインを作成しています...");
    if(new PluginMaker().Make(args[0]))
        sender.sendMessage(TextFormat.GREEN + "成功");
    else
        sender.sendMessage(TextFormat.RED + "失敗");

    return true;
}
 
Example #24
Source File: DepthCommand.java    From EssentialsNK with GNU General Public License v3.0 5 votes vote down vote up
public boolean execute(CommandSender sender, String label, String[] args) {
    if (!this.testPermission(sender)) {
        return false;
    }
    if (!this.testIngame(sender)) {
        return false;
    }
    if (args.length != 0) {
        this.sendUsage(sender);
        return false;
    }
    sender.sendMessage(Language.translate("commands.depth.success", String.valueOf(((Player) sender).getFloorY() - 63)));
    return true;
}
 
Example #25
Source File: MeCommand.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@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", name, TextFormat.WHITE + msg));

    return true;
}
 
Example #26
Source File: KickCommand.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example #27
Source File: TellCommand.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@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;
    }

    String name = args[0].toLowerCase();

    Player player = sender.getServer().getPlayer(name);
    if (player == null) {
        sender.sendMessage(new TranslationContainer("commands.generic.player.notFound"));
        return true;
    }

    if (Objects.equals(player, sender)) {
        sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.message.sameTarget"));
        return true;
    }

    String msg = "";
    for (int i = 1; i < args.length; i++) {
        msg += args[i] + " ";
    }
    if (msg.length() > 0) {
        msg = msg.substring(0, msg.length() - 1);
    }

    String displayName = (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName());

    sender.sendMessage("[" + sender.getName() + " -> " + player.getDisplayName() + "] " + msg);
    player.sendMessage("[" + displayName + " -> " + player.getName() + "] " + msg);

    return true;
}
 
Example #28
Source File: BanIpCommand.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
private void processIPBan(String ip, CommandSender sender, String reason) {
    sender.getServer().getIPBans().addBan(ip, reason, null, sender.getName());

    for (Player player : new ArrayList<>(sender.getServer().getOnlinePlayers().values())) {
        if (player.getAddress().equals(ip)) {
            player.kick(PlayerKickEvent.Reason.IP_BANNED, !reason.isEmpty() ? reason : "IP banned");
        }
    }

    sender.getServer().getNetwork().blockAddress(ip, -1);
}
 
Example #29
Source File: NukkitSenderFactory.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
protected UUID getUniqueId(CommandSender sender) {
    if (sender instanceof Player) {
        return ((Player) sender).getUniqueId();
    }
    return Sender.CONSOLE_UUID;
}
 
Example #30
Source File: CompassCommand.java    From EssentialsNK with GNU General Public License v3.0 5 votes vote down vote up
public boolean execute(CommandSender sender, String label, String[] args) {
    if (!this.testPermission(sender)) {
        return false;
    }
    if (!this.testIngame(sender)) {
        return false;
    }
    if (args.length != 0) {
        this.sendUsage(sender);
        return false;
    }
    String direction;
    switch (((Player) sender).getDirection()) {
        case SOUTH:
            direction = "south";
            break;
        case WEST:
            direction = "west";
            break;
        case NORTH:
            direction = "north";
            break;
        case EAST:
            direction = "east";
            break;
        default:
            direction = "error";
    }
    sender.sendMessage(Language.translate("commands.compass.success", Language.translate("commands.compass." + direction)));
    return true;
}