Search in sources :

Example 1 with PlayerNotFoundException

use of xyz.derkades.ublisk.utils.exception.PlayerNotFoundException in project Ublisk by Derkades.

the class SongEnd method musicStopped.

@EventHandler
public void musicStopped(SongEndEvent event) {
    try {
        SongPlayer songPlayer = event.getSongPlayer();
        for (String playername : songPlayer.getPlayerList()) {
            UPlayer player = new UPlayer(playername);
            if (player.getSetting(Setting.PLAY_MUSIC)) {
                Town town = player.getTown();
                if (town != null) {
                    town.playThemeToPlayer(player);
                }
            }
        }
        songPlayer.destroy();
    } catch (PlayerNotFoundException e) {
        Logger.log(LogLevel.WARNING, "Music", "Tried to play new song but player has already logged out");
    }
}
Also used : UPlayer(xyz.derkades.ublisk.utils.UPlayer) SongPlayer(xyz.derkades.ublisk.ext.com.xxmicloxx.noteblockapi.SongPlayer) Town(xyz.derkades.ublisk.Town) PlayerNotFoundException(xyz.derkades.ublisk.utils.exception.PlayerNotFoundException) EventHandler(org.bukkit.event.EventHandler)

Example 2 with PlayerNotFoundException

use of xyz.derkades.ublisk.utils.exception.PlayerNotFoundException in project Ublisk by Derkades.

the class Voting method onVote.

@EventHandler(priority = EventPriority.HIGH)
public void onVote(VotifierEvent event) {
    Vote vote = event.getVote();
    UPlayer player;
    try {
        player = new UPlayer(vote.getUsername());
    } catch (PlayerNotFoundException e) {
        // TODO Deal with player not online exception
        e.printStackTrace();
        return;
    }
    int points = Random.getRandomInteger(1, 3);
    player.setVotingPoints(player.getVotingPoints() + points);
    Ublisk.broadcastPrefixedMessage(player.getName() + " has voted and got " + points + " points! Vote at " + Var.VOTE_URL);
    Logger.log(LogLevel.INFO, "Vote", player.getName() + " has voted at " + vote.getServiceName() + " (" + vote.getAddress() + ") and got " + points + " points.");
}
Also used : Vote(com.vexsoftware.votifier.model.Vote) UPlayer(xyz.derkades.ublisk.utils.UPlayer) PlayerNotFoundException(xyz.derkades.ublisk.utils.exception.PlayerNotFoundException) EventHandler(org.bukkit.event.EventHandler)

Example 3 with PlayerNotFoundException

use of xyz.derkades.ublisk.utils.exception.PlayerNotFoundException in project Ublisk by Derkades.

the class MsgCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player)) {
        sender.sendMessage(Message.NOT_A_PLAYER.toString());
        return true;
    }
    UPlayer player = new UPlayer(sender);
    // If player is muted don't send private message
    if (Chat.IS_MUTED.get(player.getUniqueId())) {
        player.sendMessage(Message.CANT_PM_MUTED);
        return true;
    }
    if (args.length >= 2) {
        UPlayer target;
        try {
            target = new UPlayer(args[0]);
        } catch (PlayerNotFoundException e1) {
            player.sendMessage(Message.PLAYER_NOT_FOUND);
            return true;
        }
        List<String> list = new ArrayList<String>();
        for (int x = 1; x < args.length; x++) {
            list.add(args[x]);
        }
        String msg = String.join(" ", list);
        // Play a sound if the target player has enabled sounds.
        if (target.getSetting(Setting.PM_SOUND)) {
            target.playSound(Sound.ENTITY_ITEM_PICKUP);
        }
        target.setLastSender(player);
        target.sendPrivateMessage(player, msg);
        return true;
    } else {
        player.sendMessage(Message.WRONG_USAGE);
        return true;
    }
}
Also used : UPlayer(xyz.derkades.ublisk.utils.UPlayer) Player(org.bukkit.entity.Player) UPlayer(xyz.derkades.ublisk.utils.UPlayer) ArrayList(java.util.ArrayList) PlayerNotFoundException(xyz.derkades.ublisk.utils.exception.PlayerNotFoundException)

Example 4 with PlayerNotFoundException

use of xyz.derkades.ublisk.utils.exception.PlayerNotFoundException in project Ublisk by Derkades.

