Search in sources :

Example 6 with PlayerNotFoundException

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

the class StatsCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    UPlayer player = new UPlayer(sender);
    if (args.length == 1) {
        UPlayer target = null;
        try {
            target = new UPlayer(args[1]);
        } catch (PlayerNotFoundException e) {
            player.sendMessage(Message.PLAYER_NOT_FOUND);
            return true;
        }
        BaseComponent[] hoverText = new ComponentBuilder("yes click me pls").create();
        BaseComponent[] text = new ComponentBuilder("Click here to open " + target.getName() + "'s statistics page in your browser.").color(ChatColor.AQUA).bold(true).event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)).event(new ClickEvent(ClickEvent.Action.OPEN_URL, target.getStatsURL())).create();
        player.sendMessage(text);
        return true;
    } else if (args.length == 0) {
        BaseComponent[] hoverText = new ComponentBuilder("yes click me pls").create();
        BaseComponent[] text = new ComponentBuilder("Click here to open your statistics page in your browser.").color(ChatColor.AQUA).bold(true).event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)).event(new ClickEvent(ClickEvent.Action.OPEN_URL, player.getStatsURL())).create();
        player.sendMessage(text);
        return true;
    } else {
        return false;
    }
}
Also used : HoverEvent(net.md_5.bungee.api.chat.HoverEvent) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) UPlayer(xyz.derkades.ublisk.utils.UPlayer) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) PlayerNotFoundException(xyz.derkades.ublisk.utils.exception.PlayerNotFoundException) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 7 with PlayerNotFoundException

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

the class Debug method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (sender instanceof Player) {
        UPlayer player = new UPlayer(sender);
        if (player.hasPermission(Permission.COMMAND_DEBUG)) {
            if (args.length == 2) {
                if (args[0].equalsIgnoreCase("xp")) {
                    int xp = Integer.parseInt(args[1]);
                    player.setXP(xp);
                    return true;
                } else if (args[0].equals("refreshxp")) {
                    UPlayer target;
                    try {
                        target = new UPlayer(args[1]);
                    } catch (PlayerNotFoundException e) {
                        player.sendMessage("player not found");
                        return true;
                    }
                    player.updateXPBar();
                    player.sendMessage("XP refreshed!");
                    player.sendMessage("XP: " + target.getXP());
                    player.sendMessage("Level: " + target.getLevel());
                    return true;
                } else if (args[0].equals("life")) {
                    int life = Integer.parseInt(args[1]);
                    player.setLifeCrystals(life);
                    return true;
                } else if (args[0].equals("vote")) {
                    UPlayer target;
                    try {
                        target = new UPlayer(args[1]);
                    } catch (PlayerNotFoundException e) {
                        player.sendMessage("player not found");
                        return true;
                    }
                    player.sendMessage("Voting points: " + target.getVotingPoints());
                    return true;
                } else if (args[0].equals("inv")) {
                    UPlayer target;
                    try {
                        target = new UPlayer(args[1]);
                    } catch (PlayerNotFoundException e) {
                        player.sendMessage(Message.PLAYER_NOT_FOUND);
                        return true;
                    }
                    player.bukkit().openInventory(target.bukkit().getInventory());
                    return true;
                } else if (args[0].equals("skull")) {
                    player.getInventory().addItem(new Item(args[1]));
                    return true;
                } else if (args[0].equals("disablepl")) {
                    Main.getInstance().getServer().getPluginManager().disablePlugin(Main.getInstance().getServer().getPluginManager().getPlugin(args[1]));
                    return true;
                } else if (args[0].equals("enablepl")) {
                    Main.getInstance().getServer().getPluginManager().enablePlugin(Main.getInstance().getServer().getPluginManager().getPlugin(args[1]));
                    return true;
                } else {
                    player.sendMessage(Message.WRONG_USAGE);
                    return true;
                }
            } else if (args.length == 1) {
                if (args[0].equals("save")) {
                    for (DataFile file : DataFile.values()) {
                        file.save();
                    }
                    return true;
                } else {
                    player.sendMessage(Message.WRONG_USAGE);
                    return true;
                }
            } else {
                player.sendMessage(Message.WRONG_USAGE);
                return true;
            }
        } else {
            player.sendMessage(Message.NO_PERMISSION);
            return true;
        }
    } else {
        sender.sendMessage(Message.NOT_A_PLAYER.toString());
        return true;
    }
}
Also used : DataFile(xyz.derkades.ublisk.DataFile) Item(xyz.derkades.ublisk.utils.inventory.Item) UPlayer(xyz.derkades.ublisk.utils.UPlayer) Player(org.bukkit.entity.Player) UPlayer(xyz.derkades.ublisk.utils.UPlayer) PlayerNotFoundException(xyz.derkades.ublisk.utils.exception.PlayerNotFoundException)

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