Search in sources :

Example 1 with NMSAbstraction

use of com.wasteofplastic.acidisland.nms.NMSAbstraction in project acidisland by tastybento.

the class AcidInventory method onWaterBottleFill.

/**
 * Event that covers filling a bottle
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onWaterBottleFill(final PlayerInteractEvent e) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: " + e.getEventName());
    Player player = e.getPlayer();
    if (!player.getWorld().getName().equalsIgnoreCase(Settings.worldName))
        return;
    if (Settings.acidDamage == 0D || !Settings.acidBottle)
        return;
    if (!player.getItemInHand().getType().equals(Material.GLASS_BOTTLE)) {
        return;
    }
    // plugin.getLogger().info(e.getEventName() + " called");
    // Look at what the player was looking at
    BlockIterator iter = new BlockIterator(player, 10);
    Block lastBlock = iter.next();
    while (iter.hasNext()) {
        lastBlock = iter.next();
        if (lastBlock.getType() == Material.AIR)
            continue;
        break;
    }
    // plugin.getLogger().info(lastBlock.getType().toString());
    if (lastBlock.getType().equals(Material.WATER) || lastBlock.getType().equals(Material.STATIONARY_WATER) || lastBlock.getType().equals(Material.CAULDRON)) {
        // They *may* have filled a bottle with water
        // Check inventory for POTIONS in a tick
        plugin.getServer().getScheduler().runTask(plugin, new Runnable() {

            @Override
            public void run() {
                // plugin.getLogger().info("Checking inventory");
                PlayerInventory inv = e.getPlayer().getInventory();
                if (inv.contains(Material.POTION)) {
                    // plugin.getLogger().info("POTION in inventory");
                    // They have a POTION of some kind in inventory
                    int i = 0;
                    for (ItemStack item : inv.getContents()) {
                        if (item != null) {
                            // item.getType().toString());
                            if (item.getType().equals(Material.POTION)) {
                                NMSAbstraction nms = null;
                                try {
                                    nms = Util.checkVersion();
                                } catch (Exception ex) {
                                    return;
                                }
                                if (!nms.isPotion(item)) {
                                    // plugin.getLogger().info("Water bottle found!");
                                    ItemMeta meta = item.getItemMeta();
                                    meta.setDisplayName(plugin.myLocale(e.getPlayer().getUniqueId()).acidBottle);
                                    // ArrayList<String> lore = new
                                    // ArrayList<String>(Arrays.asList("Poison",
                                    // "Beware!", "Do not drink!"));
                                    meta.setLore(lore);
                                    item.setItemMeta(meta);
                                    inv.setItem(i, item);
                                }
                            }
                        }
                        i++;
                    }
                }
            }
        });
    }
}
Also used : BlockIterator(org.bukkit.util.BlockIterator) Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) ASkyBlock(com.wasteofplastic.acidisland.ASkyBlock) PlayerInventory(org.bukkit.inventory.PlayerInventory) ItemStack(org.bukkit.inventory.ItemStack) NMSAbstraction(com.wasteofplastic.acidisland.nms.NMSAbstraction) ItemMeta(org.bukkit.inventory.meta.ItemMeta) EventHandler(org.bukkit.event.EventHandler)

Example 2 with NMSAbstraction

use of com.wasteofplastic.acidisland.nms.NMSAbstraction in project acidisland by tastybento.

the class AcidInventory method onInventoryOpen.

/**
 * This covers items in a chest, etc. inventory, then change the name then
 *
 * @param e - event
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onInventoryOpen(InventoryOpenEvent e) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: " + e.getEventName());
    // plugin.getLogger().info("Inventory open event called");
    if (e.getPlayer().getWorld().getName().equalsIgnoreCase(Settings.worldName)) {
        Inventory inventory = e.getInventory();
        if (Settings.acidDamage == 0D || !Settings.acidBottle) {
            return;
        }
        // If this is the minishop - forget it
        if (inventory.getName() != null && inventory.getName().equalsIgnoreCase(plugin.myLocale(e.getPlayer().getUniqueId()).islandMiniShopTitle)) {
            return;
        }
        if (inventory.contains(Material.WATER_BUCKET)) {
            if (DEBUG)
                plugin.getLogger().info("Inventory contains water bucket");
            ItemStack[] inv = inventory.getContents();
            for (ItemStack item : inv) {
                if (item != null) {
                    // plugin.getLogger().info(item.toString());
                    if (item.getType() == Material.WATER_BUCKET) {
                        if (DEBUG)
                            plugin.getLogger().info("Found it!");
                        ItemMeta meta = item.getItemMeta();
                        meta.setDisplayName(plugin.myLocale(e.getPlayer().getUniqueId()).acidBucket);
                        lore = Arrays.asList(plugin.myLocale(e.getPlayer().getUniqueId()).acidLore.split("\n"));
                        meta.setLore(lore);
                        item.setItemMeta(meta);
                    }
                }
            }
        } else if (inventory.contains(Material.POTION)) {
            if (DEBUG)
                plugin.getLogger().info("Inventory contains water bottle");
            ItemStack[] inv = inventory.getContents();
            for (ItemStack item : inv) {
                if (item != null) {
                    // plugin.getLogger().info(item.toString());
                    if (item.getType() == Material.POTION) {
                        NMSAbstraction nms = null;
                        try {
                            nms = Util.checkVersion();
                        } catch (Exception ex) {
                            return;
                        }
                        if (!nms.isPotion(item)) {
                            if (DEBUG)
                                plugin.getLogger().info("Found it!");
                            ItemMeta meta = item.getItemMeta();
                            meta.setDisplayName(plugin.myLocale(e.getPlayer().getUniqueId()).acidBottle);
                            lore = Arrays.asList(plugin.myLocale(e.getPlayer().getUniqueId()).acidLore.split("\n"));
                            meta.setLore(lore);
                            item.setItemMeta(meta);
                        }
                    }
                }
            }
        }
    }
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) NMSAbstraction(com.wasteofplastic.acidisland.nms.NMSAbstraction) BrewerInventory(org.bukkit.inventory.BrewerInventory) Inventory(org.bukkit.inventory.Inventory) PlayerInventory(org.bukkit.inventory.PlayerInventory) ItemMeta(org.bukkit.inventory.meta.ItemMeta) EventHandler(org.bukkit.event.EventHandler)

Example 3 with NMSAbstraction

use of com.wasteofplastic.acidisland.nms.NMSAbstraction in project acidisland by tastybento.

the class AcidInventory method onWaterBottleDrink.

/**
 * Checks to see if a player is drinking acid
 *
 * @param e - event
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onWaterBottleDrink(final PlayerItemConsumeEvent e) {
    if (Settings.acidDamage == 0D || !Settings.acidBottle)
        return;
    if (DEBUG)
        plugin.getLogger().info("DEBUG: " + e.getEventName());
    if (e.getPlayer().getWorld().getName().equalsIgnoreCase(Settings.worldName) && e.getItem().getType().equals(Material.POTION)) {
        if (DEBUG)
            plugin.getLogger().info(e.getEventName() + " called for " + e.getItem().getType());
        NMSAbstraction nms = null;
        try {
            nms = Util.checkVersion();
        } catch (Exception ex) {
            return;
        }
        if (!nms.isPotion(e.getItem())) {
            plugin.getLogger().info(e.getPlayer().getName() + " " + plugin.myLocale().drankAcidAndDied);
            if (!Settings.muteDeathMessages) {
                for (Player p : plugin.getServer().getOnlinePlayers()) {
                    Util.sendMessage(p, e.getPlayer().getName() + " " + plugin.myLocale(p.getUniqueId()).drankAcid);
                }
            }
            final ItemStack item = new ItemStack(Material.GLASS_BOTTLE);
            e.getPlayer().setItemInHand(item);
            e.getPlayer().setHealth(0D);
            e.setCancelled(true);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) ItemStack(org.bukkit.inventory.ItemStack) NMSAbstraction(com.wasteofplastic.acidisland.nms.NMSAbstraction) EventHandler(org.bukkit.event.EventHandler)

Aggregations

NMSAbstraction (com.wasteofplastic.acidisland.nms.NMSAbstraction)3 EventHandler (org.bukkit.event.EventHandler)3 ItemStack (org.bukkit.inventory.ItemStack)3 Player (org.bukkit.entity.Player)2 PlayerInventory (org.bukkit.inventory.PlayerInventory)2 ItemMeta (org.bukkit.inventory.meta.ItemMeta)2 ASkyBlock (com.wasteofplastic.acidisland.ASkyBlock)1 Block (org.bukkit.block.Block)1 BrewerInventory (org.bukkit.inventory.BrewerInventory)1 Inventory (org.bukkit.inventory.Inventory)1 BlockIterator (org.bukkit.util.BlockIterator)1