Skip to content

Instantly share code, notes, and snippets.

@knight-ryu12
Created August 22, 2016 12:45
Show Gist options
  • Save knight-ryu12/c67cc9541ea00b594c7226085f0c9cb5 to your computer and use it in GitHub Desktop.
Save knight-ryu12/c67cc9541ea00b594c7226085f0c9cb5 to your computer and use it in GitHub Desktop.
import com.sun.istack.internal.NotNull;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
/**
* ItemGiver is Giving Item to someone
* @author Chromaryu
*/
public class ItemGiver {
/**
*
* @param p Player
* @param is ItemStack
* @return boolean
* @throws IllegalArgumentException
*/
public static boolean give(@NotNull Player p, @NotNull ItemStack is) {
if(is == null | p == null) {
throw new IllegalArgumentException("Failed to parse args");
}
PlayerInventory pi = p.getInventory();
pi.addItem(is);
return true;
}
/**
*
* @param p Player
* @param i Item
* @param n1 itemAmount
* @return boolean
* @throws IllegalArgumentException
*/
public static boolean give(@NotNull Player p, @NotNull Item i,@NotNull int n1) {
if(i == null | p == null) {
throw new IllegalArgumentException("Failed to parse args");
}
ItemStack is = i.getItemStack();
is.setAmount(n1);
PlayerInventory pi = p.getInventory();
pi.addItem(is);
return true;
}
/**
*
* @param p Player
* @param is ItemStack
* @param im ItemMeta
* @return boolean
* @throws IllegalArgumentException
*/
public static boolean give(@NotNull Player p,@NotNull ItemStack is,@NotNull ItemMeta im) {
if(is == null | p == null | im == null) {
throw new IllegalArgumentException("Failed to parse args");
}
is.setItemMeta(im);
PlayerInventory pi = p.getInventory();
pi.addItem(is);
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment