Search in sources :

Example 1 with Item

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

the class Voting method onVoteBoxOpen.

@EventHandler(priority = EventPriority.HIGH)
public void onVoteBoxOpen(PlayerInteractEvent event) {
    if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
        return;
    }
    UPlayer player = new UPlayer(event);
    if (player.isSneaking()) {
        return;
    }
    Block block = event.getClickedBlock();
    if (Voting.isVotingChest(block)) {
        Chest chest = (Chest) block.getState();
        Inventory inv = chest.getInventory();
        int gold = Voting.getRandomGold();
        int xp = Voting.getRandomXP();
        int life = Voting.getRandomLife();
        Item goldItem = new Item(Material.GOLD_NUGGET).setName(ChatColor.GOLD + "" + ChatColor.BOLD + "Gold: " + gold).setAmount(gold);
        Item xpItem = new Item(Material.EXP_BOTTLE).setName(ChatColor.GREEN + "" + ChatColor.BOLD + "XP: " + xp).setAmount(xp);
        Item lifeItem = new Item(Material.NETHER_STAR).setName(ChatColor.BOLD + "Life Crystals: " + life).setAmount(life);
        inv.setItem(12, goldItem.getItemStack());
        inv.setItem(13, xpItem.getItemStack());
        inv.setItem(14, lifeItem.getItemStack());
        if (gold != 0) {
            player.getInventory().addItem(Material.GOLD_NUGGET, gold);
        }
        if (xp != 0) {
            player.addXP(xp);
        }
        if (life != 0) {
            player.setLifeCrystals(player.getLifeCrystals() + life);
        }
        player.tracker(PlayerInfo.VOTE_BOX);
        Logger.log(LogLevel.DEBUG, "Voting", "Gold: " + gold + " | XP: " + xp + " | Life: " + life);
    }
}
Also used : Chest(org.bukkit.block.Chest) Item(xyz.derkades.ublisk.utils.inventory.Item) UPlayer(xyz.derkades.ublisk.utils.UPlayer) Block(org.bukkit.block.Block) Inventory(org.bukkit.inventory.Inventory) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Item

use of xyz.derkades.ublisk.utils.inventory.Item 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 3 with Item

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

the class LifeCrystalInventory method run.

@Override
public void run() {
    for (UPlayer player : Ublisk.getOnlinePlayers()) {
        if (player.isInBuilderMode()) {
            Item helmet = new Item(Material.GOLD_HELMET).setName(ChatColor.GOLD + "Builder's Helmet");
            player.getInventory().setHelmet(helmet);
        } else {
            Item menuChest = new Item(Material.CHEST).setName(ChatColor.BLUE + "" + ChatColor.BOLD + "Chest").setLore(ChatColor.GRAY + "Right click to open menu.", ChatColor.GRAY + "TIP: You can also use /menu").setDroppable(false);
            player.getInventory().set(7, menuChest);
            Item item = new Item(Material.NETHER_STAR).setAmount(player.getLifeCrystals()).setName(ChatColor.BLUE + "Life Crystals: " + ChatColor.AQUA + player.getLifeCrystals()).setLore("You have " + player.getLifeCrystals() + " life crystals").setDroppable(false);
            player.getInventory().set(8, item);
        }
    }
}
Also used : Item(xyz.derkades.ublisk.utils.inventory.Item) UPlayer(xyz.derkades.ublisk.utils.UPlayer)

Example 4 with Item

use of xyz.derkades.ublisk.utils.inventory.Item 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)

Example 5 with Item

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

the class PlayerDropItem method onItemDrop.

@EventHandler(priority = EventPriority.LOW)
public void onItemDrop(PlayerDropItemEvent event) {
    UPlayer player = new UPlayer(event);
    if (player.isInBuilderMode()) {
        return;
    }
    Item item = new Item(event.getItemDrop());
    event.setCancelled(!item.isDroppable());
}
Also used : Item(xyz.derkades.ublisk.utils.inventory.Item) UPlayer(xyz.derkades.ublisk.utils.UPlayer) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Item (xyz.derkades.ublisk.utils.inventory.Item)8 UPlayer (xyz.derkades.ublisk.utils.UPlayer)5 EventHandler (org.bukkit.event.EventHandler)2 UInventory (xyz.derkades.ublisk.utils.inventory.UInventory)2 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)1 NBTTagList (net.minecraft.server.v1_12_R1.NBTTagList)1 Block (org.bukkit.block.Block)1 Chest (org.bukkit.block.Chest)1 Player (org.bukkit.entity.Player)1 Inventory (org.bukkit.inventory.Inventory)1 DataFile (xyz.derkades.ublisk.DataFile)1 MoneyItem (xyz.derkades.ublisk.money.MoneyItem)1 QuestParticipant (xyz.derkades.ublisk.quest.QuestParticipant)1 PlayerNotFoundException (xyz.derkades.ublisk.utils.exception.PlayerNotFoundException)1