the class MuteCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player)) {
        sender.sendMessage(Message.NOT_A_PLAYER.toString());
        return true;
    }
    UPlayer player = new UPlayer(sender);
    if (player.hasPermission(Permission.COMMAND_MUTE)) {
        player.sendMessage(Message.NO_PERMISSION);
        return true;
    }
    if (args.length == 1) {
        UPlayer target;
        try {
            target = new UPlayer(args[0]);
        } catch (PlayerNotFoundException e) {
            player.sendMessage(Message.PLAYER_NOT_FOUND);
            return true;
        }
        UUID uuid = target.getUniqueId();
        String targetName = target.getName();
        String playerName = player.getName();
        if (Chat.IS_MUTED.get(uuid)) {
            player.sendPrefixedMessage("Chat", targetName + " has been unmuted.");
            target.sendPrefixedMessage("Chat", "You have been unmuted by " + playerName);
            Chat.IS_MUTED.put(uuid, false);
            return true;
        } else {
            player.sendPrefixedMessage("Chat", targetName + " has been muted.");
            target.sendPrefixedMessage("Chat", "You have been muted by " + playerName);
            Chat.IS_MUTED.put(uuid, true);
            return true;
        }
    } else if (args.length == 2 && args[0].equalsIgnoreCase("soft")) {
        UPlayer target;
        try {
            target = new UPlayer(args[1]);
        } catch (PlayerNotFoundException e) {
            player.sendMessage(Message.PLAYER_NOT_FOUND);
            return true;
        }
        UUID uuid = target.getUniqueId();
        String targetName = target.getName();
        String playerName = player.getName();
        if (Chat.IS_SOFT_MUTED.get(uuid)) {
            player.sendPrefixedMessage("Chat", targetName + " has been un-soft-muted.");
            target.sendPrefixedMessage("Chat", "You have been un-soft-muted by " + playerName);
            Chat.IS_MUTED.put(uuid, false);
            return true;
        } else {
            player.sendPrefixedMessage("Chat", targetName + " has been soft-muted.");
            target.sendPrefixedMessage("Chat", "You have been soft-muted by " + playerName);
            Chat.IS_MUTED.put(uuid, true);
            return true;
        }
    } else {
        player.sendMessage(Message.WRONG_USAGE);
        return true;
    }
}
Also used : UPlayer(xyz.derkades.ublisk.utils.UPlayer) Player(org.bukkit.entity.Player) UPlayer(xyz.derkades.ublisk.utils.UPlayer) PlayerNotFoundException(xyz.derkades.ublisk.utils.exception.PlayerNotFoundException) UUID(java.util.UUID)

Example 5 with PlayerNotFoundException

use of xyz.derkades.ublisk.utils.exception.PlayerNotFoundException in project Ublisk by Derkades.

