Untitled
raw download clone
JAVASCRIPT
views 17
,
size 6954 b
package me.samy.customitems;

import java.util.ArrayList;
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

import net.md_5.bungee.api.ChatColor;

public class CustomItem extends JavaPlugin implements Listener{
	
public List<String> list = new ArrayList<String>(); 
	
	@Override
	public void onEnable() {
		this.getServer().getPluginManager().registerEvents(this, this);
		

	}

	@Override
	public void onDisable() {

	}
	


	public boolean onCommand(CommandSender sender, Command cmd, String lable, String[] args) {
		Player player = (Player) sender;

			
		
		
		
		if (!player.hasPermission("getBottle.use")) {
			player.sendMessage(ChatColor.RED + "you do not have permission to use this command");
			return  true;
	}
		
		if (lable.equalsIgnoreCase("getBottle")) {
			if (!(sender instanceof Player)) {
				sender.sendMessage(ChatColor.RED + "You cannot use this command!");
				return true;
	}	
			
			if (player.getInventory().firstEmpty() == -1) {
				
				Location loc = player.getLocation();
				World world = player.getWorld();
				
				world.dropItemNaturally(loc, getPinkBottle());
				player.sendMessage(ChatColor.GOLD + "You Got A Bottle");
				return true;
				
	}
			player.getInventory().addItem(getPinkBottle());
			player.sendMessage(ChatColor.GOLD + "You Got A Bottle But It Is On The Ground!");
			return true;
	}
		
		return false;
	} 
	
	public ItemStack getPinkBottle() {
				
		ItemStack PinkBottle = new ItemStack(Material.POTION);
		ItemMeta meta = PinkBottle.getItemMeta();
		
		meta.setDisplayName(ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Pink Bottle");
		List<String> lore = new ArrayList<String>();
		lore.add("");
		meta.setLore(lore);	
		meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
		meta.setUnbreakable(true);
		meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
		meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
		meta.addItemFlags(ItemFlag.HIDE_DESTROYS);
		meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
		meta.addItemFlags(ItemFlag.HIDE_PLACED_ON);
		PinkBottle.setItemMeta(meta);
		return PinkBottle;
	}

	


	public ItemStack getEmptyPinkBottle() {
		
		ItemStack PinkEmptyBottle = new ItemStack(Material.BOWL);
		ItemMeta meta = PinkEmptyBottle.getItemMeta();
		
		meta.setDisplayName(ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Pink Bottle");
		List<String> lore = new ArrayList<String>();
		lore.add("");
		meta.setLore(lore);	
		meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
		meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
		meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
		meta.addItemFlags(ItemFlag.HIDE_DESTROYS);
		meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
		meta.addItemFlags(ItemFlag.HIDE_PLACED_ON);
		meta.setUnbreakable(true);
		
		
		PinkEmptyBottle.setItemMeta(meta);
		
		return PinkEmptyBottle;
	}

	
	@EventHandler(priority = EventPriority.HIGHEST)
	public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
		if (event.getPlayer().getInventory().getItemInMainHand().getItemMeta().hasLore()){
			Player player = (Player) event.getPlayer();
			
			player.getInventory().addItem(getEmptyPinkBottle());
			player.getInventory().remove(Material.GLASS_BOTTLE);
			player.updateInventory();
            ItemStack air = new ItemStack(Material.AIR);
            player.getInventory().setItemInMainHand(air);
			
			
			
	     }
	}
	@EventHandler(priority = EventPriority.HIGHEST)
	public void onClick(PlayerInteractEvent event) {
		if (event.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.BOWL))
			if (event.getPlayer().getInventory().getItemInMainHand().getItemMeta().hasLore()) {
				Player player = (Player) event.getPlayer();
				
				if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
					 if(event.getClickedBlock().getRelative(event.getBlockFace()).getType() == Material.WATER) {
						player.getInventory().contains(getEmptyPinkBottle());
							player.getInventory().removeItem(getEmptyPinkBottle());
							player.getInventory().addItem(getPinkBottle());
							player.updateInventory();
							
					 }
				}
			}
				
			
	
				
			}

			
			@EventHandler(priority = EventPriority.LOWEST)
			public void onPlayerItemConsume1(PlayerItemConsumeEvent event) {
				if (event.getPlayer().getInventory().getItemInOffHand().getItemMeta().hasLore()){
					Player player = (Player) event.getPlayer();
					
					player.getInventory().addItem(getEmptyPinkBottle());
					player.getInventory().remove(Material.GLASS_BOTTLE);
					player.updateInventory();
					ItemStack Bottle = new ItemStack(Material.GLASS_BOTTLE);
					player.getInventory().remove(Bottle);
		            ItemStack air = new ItemStack(Material.AIR);
		            player.getInventory().setItemInMainHand(air);
					
					
					
			     }
			}
			@EventHandler(priority = EventPriority.HIGHEST)
			public void onClick1(PlayerInteractEvent event) {
				if (event.getPlayer().getInventory().getItemInOffHand().getType().equals(Material.BOWL))
					if (event.getPlayer().getInventory().getItemInOffHand().getItemMeta().hasLore()) {
						Player player = (Player) event.getPlayer();
						
						if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
							 if(event.getClickedBlock().getRelative(event.getBlockFace()).getType() == Material.WATER) {
								player.getInventory().contains(getEmptyPinkBottle());
									player.getInventory().removeItem(getEmptyPinkBottle());
									player.getInventory().addItem(getPinkBottle());
									player.updateInventory();
									
						}
					}
				}
			}
				@SuppressWarnings("deprecation")
				@EventHandler
				    public void onConsume(PlayerItemConsumeEvent event) {
				        if (event.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.POTION)) {
				            Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(this, new BukkitRunnable(){
				                @Override
				                public void run() {
				                    event.getPlayer().getInventory().setItemInMainHand(new ItemStack(Material.AIR));
				                }
				            }, 1L);
				        }
				    }

				
				
			}
close fullscreen
Login or Register to edit or fork this paste. It's free.