Java Code Examples for org.bukkit.material.MaterialData#toItemStack()

The following examples show how to use org.bukkit.material.MaterialData#toItemStack() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlagSpectate.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
private void addLeaveItem(Player player) {
      MaterialData data = config.getFlagSection().getLeaveItem();
      if (data == null) {
      	return;
}

      MetadatableItemStack stack = new MetadatableItemStack(data.toItemStack(1));
      ItemMeta meta = stack.getItemMeta();
      meta.setDisplayName(getI18N().getString(Messages.Player.LEAVE_SPECTATE_DISPLAYNAME));
      meta.setLore(Lists.newArrayList(getI18N().getString(Messages.Player.LEAVE_SPECTATE_LORE)));
      stack.setItemMeta(meta);

      stack.setMetadata(LEAVE_ITEM_KEY, null);

      player.getInventory().setItem(RIGHT_HOTBAR_SLOT, stack);
      player.updateInventory();
  }
 
Example 2
Source File: CustomItem.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
@Deprecated
public CustomItem(MaterialData data, String name, String... lore) {
	super(data.toItemStack(1));
	ItemMeta im = getItemMeta();
	im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
	List<String> lines = new ArrayList<String>();
	for (String line: lore) {
		lines.add(ChatColor.translateAlternateColorCodes('&', line));
	}
	im.setLore(lines);
	setItemMeta(im);
}
 
Example 3
Source File: FlagQueueLobby.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe(priority = Subscribe.Priority.MONITOR)
public void onQueueEnter(PlayerEnterQueueEvent event) {
	if (event.isCancelled()) {
		return;
	}
	
	Location teleportPoint = getValue();
	
	SpleefPlayer player = event.getPlayer();
	Player bukkitPlayer = player.getBukkitPlayer();
	
	PlayerStateHolder holder = new PlayerStateHolder();
	holder.setLocation(bukkitPlayer.getLocation());
	holder.setGamemode(bukkitPlayer.getGameMode());
	
	bukkitPlayer.setGameMode(GameMode.SURVIVAL);
	player.teleport(teleportPoint);
	
	holder.updateState(bukkitPlayer, false, holder.getGamemode());
	player.savePlayerState(this, holder);

       boolean adventureMode = config.getGeneralSection().isAdventureMode();
	PlayerStateHolder.applyDefaultState(bukkitPlayer, adventureMode);
	
	MaterialData data = config.getFlagSection().getLeaveItem();
	if (data != null) {
		MetadatableItemStack stack = new MetadatableItemStack(data.toItemStack(1));
		ItemMeta meta = stack.getItemMeta();
		meta.setDisplayName(getI18N().getString(Messages.Player.LEAVE_QUEUE_DISPLAYNAME));
		meta.setLore(Lists.newArrayList(getI18N().getString(Messages.Player.LEAVE_QUEUE_LORE)));
		stack.setItemMeta(meta);

		stack.setMetadata(LEAVE_ITEM_KEY, null);

		bukkitPlayer.getInventory().setItem(RIGHT_HOTBAR_SLOT, stack);
		bukkitPlayer.updateInventory();
	}
}
 
Example 4
Source File: FlagTrackingSpectate.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Subscribe
public void onPlayerJoinGame(PlayerJoinGameEvent event) {
	SpleefPlayer player = event.getPlayer();
	GuiInventory trackerInventory = getTrackerInventory();
	
	//Insert the player's head somewhere in the tracker inventory
	for (int y = 0; y < trackerInventory.getLines(); y++) {
		for (int x = 0; x < GuiInventory.SLOTS_PER_LINE; x++) {
			trackerInventory.getSlot(x, y);
			
			GuiInventorySlot slot = trackerInventory.getSlot(x, y);
			if (slot.getItem() != null) {
				continue;
			}
			
			MaterialData data = new MaterialData(Material.SKULL_ITEM, (byte)SkullType.PLAYER.ordinal());
			ItemStack skull = data.toItemStack(1);
			SkullMeta meta = (SkullMeta) skull.getItemMeta();
			meta.setDisplayName(getI18N().getVarString(Messages.Player.TRACKER_SKULL_TITLE)
					.setVariable("tracking", player.getDisplayName())
					.toString());
			meta.setOwner(player.getName());
			skull.setItemMeta(meta);
			
			slot.setItem(skull);
			slot.setValue(player);
			break;
		}
	}
	
	trackerInventory.updateViews();
}
 
Example 5
Source File: FlagLeaveItem.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
private void addLeaveItem(SpleefPlayer player) {
    MaterialData leaveItemData = config.getFlagSection().getLeaveItem();
    MetadatableItemStack stack = new MetadatableItemStack(leaveItemData.toItemStack(1));

    ItemMeta meta = stack.getItemMeta();
    meta.setDisplayName(getI18N().getString(Messages.Player.LEAVE_GAME_DISPLAYNAME));
    meta.setLore(Lists.newArrayList(getI18N().getString(Messages.Player.LEAVE_GAME_LORE)));
    stack.setItemMeta(meta);
    stack.setMetadata(LEAVE_ITEM_KEY, null);

    Player bukkitPlayer = player.getBukkitPlayer();
    bukkitPlayer.getInventory().setItem(RIGHT_HOTBAR_SLOT, stack);
    bukkitPlayer.updateInventory();
}
 
Example 6
Source File: CustomItem.java    From CS-CoreLib with GNU General Public License v3.0 4 votes vote down vote up
@Deprecated
public CustomItem(MaterialData data, int amount) {
	super(data.toItemStack(amount));
}
 
Example 7
Source File: ItemStackFlag.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ItemStack parseInput(SpleefPlayer player, String input) throws InputParseException {
	String components[] = splitWithQuotes(input, " ");

	if (components.length == 0) {
		throw new InputParseException("No value was given for this itemstack flag\n" + HELP_STRING);
	}

	int amount = 1;
	MaterialData data = parseMaterial(components[0]);

	if (components.length > 1) {
		try {
			amount = Integer.parseInt(components[1]);
		} catch (NumberFormatException e) {
			throw new InputParseException("Invalid amount '" + components[1] + "' given\n" + HELP_STRING);
		}
	}

	ItemStack stack = data.toItemStack(amount);
	if (components.length > 2) {
		String displayName = ChatColor.translateAlternateColorCodes(TRANSLATE_CHAR, components[2]);
		ItemMeta meta = stack.getItemMeta();
		
		meta.setDisplayName(displayName);
		
		if (components.length > 3) {
			List<String> lore = Lists.newArrayList();
			for (int i = 3; i < components.length; i++) {
				String loreLine = components[i];
				loreLine = ChatColor.translateAlternateColorCodes(TRANSLATE_CHAR, loreLine);
				
				lore.add(loreLine);
			}
			
			meta.setLore(lore);
		}
		
		stack.setItemMeta(meta);
	}
	
	return stack;
}