Search in sources :

Example 1 with FriendsMenu

use of xyz.derkades.ublisk.iconmenus.FriendsMenu in project Ublisk by Derkades.

the class FriendsCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (sender instanceof Player) {
        UPlayer player = new UPlayer(sender);
        if (args.length == 0) {
            new FriendsMenu(player).open();
        } else if (args.length == 2) {
            if (args[0].equals("add")) {
                OfflinePlayer target = Ublisk.getOfflinePlayer(args[1]);
                if (target == null) {
                    player.sendMessage(Message.PLAYER_NOT_FOUND);
                    return true;
                }
                if (player.isFriend(target)) {
                    player.sendPrefixedMessage("Friends", ChatColor.RED + target.getName() + " is already in your friends list.");
                    return true;
                }
                player.addFriend(target);
                player.sendPrefixedMessage("Friends", target.getName() + " has been added to your friends list");
            } else if (args[0].equals("remove") || args[0].equals("delete")) {
                OfflinePlayer target = Ublisk.getOfflinePlayer(args[1]);
                if (target == null) {
                    player.sendMessage(Message.PLAYER_NOT_FOUND);
                    return true;
                }
                if (!player.isFriend(target)) {
                    player.sendMessage(Message.FRIEND_NOT_EXIST);
                    return true;
                }
                player.removeFriend(target);
                player.sendPrefixedMessage("Friends", target.getName() + " has been removed from your friends list");
            } else {
                player.sendMessage(Message.WRONG_USAGE);
            }
        } else {
            player.sendMessage(Message.WRONG_USAGE);
        }
    } else {
        sender.sendMessage(Message.NOT_A_PLAYER.toString());
    }
    return true;
}
Also used : UPlayer(xyz.derkades.ublisk.utils.UPlayer) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) UPlayer(xyz.derkades.ublisk.utils.UPlayer) FriendsMenu(xyz.derkades.ublisk.iconmenus.FriendsMenu) OfflinePlayer(org.bukkit.OfflinePlayer)

Aggregations

OfflinePlayer (org.bukkit.OfflinePlayer)1 Player (org.bukkit.entity.Player)1 FriendsMenu (xyz.derkades.ublisk.iconmenus.FriendsMenu)1 UPlayer (xyz.derkades.ublisk.utils.UPlayer)1