Java Code Examples for org.bukkit.inventory.PlayerInventory#setArmorContents()
The following examples show how to use
org.bukkit.inventory.PlayerInventory#setArmorContents() .
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: InventorySerializer.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
/** * Sets the Inventory using an ItemStack array constructed from a JsonObject. * * @param player The InventoryHolder to which the Inventory will be set * @param inv The reference JsonArray * @param format Data format being used; 0 is old, 1 is new */ public void setInventory(Player player, JsonObject inv, int format) { PlayerInventory inventory = player.getInventory(); ItemStack[] armor = deserializeInventory(inv.getAsJsonArray("armor"), 4, format); ItemStack[] inventoryContents = deserializeInventory(inv.getAsJsonArray("inventory"), inventory.getSize(), format); inventory.clear(); if (armor != null) { inventory.setArmorContents(armor); } if (inventoryContents != null) { inventory.setContents(inventoryContents); } }
Example 2
Source File: PWIPlayerManagerTest.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
private Player mockPlayer(String name, GameMode gameMode) { Player mock = mock(Player.class); PlayerInventory inv = mock(PlayerInventory.class); inv.setContents(new ItemStack[39]); inv.setArmorContents(new ItemStack[4]); Inventory enderChest = mock(Inventory.class); enderChest.setContents(new ItemStack[27]); given(mock.getInventory()).willReturn(inv); given(mock.getEnderChest()).willReturn(enderChest); given(mock.getName()).willReturn(name); given(mock.getUniqueId()).willReturn(TestHelper.TEST_UUID); given(mock.getGameMode()).willReturn(gameMode); AttributeInstance attribute = mock(AttributeInstance.class); given(mock.getAttribute(Attribute.GENERIC_MAX_HEALTH)).willReturn(attribute); given(attribute.getBaseValue()).willReturn(20.0); return mock; }
Example 3
Source File: ClearInventoryAction.java From UHC with MIT License | 6 votes |
@Override protected void run(Player player) { final PlayerInventory inv = player.getInventory(); // clear main inventory contents = inv.getContents(); inv.clear(); // clear armour slots armourContents = inv.getArmorContents(); inv.setArmorContents(null); // clear if they have something on their cursour currently onCursor = player.getItemOnCursor(); player.setItemOnCursor(new ItemStack(Material.AIR)); // if they have a crafting inventory open clear items from it too // stops storing items in crafting slots bypassing clear inventories final InventoryView openInventory = player.getOpenInventory(); if (openInventory.getType() == InventoryType.CRAFTING) { crafting = Optional.of(openInventory.getTopInventory().getContents()); openInventory.getTopInventory().clear(); } else { crafting = Optional.absent(); } }
Example 4
Source File: InventorySerializer.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
/** * Sets the Inventory using an ItemStack array constructed from a JsonObject. * * @param player The InventoryHolder to which the Inventory will be set * @param inv The reference JsonArray * @param format Data format being used; 0 is old, 1 is new */ public void setInventory(Player player, JsonObject inv, int format) { PlayerInventory inventory = player.getInventory(); ItemStack[] armor = deserializeInventory(inv.getAsJsonArray("armor"), 4, format); ItemStack[] inventoryContents = deserializeInventory(inv.getAsJsonArray("inventory"), inventory.getSize(), format); inventory.clear(); if (armor != null) { inventory.setArmorContents(armor); } if (inventoryContents != null) { inventory.setContents(inventoryContents); } }
Example 5
Source File: PWIPlayerManagerTest.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
private Player mockPlayer(String name, GameMode gameMode) { Player mock = mock(Player.class); PlayerInventory inv = mock(PlayerInventory.class); inv.setContents(new ItemStack[39]); inv.setArmorContents(new ItemStack[4]); Inventory enderChest = mock(Inventory.class); enderChest.setContents(new ItemStack[27]); given(mock.getInventory()).willReturn(inv); given(mock.getEnderChest()).willReturn(enderChest); given(mock.getName()).willReturn(name); given(mock.getUniqueId()).willReturn(TestHelper.TEST_UUID); given(mock.getGameMode()).willReturn(gameMode); AttributeInstance attribute = mock(AttributeInstance.class); given(mock.getAttribute(Attribute.GENERIC_MAX_HEALTH)).willReturn(attribute); given(attribute.getBaseValue()).willReturn(20.0); return mock; }
Example 6
Source File: GamePlayer.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
public void clean() { PlayerInventory inv = this.player.getInventory(); inv.setArmorContents(new ItemStack[4]); inv.setContents(new ItemStack[]{}); this.player.setAllowFlight(false); this.player.setFlying(false); this.player.setExp(0.0F); this.player.setLevel(0); this.player.setSneaking(false); this.player.setSprinting(false); this.player.setFoodLevel(20); this.player.setSaturation(10); this.player.setExhaustion(0); this.player.setMaxHealth(20D); this.player.setHealth(this.player.getMaxHealth()); this.player.setFireTicks(0); this.player.setGameMode(GameMode.SURVIVAL); if (this.player.isInsideVehicle()) { this.player.leaveVehicle(); } for (PotionEffect e : this.player.getActivePotionEffects()) { this.player.removePotionEffect(e.getType()); } this.player.updateInventory(); }
Example 7
Source File: ScoreMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
private double redeemItems(ScoreBox box, PlayerInventory inventory) { ItemStack[] notArmor = inventory.getContents(); ItemStack[] armor = inventory.getArmorContents(); double points = redeemItems(box, notArmor) + redeemItems(box, armor); if (points != 0) { inventory.setContents(notArmor); inventory.setArmorContents(armor); } return points; }
Example 8
Source File: GamePlayer.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
public void clean() { PlayerInventory inv = this.player.getInventory(); inv.setArmorContents(new ItemStack[4]); inv.setContents(new ItemStack[]{}); this.player.setAllowFlight(false); this.player.setFlying(false); this.player.setExp(0.0F); this.player.setLevel(0); this.player.setSneaking(false); this.player.setSprinting(false); this.player.setFoodLevel(20); this.player.setSaturation(10); this.player.setExhaustion(0); this.player.setMaxHealth(20D); this.player.setHealth(this.player.getMaxHealth()); this.player.setFireTicks(0); this.player.setGameMode(GameMode.SURVIVAL); if (this.player.isInsideVehicle()) { this.player.leaveVehicle(); } for (PotionEffect e : this.player.getActivePotionEffects()) { this.player.removePotionEffect(e.getType()); } this.player.updateInventory(); }
Example 9
Source File: ClearInventoryAction.java From UHC with MIT License | 5 votes |
@Override protected void revert(Player player) { final PlayerInventory inv = player.getInventory(); inv.setContents(contents); inv.setArmorContents(armourContents); player.setItemOnCursor(onCursor); if (crafting.isPresent()) { // add back to main inventory instead of the crafting slots inv.addItem(crafting.get()); } }
Example 10
Source File: PlayerStorage.java From BedwarsRel with GNU General Public License v3.0 | 4 votes |
public void clean() { PlayerInventory inv = this.player.getInventory(); inv.setArmorContents(new ItemStack[4]); inv.setContents(new ItemStack[]{}); this.player.setAllowFlight(false); this.player.setFlying(false); this.player.setExp(0.0F); this.player.setLevel(0); this.player.setSneaking(false); this.player.setSprinting(false); this.player.setFoodLevel(20); this.player.setSaturation(10); this.player.setExhaustion(0); this.player.setMaxHealth(20.0D); this.player.setHealth(20.0D); this.player.setFireTicks(0); boolean teamnameOnTab = BedwarsRel.getInstance().getBooleanConfig("teamname-on-tab", true); boolean overwriteNames = BedwarsRel.getInstance().getBooleanConfig("overwrite-names", false); String displayName = this.player.getDisplayName(); String playerListName = this.player.getPlayerListName(); if (overwriteNames || teamnameOnTab) { Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(this.player); if (game != null) { game.setPlayerGameMode(player); Team team = game.getPlayerTeam(this.player); if (overwriteNames) { if (team != null) { displayName = team.getChatColor() + ChatColor.stripColor(this.player.getName()); } else { displayName = ChatColor.stripColor(this.player.getName()); } } if (teamnameOnTab) { if (team != null) { playerListName = team.getChatColor() + team.getName() + ChatColor.WHITE + " | " + team.getChatColor() + ChatColor.stripColor(this.player.getDisplayName()); } else { playerListName = ChatColor.stripColor(this.player.getDisplayName()); } } BedwarsPlayerSetNameEvent playerSetNameEvent = new BedwarsPlayerSetNameEvent(team, displayName, playerListName, player); BedwarsRel.getInstance().getServer().getPluginManager().callEvent(playerSetNameEvent); if (!playerSetNameEvent.isCancelled()) { this.player.setDisplayName(playerSetNameEvent.getDisplayName()); this.player.setPlayerListName(playerSetNameEvent.getPlayerListName()); } } } if (this.player.isInsideVehicle()) { this.player.leaveVehicle(); } for (PotionEffect e : this.player.getActivePotionEffects()) { this.player.removePotionEffect(e.getType()); } this.player.updateInventory(); }
Example 11
Source File: PlayerStateHolder.java From HeavySpleef with GNU General Public License v3.0 | 4 votes |
public void apply(Player player, boolean teleport) { PlayerInventory playerInv = player.getInventory(); boolean is1_9 = MinecraftVersion.getImplementationVersion().compareTo(MinecraftVersion.V1_9) >= 0; boolean isSimpleSize = playerInv.getContents().length <= SIMPLE_INVENTORY_SIZE; ItemStack[] inventoryContents = new ItemStack[is1_9 && !isSimpleSize ? playerInv.getSize() : SIMPLE_INVENTORY_SIZE]; System.arraycopy(inventory, 0, inventoryContents, 0, inventoryContents.length); if (!is1_9 || isSimpleSize) { ItemStack[] armorContents = new ItemStack[ARMOR_INVENTORY_SIZE]; System.arraycopy(inventory, inventory.length - ARMOR_INVENTORY_SIZE, armorContents, 0, armorContents.length); playerInv.setArmorContents(armorContents); } playerInv.setContents(inventoryContents); player.setItemOnCursor(null); Map<Integer, ItemStack> exceeded = playerInv.addItem(onCursor); for (ItemStack stack : exceeded.values()) { if (stack.getType() == Material.AIR) { continue; } player.getWorld().dropItem(player.getLocation(), stack); } player.updateInventory(); player.setMaxHealth(maxHealth); player.setHealth(health); player.setFoodLevel(foodLevel); player.setLevel(level); player.setExp(experience); player.setAllowFlight(allowFlight); player.setFlying(isFlying); /* Remove current potion effects */ Collection<PotionEffect> effects = player.getActivePotionEffects(); for (PotionEffect effect : effects) { player.removePotionEffect(effect.getType()); } player.addPotionEffects(activeEffects); player.setExhaustion(exhaustion); player.setSaturation(saturation); player.setFallDistance(fallDistance); player.setFireTicks(fireTicks); if (scoreboard != player.getScoreboard()) { Scoreboard showBoard = scoreboard; if (scoreboard == null) { showBoard = Bukkit.getScoreboardManager().getMainScoreboard(); } player.setScoreboard(showBoard); } if (teleport) { player.teleport(location); } Location compassTarget = this.compassTarget; if (compassTarget == null) { compassTarget = player.getWorld().getSpawnLocation(); } player.setCompassTarget(compassTarget); for (WeakReference<Player> ref : cantSee) { Player cantSeePlayer = ref.get(); if (cantSeePlayer == null) { // Player object has been garbage-collected continue; } if (!cantSeePlayer.isOnline()) { continue; } player.hidePlayer(cantSeePlayer); } player.setGameMode(gamemode); }