the class GuildCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player)) {
        sender.sendMessage(Message.NOT_A_PLAYER.toString());
    }
    UPlayer player = new UPlayer(sender);
    if (args.length == 1) {
        if (args[0].equalsIgnoreCase("accept")) {
            if (Guild.GUILD_INVITES.containsKey(player.getName())) {
                // Player has got an invite
                GuildInvite invite = Guild.GUILD_INVITES.get(player.getName());
                Guild guild = invite.getGuild();
                player.setGuild(guild);
                player.sendPrefixedMessage("Guilds", "You joined " + guild.getName() + "!");
                for (UPlayer guildMember : guild.getMembers()) {
                    if (guildMember.isOnline() && guildMember.getUniqueId() != player.getUniqueId()) {
                        guildMember.sendMessage(ChatColor.DARK_AQUA + "" + ChatColor.BOLD + player.getName() + " has joined your guild!");
                    }
                }
                Guild.GUILD_INVITES.remove(player.getName());
                return true;
            } else {
                // Player does not have an invite
                player.sendPrefixedMessage("Guilds", "You don't have any pending invites.");
                return true;
            }
        } else if (args[0].equalsIgnoreCase("leave")) {
            if (player.getGuild() == null) {
                player.sendPrefixedMessage("Guilds", "You are not in a guild");
                return true;
            }
            Guild guild = player.getGuild();
            if (guild.getMembers().size() <= 1) {
                // If player is last person in guild (player can be owner if they're the only one left)
                player.sendPrefixedMessage("Guilds", "You left " + guild.getName() + ". Because you were the last player in the guild, your guild has been queued for deletion. If you regret leaving this guild, ask a staff member to add you back.");
                player.leaveGuild();
                return true;
            } else if (guild.getOwner().getUniqueId().equals(player.getUniqueId())) {
                // If player is owner - don't allow them to leave
                player.sendMessage("You are owner of this guild. You can only leave this guild if you transfer ownership to another guild member.");
                return true;
            } else {
                // Otherwise it's just a normal player - allow leaving
                player.sendPrefixedMessage("Guilds", "You have left " + guild.getName());
                player.leaveGuild();
                return true;
            }
        } else if (args[0].equalsIgnoreCase("list")) {
            player.sendMessage(ChatColor.AQUA + "----------={" + ChatColor.DARK_AQUA + " Guilds " + ChatColor.AQUA + "}=----------");
            for (Guild guild : Guild.getGuildsList(10)) {
                BaseComponent[] members = new BaseComponent[] {};
                for (UPlayer member : guild.getMembers()) {
                    BaseComponent[] components = member.getDisplayName(ChatColor.BLUE, false);
                    members = ArrayUtils.addAll(members, components);
                }
                player.sendMessage(ArrayUtils.addAll(TextComponent.fromLegacyText(ChatColor.YELLOW + guild.getName() + ChatColor.DARK_GRAY + " | " + ChatColor.RED + guild.getPoints() + " Points" + ChatColor.DARK_GRAY + " | "), members));
            }
            return true;
        } else if (args[0].equalsIgnoreCase("help")) {
            return false;
        } else if (args[0].equalsIgnoreCase("info")) {
            Guild guild = player.getGuild();
            if (guild == null) {
                player.sendPrefixedMessage("Guilds", "You are not in a guild. Use /guild info [guild] to check information about another guild.");
                return true;
            }
            player.executeCommand("guild info " + guild.getName());
            return true;
        } else {
            return false;
        }
    } else if (args.length == 2) {
        if (args[0].equals("create")) {
            Ublisk.runAsync(() -> {
                if (args[1].length() > 20) {
                    Ublisk.runSync(() -> player.sendPrefixedMessage("Guilds", "This guild name is too long."));
                    return;
                }
                if (!StringUtils.validateString(args[1])) {
                    Ublisk.runSync(() -> player.sendPrefixedMessage("Guilds", "Guild names can only contain alphanumerical characters and underscores (a-z, A-Z, 0-9, _)"));
                    return;
                }
                if (player.getGuild() != null) {
                    Ublisk.runSync(() -> player.sendPrefixedMessage("Guilds", "You are already in a guild. Please leave your current guild before creating a new one."));
                    return;
                }
                Guild guild = new Guild(args[1]);
                if (guild.exists()) {
                    Ublisk.runSync(() -> player.sendPrefixedMessage("Guilds", "A guild with this name already exists."));
                    return;
                }
                guild.create(player);
                Ublisk.runSync(() -> player.sendPrefixedMessage("Guilds", "The guild has been created."));
            });
            return true;
        } else if (args[0].equals("info")) {
            Guild guild = new Guild(args[1]);
            if (!guild.exists()) {
                player.sendPrefixedMessage("Guilds", "This guild does not exist.");
                return true;
            }
            player.sendMessage(new ComponentBuilder("Name: ").color(ChatColor.DARK_AQUA).create(), new ComponentBuilder(guild.getName()).color(ChatColor.AQUA).create());
            player.sendMessage(new ComponentBuilder("Points: ").color(ChatColor.DARK_AQUA).create(), new ComponentBuilder(guild.getPoints() + "").color(ChatColor.AQUA).create());
            player.sendMessage(new ComponentBuilder("Description: ").color(ChatColor.DARK_AQUA).create(), new ComponentBuilder(guild.getDescription()).color(ChatColor.AQUA).create());
            player.sendMessage(new ComponentBuilder("Members: ").color(ChatColor.DARK_AQUA).create());
            for (UPlayer member : guild.getMembers()) {
                player.sendMessage(new ComponentBuilder("- ").color(ChatColor.DARK_GRAY).bold(true).create(), member.getDisplayName(ChatColor.AQUA, false));
            }
            return true;
        } else if (args[0].equalsIgnoreCase("invite")) {
            if (player.getGuild() == null) {
                player.sendPrefixedMessage("Guilds", "You are not in a guild.");
                return true;
            }
            UPlayer target = null;
            try {
                target = new UPlayer(args[1]);
            } catch (PlayerNotFoundException e) {
                player.sendMessage(Message.PLAYER_NOT_FOUND);
                return true;
            }
            Guild guild = player.getGuild();
            guild.invitePlayer(player, target);
            player.sendPrefixedMessage("Guilds", "You have invited " + target.getName() + " to your guild.");
            return true;
        } else if (args[0].equalsIgnoreCase("rename")) {
            if (player.getGuild() == null) {
                player.sendPrefixedMessage("Guilds", "You are not in a guild.");
                return true;
            }
            if (!StringUtils.validateString(args[1])) {
                player.sendPrefixedMessage("Guilds", "Guild names can only contain alphanumerical characters and underscores (a-z, A-Z, 0-9, _).");
                return true;
            }
            Guild guild = new Guild(args[1]);
            if (guild.exists()) {
                player.sendPrefixedMessage("Guilds", "A guild with this name already exists.");
                return true;
            }
            player.sendPrefixedMessage("Guilds", "Your guild has been renamed to " + args[1]);
            Ublisk.runAsync(() -> {
                guild.rename(args[1]);
            });
            return true;
        } else if (args[0].equalsIgnoreCase("owner")) {
            if (player.getGuild() == null) {
                player.sendPrefixedMessage("Guilds", "You are not in a guild.");
                return true;
            }
            UPlayer target;
            try {
                target = new UPlayer(args[1]);
            } catch (PlayerNotFoundException e) {
                player.sendPrefixedMessage("Guilds", "This player could not be found.");
                return true;
            }
            Guild guild = player.getGuild();
            if (!player.getGuild().getName().equals(target.getGuild().getName())) {
                player.sendPrefixedMessage("Guilds", "You cannot transfer ownership to a player who is not in your guild.");
                return true;
            }
            player.sendPrefixedMessage("Guilds", target.getName() + " is now the owner of " + guild.getName());
            Ublisk.runAsync(() -> {
                guild.setOwner(target);
            });
            return true;
        } else {
            return false;
        }
    } else if (args[0].equalsIgnoreCase("description") || args[0].equalsIgnoreCase("desc")) {
        String description = String.join(" ", ListUtils.removeFirstStringFromArray(args));
        if (description.length() > 100) {
            player.sendPrefixedMessage("Guilds", "This description is too long.");
            return true;
        }
        if (description.length() < 6) {
            player.sendPrefixedMessage("Guilds", "This description is too short.");
            return true;
        }
        Guild guild = player.getGuild();
        if (guild == null) {
            player.sendPrefixedMessage("Guilds", "You are not in a guild.");
            return true;
        }
        player.sendPrefixedMessage("Guilds", "You have changed your guild's description to " + StringUtils.addDotIfNecessary(description));
        Ublisk.runAsync(() -> {
            guild.setDescription(description);
        });
        return true;
    } else {
        return false;
    }
}
Also used : UPlayer(xyz.derkades.ublisk.utils.UPlayer) Player(org.bukkit.entity.Player) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) UPlayer(xyz.derkades.ublisk.utils.UPlayer) GuildInvite(xyz.derkades.ublisk.utils.Guild.GuildInvite) PlayerNotFoundException(xyz.derkades.ublisk.utils.exception.PlayerNotFoundException) Guild(xyz.derkades.ublisk.utils.Guild) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Aggregations

UPlayer (xyz.derkades.ublisk.utils.UPlayer)7 PlayerNotFoundException (xyz.derkades.ublisk.utils.exception.PlayerNotFoundException)7 Player (org.bukkit.entity.Player)4 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)2 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)2 EventHandler (org.bukkit.event.EventHandler)2 Vote (com.vexsoftware.votifier.model.Vote)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 ClickEvent (net.md_5.bungee.api.chat.ClickEvent)1 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)1 DataFile (xyz.derkades.ublisk.DataFile)1 Town (xyz.derkades.ublisk.Town)1 SongPlayer (xyz.derkades.ublisk.ext.com.xxmicloxx.noteblockapi.SongPlayer)1 Guild (xyz.derkades.ublisk.utils.Guild)1 GuildInvite (xyz.derkades.ublisk.utils.Guild.GuildInvite)1 Item (xyz.derkades.ublisk.utils.inventory.Item)1