Search in sources :

Example 16 with UPlayer

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

the class BankMenu method onOptionClick.

@Override
public boolean onOptionClick(OptionClickEvent event) {
    UPlayer player = new UPlayer(event);
    MoneyItem item = MoneyItem.fromItem(new Item(event.getItemStack()));
    if (item == null) {
        player.sendMessage(Message.ERROR_MENU);
        return true;
    }
    UInventory inv = player.getInventory();
    if (event.getName().contains("Deposit")) {
        if (!inv.contains(item)) {
            player.sendMessage(Message.INVENTORY_NOT_CONTAIN_MONEY_ITEM);
            return false;
        }
        player.setMoney(player.getMoney() + item.getValue());
        inv.remove(item);
    } else {
        if (player.getMoney() < item.getValue()) {
            player.sendMessage(Message.NOT_ENOUGH_MONEY);
            return false;
        }
        player.setMoney(player.getMoney() - item.getValue());
        inv.addItem(item);
    }
    return false;
}
Also used : Item(xyz.derkades.ublisk.utils.inventory.Item) UPlayer(xyz.derkades.ublisk.utils.UPlayer) UInventory(xyz.derkades.ublisk.utils.inventory.UInventory)

Example 17 with UPlayer

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

the class FriendsMenu method onOptionClick.

@Override
public boolean onOptionClick(OptionClickEvent event) {
    UPlayer player = new UPlayer(event);
    Material item = event.getItemStack().getType();
    if (item == Material.SPECKLED_MELON) {
        if (player.getSetting(Setting.FRIENDS_SHOW_HEALTH)) {
            player.setSetting(Setting.FRIENDS_SHOW_HEALTH, false);
            player.sendMessage(Message.FRIEND_HEALTH_DISABLED);
        } else {
            player.setSetting(Setting.FRIENDS_SHOW_HEALTH, true);
            player.sendMessage(Message.FRIEND_HEALTH_ENABLED);
        }
        return false;
    } else if (player.getFriends().isEmpty()) {
        return false;
    } else {
        // Clicked item is a player
        // OfflinePlayer friend = Ublisk.getOfflinePlayer(event.getName());
        OfflinePlayer offlineFriend = player.getFriends().get(event.getPosition());
        if (offlineFriend == null)
            player.sendMessage("error");
        UPlayer friend = new UPlayer(offlineFriend);
        player.sendMessage(friend.getDisplayName(ChatColor.DARK_AQUA, true), new ComponentBuilder(" - ").color(ChatColor.DARK_GRAY).bold(true).create(), new ComponentBuilder("Remove friend").color(ChatColor.RED).italic(true).event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/friend remove " + friend.getName())).create());
        return true;
    }
}
Also used : UPlayer(xyz.derkades.ublisk.utils.UPlayer) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) OfflinePlayer(org.bukkit.OfflinePlayer) Material(org.bukkit.Material) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 18 with UPlayer

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

the class MainMenu method onOptionClick.

@Override
public boolean onOptionClick(OptionClickEvent event) {
    String name = event.getName().toLowerCase();
    final UPlayer player = new UPlayer(event.getPlayer());
    if (name.equals("settings")) {
        new SettingsMenu(player).open();
    } else if (name.equals("voting")) {
        new VotingMenu(player).open();
    } else if (name.equals("friends")) {
        new FriendsMenu(player).open();
    } else if (name.equals("help")) {
        new HelpMenu(player).open();
    } else if (name.equals("bank")) {
        new BankMenu(player).open();
    } else {
        player.sendMessage(Message.ERROR_MENU);
    }
    return false;
}
Also used : UPlayer(xyz.derkades.ublisk.utils.UPlayer) HelpMenu(xyz.derkades.ublisk.iconmenus.help.HelpMenu) BankMenu(xyz.derkades.ublisk.money.BankMenu)

Example 19 with UPlayer

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

the class SettingsMenu method onOptionClick.

@Override
public boolean onOptionClick(OptionClickEvent event) {
    String name = event.getName();
    final UPlayer player = new UPlayer(event.getPlayer());
    if (name.equalsIgnoreCase("back")) {
        new MainMenu(player).open();
        return false;
    }
    Setting setting = Setting.fromName(name);
    // If setting is set to true, set to false and if set to false, set to true
    player.setSetting(setting, !player.getSetting(setting));
    String enabledDisabled;
    if (player.getSetting(setting))
        enabledDisabled = "enabled";
    else
        enabledDisabled = "disabled";
    player.sendMessage(Ublisk.getPrefix("Settings") + name + " has been " + enabledDisabled + ".");
    // Re-open menu to refresh settings
    this.open();
    return false;
}
Also used : UPlayer(xyz.derkades.ublisk.utils.UPlayer) Setting(xyz.derkades.ublisk.utils.settings.Setting)

Example 20 with UPlayer

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

the class VotingMenu method onOptionClick.

@Override
public boolean onOptionClick(OptionClickEvent event) {
    String name = event.getName().toLowerCase();
    UPlayer player = new UPlayer(event.getPlayer());
    if (name.contains("points")) {
        return false;
    } else {
        if (Voting.playerOpeningBox != null) {
            player.sendMessage(Message.VOTE_BOX_BUSY);
            return false;
        } else if (!player.hasVotingPoints(3)) {
            player.sendMessage(Message.VOTE_BOX_INSUFFICIENT_POINTS);
            return false;
        } else {
            player.setVotingPoints(player.getVotingPoints() - 3);
            // TODO Use UPlayer
            Voting.openVotingBox(player.bukkit());
            return true;
        }
    }
}
Also used : UPlayer(xyz.derkades.ublisk.utils.UPlayer)

Aggregations

UPlayer (xyz.derkades.ublisk.utils.UPlayer)47 EventHandler (org.bukkit.event.EventHandler)26 Player (org.bukkit.entity.Player)9 PlayerNotFoundException (xyz.derkades.ublisk.utils.exception.PlayerNotFoundException)7 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)5 Item (xyz.derkades.ublisk.utils.inventory.Item)5 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)4 ArrayList (java.util.ArrayList)3 ClickEvent (net.md_5.bungee.api.chat.ClickEvent)3 Material (org.bukkit.Material)3 OfflinePlayer (org.bukkit.OfflinePlayer)3 Chest (org.bukkit.block.Chest)3 Action (org.bukkit.event.block.Action)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 Town (xyz.derkades.ublisk.Town)3 MainMenu (xyz.derkades.ublisk.iconmenus.MainMenu)3 UUID (java.util.UUID)2 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)2 Location (org.bukkit.Location)2 Block (org.bukkit.block.Block)2