Java Code Examples for cn.nukkit.command.CommandSender#getName()

The following examples show how to use cn.nukkit.command.CommandSender#getName() . 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: 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 2
Source File: SayCommand.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 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;
}
 
Example 3
Source File: MeCommand.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;
    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;
}
 
Example 4
Source File: TellCommand.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 < 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 5
Source File: SayCommand.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 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",
            senderString, TextFormat.LIGHT_PURPLE + msg));
    return true;
}
 
Example 6
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 7
Source File: NukkitSenderFactory.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
protected String getName(CommandSender sender) {
    if (sender instanceof Player) {
        return sender.getName();
    }
    return Sender.CONSOLE_NAME;
}
 
Example 8
Source File: TellCommand.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 < 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 9
Source File: SayCommand.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 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;
}
 
Example 10
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", new String[]{name, TextFormat.WHITE + msg}));

    return true;
}