本文整理汇总了Java中org.bukkit.inventory.PlayerInventory.setContents方法的典型用法代码示例。如果您正苦于以下问题:Java PlayerInventory.setContents方法的具体用法?Java PlayerInventory.setContents怎么用?Java PlayerInventory.setContents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.inventory.PlayerInventory
的用法示例。
在下文中一共展示了PlayerInventory.setContents方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setInventory
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
/**
* 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);
}
}
示例2: mockPlayer
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
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;
}
示例3: 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);
}
示例4: apply
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
default void apply(Backend backend, Player player, boolean health) {
PlayerInventory inventory = player.getInventory();
inventory.setContents(getContents());
inventory.setArmorContents(getArmor());
player.getActivePotionEffects().forEach(potionEffect -> player.removePotionEffect(potionEffect.getType()));
player.addPotionEffects(Arrays.asList(getPotionEffects()));
if (health) {
player.setHealthScaled(true);
player.setHealthScale(getHealthScale());
player.setMaxHealth(getMaxHealth());
player.setHealth(getHealth());
player.setFoodLevel(getFoodLevel());
player.setExhaustion(getExhaustion());
player.setSaturation(getSaturation());
player.setFireTicks(getFireTicks());
player.setTotalExperience(getTotalExperience());
player.setMaximumAir(getMaximumAir());
player.setRemainingAir(getRemainingAir());
}
backend.getProfileRegistry().fromPlayer(backend, player).setKit(backend, this);
}
示例5: loadInventory
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static void loadInventory(Player p){
UUID id = p.getUniqueId();
PlayerInventory inv = p.getInventory();
File invFile = HTConfigHandler.getInventoryFile(id);
if(!invFile.exists()){ Mes.mes(p, "chat.creationMode.inventory.restoreFail"); return; }
YamlConfiguration invConfig = YamlConfiguration.loadConfiguration(invFile);
List<ItemStack> inventoryItems = (List<ItemStack>) invConfig.getList("inventory");
inv.setContents(inventoryItems.toArray(new ItemStack[inventoryItems.size()]));
List<ItemStack> armourItems = (List<ItemStack>) invConfig.getList("armour");
inv.setArmorContents(armourItems.toArray(new ItemStack[armourItems.size()]));
try{
List<ItemStack> extraItems = (List<ItemStack>) invConfig.getList("extra");
inv.setExtraContents(extraItems.toArray(new ItemStack[extraItems.size()]));
}
catch(Exception et){ } //Must be in a pre-1.9 version
Mes.mes(p, "chat.creationMode.inventory.restoreSuccess");
invFile.delete();
}
示例6: 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);
}
}
示例7: restore
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
public void restore(Player p) {
PlayerInventory inv = p.getInventory();
inv.setContents(items);
inv.setArmorContents(armorItems);
p.setLevel(level);
p.setExp(exp);
p.updateInventory();
}
示例8: setFor
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
/**
* Set this kit for given player
*
* @param player The player
*/
public void setFor(Player player){
PlayerInventory inv = player.getInventory();
inv.setContents(getContents(content));
this.setArmor(player);
}
示例9: setToPlayer
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
public void setToPlayer(Player player) {
PlayerInventory inventory = player.getInventory();
ItemStack[] armor = ItemUtil.deserializeItemStacks(this.armor);
ItemStack[] items = ItemUtil.deserializeItemStacks(this.items);
inventory.setArmorContents(armor);
inventory.setContents(items);
}
示例10: applyKit
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
public void applyKit(Player player, boolean clearInv) {
if (player.hasPermission("kit." + name)) {
IPlayer iPlayer = IPlayerHandler.getPlayer(player);
long lastUse = iPlayer.getLastUse(world,this);
long timeSinceUse = (System.currentTimeMillis() - lastUse) / 1000;
System.out.println("Last use of " + name + " for " + player.getName() + " was " + lastUse / 1000 + " and the current time is " + System.currentTimeMillis() / 1000);
if (timeSinceUse >= cooldown || player.hasPermission("kit.bypass_cooldown")) {
if (clearInv) {
PlayerInventory inv = player.getInventory();
inv.setContents(contents);
inv.setArmorContents(armor);
for (PotionEffect effect : player.getActivePotionEffects()) {
player.removePotionEffect(effect.getType());
}
} else {
for(ItemStack item : contents){
if(item != null){
Util.giveItem(player, item);
}
}
}
for (PotionEffect pE : effects) {
player.addPotionEffect(pE);
}
iPlayer.gotKit = true;
iPlayer.setLastUse(world,this, System.currentTimeMillis());
iPlayer.setGhost(false);
if (name.equals("ghost")) {
iPlayer.setGhost(true);
}
} else {
String nextUseTime = Util.formatTime(lastUse + (cooldown * 1000) - System.currentTimeMillis());
player.sendMessage(ChatColor.RED + "You can use that kit again in " + ChatColor.AQUA + nextUseTime);
KitManager.openGUI(player);
IPlayerHandler.getPlayer(player).setGhost(false);
}
} else {
player.sendMessage(ChatColor.RED + "You don't have access to that kit. You can purchase access to this and other kits at " + ChatColor.AQUA + " store.izenith.net");
KitManager.openGUI(player);
IPlayerHandler.getPlayer(player).setGhost(false);
}
}
示例11: clean
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
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();
}
示例12: applyItems
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
default void applyItems(Player player) {
PlayerInventory inventory = player.getInventory();
inventory.setContents(getContents());
inventory.setArmorContents(getArmor());
}