本文整理汇总了Java中org.bukkit.inventory.PlayerInventory.addItem方法的典型用法代码示例。如果您正苦于以下问题:Java PlayerInventory.addItem方法的具体用法?Java PlayerInventory.addItem怎么用?Java PlayerInventory.addItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.inventory.PlayerInventory
的用法示例。
在下文中一共展示了PlayerInventory.addItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onWorldChange
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
@EventHandler (priority = EventPriority.HIGHEST)
public void onWorldChange(PlayerChangedWorldEvent e){
Player p = e.getPlayer();
World w = p.getWorld();
if(!isEnabled(w)) return;
PlayerInventory inv = p.getInventory();
ItemStack chestplate = inv.getChestplate();
if(chestplate == null || chestplate.getType() != Material.ELYTRA) return;
inv.setChestplate(new ItemStack(Material.AIR));
if(inv.firstEmpty() != -1)
inv.addItem(chestplate);
else
w.dropItem(p.getLocation(), chestplate);
}
示例2: onProjectileHit
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.LOW)
public void onProjectileHit(ProjectileHitEvent event)
{
if(event.getEntityType() != EntityType.ARROW && event.getEntityType() != EntityType.SNOWBALL) return;
Projectile arrow = event.getEntity();
ProjectileSource source = arrow.getShooter();
if(source == null || !(source instanceof Player)) return;
Player player = (Player)source;
if(player.getGameMode() == GameMode.CREATIVE) return;
Flag flag = this.GetFlagInstanceAtLocation(arrow.getLocation(), player);
if(flag == null) return;
PlayerInventory inventory = player.getInventory();
ItemMeta meta = inventory.getItemInMainHand().getItemMeta();
if(meta != null && meta.hasEnchant(Enchantment.ARROW_INFINITE)) return;
arrow.remove();
inventory.addItem(new ItemStack(Material.ARROW));
}
示例3: giveFirstPlayKit
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
public static void giveFirstPlayKit(Player p, SQLUser sqlUser) {
PlayerInventory inv = p.getInventory();
if ( !sqlUser.getRank().equals("Gracz")){
Kits.giveVipKit(p);
inv.addItem(
new ItemStack(Material.ENDER_CHEST, 2)
);
} else {
Kits.giveDefaultKit(p);
inv.addItem(
new ItemStack(Material.ENDER_CHEST, 1)
);
}
}
示例4: onItemClick
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
@Override
public void onItemClick(ItemClickEvent event)
{
Player player = event.getPlayer();
PlayerInventory p = player.getInventory();
if(p.containsAtLeast(new ItemStack(Material.GOLD_INGOT), cost))
{
int total = 0;
for(ItemStack s : p.all(Material.GOLD_INGOT).values())
{
total += s.getAmount();
}
p.remove(Material.GOLD_INGOT);
if(total-cost > 0)
p.addItem(new ItemStack(Material.GOLD_INGOT,total-cost));
p.addItem(product);
player.sendMessage(Lang.PURCHASEDITEM.toString());
}
else player.sendMessage(Lang.COULDNOTPURCHASE.toString());
}
示例5: restoreInventory
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
void restoreInventory(Player p) {
removeAllTools(p);
UUID uuid = p.getUniqueId();
ItemStack[] savedInv = savedInventories.get(uuid);
if(savedInv == null) return;
PlayerInventory plrInv = p.getInventory();
ItemStack[] newItems = plrInv.getContents().clone();
plrInv.setContents(savedInv);
savedInventories.remove(uuid);
for(ItemStack i : newItems) {
if(i == null) continue;
HashMap<Integer, ItemStack> couldntFit = plrInv.addItem(i);
for (ItemStack is : couldntFit.values()) {
p.getWorld().dropItem(p.getLocation(), is);
}
}
p.sendMessage(ChatColor.GREEN + Config.invReturned);
}
示例6: checkMobInventoy
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
public static void checkMobInventoy(EntityType Entity, Player p, EntityDeathEvent ede){
PlayerInventory pi = p.getInventory();
FileConfiguration gc = Core.plugin.getConfig();
//Checks to see if killed entity is a Player
if(Entity.equals(EntityType.PLAYER)){
if(!Globals.PlayerDrops){ede.getDrops().clear();}
}else{
if(!Globals.BothDrops){ ede.getDrops().clear(); };
}
//Shows Killed Entity and What item is in config according to said Entity.
if(Globals.Debug){
p.sendMessage(Globals.Debug(Entity.name()));
p.sendMessage(Globals.Debug(gc.getString("eDrop.Mobs." + Entity.name() + ".Item")));
}
Material m = Material.valueOf(gc.getString("eDrop.Mobs." + Entity.name() + ".Item")); //Gets Mobs Item
int a = gc.getInt("eDrop.Mobs." + Entity.name() + ".ItemAmount"); //Gets Mobs Item Amount
pi.addItem(new ItemStack(m, a)); //Adds Item to Inventory of Player
}
示例7: mergeIntoPlayerInventory
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
public void mergeIntoPlayerInventory(Player player, Location overflowDropLocation) {
PlayerInventory inventory = player.getInventory();
LinkedList<ItemStack> overflows = new LinkedList<ItemStack>();
inventory.setArmorContents(itemsToSet(inventory.getArmorContents(), savedArmorContents, overflows));
inventory.setContents(itemsToSet(inventory.getContents(), savedInventoryContents, overflows));
// Now add any overflows
HashMap<Integer, ItemStack> failedToAdd = inventory.addItem(overflows.toArray(new ItemStack[overflows.size()]));
// If we failed to add any items (due to a full inventory), drop them near the player
// This can only occur if another plugin has filled up the player's inventory before us
for (ItemStack item : failedToAdd.values()) {
player.sendMessage("Dropping " + item.getAmount() + " " + item.getType() + " due to full inventory!");
player.getWorld().dropItem(overflowDropLocation, item);
}
}
示例8: onCommand
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
Player player = null;
if (!(sender instanceof Player))
Resources.privateMsg(sender, "Only a player can execute this command");
else{
//Permissions
if (!sender.hasPermission("LetItRain.launcher"))
return true;
player = (Player)sender;
PlayerInventory inventory = player.getInventory();
inventory.addItem(new ItemStack(LetItRain.item));
String outputMsg = LetItRain.dGrenadeMsg;
outputMsg = outputMsg.replaceAll(Pattern.quote("[player]"), player.getName());
if(!outputMsg.isEmpty())
Resources.broadcast(outputMsg);
}
return true;
}
示例9: handlePlayer
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
public boolean handlePlayer(BytecraftPlayer player, String[] args)
{
if(!player.getRank().canSpawnHeads()){
player.sendMessage(getInvalidPermsMessage());
return true;
}
if (args.length == 1) {
ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
SkullMeta itemMeta = (SkullMeta) item.getItemMeta();
itemMeta.setOwner(args[0]);
itemMeta.setDisplayName(ChatColor.YELLOW + args[0] + "'s head");
item.setItemMeta(itemMeta);
PlayerInventory inventory = player.getInventory();
inventory.addItem(item);
player.sendMessage(ChatColor.YELLOW + "You received the head of "
+ args[0]);
}
else {
player.sendMessage(ChatColor.RED + "Type /head <player>");
}
return true;
}
示例10: stuff
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
/**
* Give an item set to a player.
* @param player
* @param item
*/
public void stuff(Player player, ItemSet item)
{
PlayerInventory inv = player.getInventory();
switch (item)
{
case MANUAL:
if (new Random().nextInt(20) > 0)
inv.addItem(manual);
else
inv.addItem(manual_bonus);
break;
case SPECTATOR:
inv.addItem(spectating_compass);
break;
}
}
示例11: giveVipKit
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
public static void giveVipKit(Player p) {
PlayerInventory inv = p.getInventory();
if (inv.firstEmpty() != -1) {
inv.addItem(
new ItemStack(Material.IRON_SWORD, 1),
new ItemStack(Material.IRON_PICKAXE, 1),
new ItemStack(Material.IRON_AXE, 1),
new ItemStack(Material.IRON_SPADE, 1),
new ItemStack(Material.COOKED_BEEF, 32),
new ItemStack(Material.BOAT, 1)
);
}
}
示例12: giveDefaultKit
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
public static void giveDefaultKit(Player p) {
PlayerInventory inv = p.getInventory();
if (inv.firstEmpty() != -1) {
inv.addItem(
new ItemStack(Material.STONE_SWORD, 1),
new ItemStack(Material.STONE_PICKAXE, 1),
new ItemStack(Material.STONE_AXE, 1),
new ItemStack(Material.STONE_SPADE, 1),
new ItemStack(Material.COOKED_BEEF, 32),
new ItemStack(Material.BOAT, 1)
);
}
}
示例13: giveStartingGear
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
/**Gives the players starting gear, called during dungeon startup.
* @param p The player to give stuff to.
*/
private void giveStartingGear(Player p) {
PlayerInventory i = p.getInventory();
i.clear();
i.addItem( new ItemStack(Material.STONE_SWORD, 1));
i.addItem( new ItemStack(Material.BOW, 1));
i.addItem( new ItemStack(Material.ARROW, 1));
i.addItem( new ItemStack(Material.MUSHROOM_SOUP, 1));
i.setBoots(new ItemStack(Material.LEATHER_BOOTS, 1));
}
示例14: give
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
@Override
public void give(Player player) {
for (ItemReward item : getItems()) {
Material material = Material.getMaterial(item.getId());
if (material != null) {
ItemStack stack = new ItemStack(material, item.getAmount());
PlayerInventory inventory = player.getInventory();
HashMap<Integer, ItemStack> leftOvers = inventory.addItem(stack);
for (ItemStack itemStack : leftOvers.values()) {
player.getWorld().dropItemNaturally(player.getLocation(), itemStack);
}
}
}
}
示例15: apply
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
@Override
public void apply(GamePlayer player) {
PlayerInventory inventory = player.getBukkit().getInventory();
if (this.hasSlot()) {
inventory.setItem(this.getSlot(), this.getResult());
} else {
inventory.addItem(this.getResult());
}
}