本文整理汇总了Java中org.bukkit.inventory.PlayerInventory.clear方法的典型用法代码示例。如果您正苦于以下问题:Java PlayerInventory.clear方法的具体用法?Java PlayerInventory.clear怎么用?Java PlayerInventory.clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.inventory.PlayerInventory
的用法示例。
在下文中一共展示了PlayerInventory.clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onInteract
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
@EventHandler
public void onInteract(PlayerInteractEvent e) {
Player p = e.getPlayer();
PlayerInventory i = p.getInventory();
if(i.getItemInMainHand().equals(PlayerJoinList.JOIN_ITEM) && (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)){
DrawSystem.addUser(UserManager.getUser(p));
i.clear();
// TODO ?
return;
}
String turretName = TurretManager.getNearestTurretName(e.getPlayer());
Turret turret = TurretManager.getTurretByName(turretName);
if(turret == null) {
return;
}
if(e.getAction() == Action.LEFT_CLICK_BLOCK) {
if (e.getClickedBlock().getType() != Material.GRASS) {
Bukkit.getPluginManager().callEvent(new PlayerAttackTurretEvent(turret, e.getPlayer(), e.getClickedBlock()));
}
}
}
示例2: clearKit
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
public static void clearKit(Player player) {
PlayerInventory inv = player.getInventory();
inv.clear();
inv.setArmorContents(new ItemStack[4]);
for (PotionEffect effect : player.getActivePotionEffects()) {
player.removePotionEffect(effect.getType());
}
IPlayer iPlayer = IPlayerHandler.getPlayer(player);
if (iPlayer.isGhost()) {
iPlayer.setGhost(false);
iPlayer.setTeam();
}
iPlayer.gotKit = false;
}
示例3: onJoin
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
@EventHandler
public void onJoin(PlayerJoinEvent e){
Player p = e.getPlayer();
p.setHealth(p.getMaxHealth());
p.setFoodLevel(20); //TODO
PlayerInventory i = p.getInventory();
i.clear();
i.setHeldItemSlot(4);
i.setItem(4, JOIN_ITEM);
User u = new User(p);
UserManager.addUser(u);
u.setChampion(ChampType.YASUO);
u.setTeam(TeamType.NONE);
TabTitle tab = new TabTitle("�2Witaj na serwerze \n Grzybie", "�5League Of Legends!");
Title title = new Title("�6�lWitamy", "�a�lXD Prodaksh�n", 10, 10, 30);
bar.addPlayer(p);
tab.send(p);
title.send(p);
runTask(ScoreBoard.get(p)); //test
ProfileLoader profile = new ProfileLoader(p.getUniqueId().toString(), p.getName(), "skkf");
profile.loadProfile();
}
示例4: pushInventory
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
/**
* Pushes the inventory of the given player into persistent storage.
*
* @param player The {@link Player} to push the inventory of
* @throws IOException If an exception occurs while saving into persistent
* storage
*/
@SuppressWarnings("deprecation")
public static void pushInventory(Player player) throws IOException {
PlayerInventory inv = player.getInventory();
// the file to store the inventory in
File storage = new File(SteelDataFiles.PLAYER_INVENTORY_DIR.getFile(), player.getUniqueId() + ".yml");
if (storage.exists()) { // verify file isn't already present on disk (meaning it wasn't popped the last time)
SteelCore.logVerbose("Inventory push requested for player " + player.getName() + ", but "
+ "inventory was already present in persistent storage. Popping stored inventory first.");
try {
popInventory(player);
} catch (InvalidConfigurationException ex) {
throw new IOException(ex); // this is probably a bad thing of me to do but it's for a fringe case anyway
}
}
YamlConfiguration yaml = new YamlConfiguration();
yaml.set(PLAYER_INVENTORY_PRIMARY_KEY, InventoryHelper.serializeInventory(inv));
yaml.set(PLAYER_INVENTORY_ARMOR_KEY, InventoryHelper.serializeInventory(inv.getArmorContents()));
yaml.save(storage); // save to disk
inv.clear(); // clear the inventory to complete the push to disk
inv.setArmorContents(new ItemStack[inv.getArmorContents().length]);
player.updateInventory();
}
示例5: 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);
}
}
示例6: clearInventory
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
public void clearInventory(Player p) {
PlayerInventory inv = p.getInventory();
inv.clear();
inv.setHelmet(null);
inv.setChestplate(null);
inv.setLeggings(null);
inv.setBoots(null);
InventoryView view = p.getOpenInventory();
if (view != null) {
view.setCursor(null);
Inventory i = view.getTopInventory();
if (i != null) {
i.clear();
}
}
}
示例7: 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));
}
示例8: clearInventory
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
public void clearInventory(boolean armor) {
PlayerInventory inventory = this.getBukkit().getInventory();
inventory.clear();
if (armor) {
inventory.setHelmet(null);
inventory.setChestplate(null);
inventory.setLeggings(null);
inventory.setBoots(null);
}
}
示例9: clearInventory
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
public void clearInventory()
{
Player player = getPlayer();
PlayerInventory pi = player.getInventory();
pi.clear();
pi.setArmorContents(new ItemStack[] { null, null, null, null });
}
示例10: loadInventory
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
private void loadInventory(PlayerInventory inv) {
inv.clear();
inv.setArmorContents(new ItemStack[] {null, null, null, null});
if(!this.database.contains(this.key + ".inventory")) {
return;
}
Map<String, Object> inventory = null;
try {
BukkitObjectInputStream in = new BukkitObjectInputStream(new ByteArrayInputStream(this.database.getBytes(this.key + ".inventory")));
inventory = (Map<String, Object>) in.readObject();
} catch(Exception e) {
this.module.getLogger().log(Level.SEVERE, "Failed to load inventory.", e);
return;
}
for(int slot = 0; slot < inv.getSize(); slot++) {
if(inventory.containsKey(String.valueOf(slot))) {
inv.setItem(slot, ItemStack.deserialize((Map<String, Object>) inventory.get(String.valueOf(slot))));
} else {
inv.setItem(slot, null);
}
}
if(inventory.containsKey("helmet")) {
inv.setHelmet(ItemStack.deserialize((Map<String, Object>) inventory.get(String.valueOf("helmet"))));
}
if(inventory.containsKey("chestplate")) {
inv.setChestplate(ItemStack.deserialize((Map<String, Object>) inventory.get(String.valueOf("chestplate"))));
}
if(inventory.containsKey("leggings")) {
inv.setLeggings(ItemStack.deserialize((Map<String, Object>) inventory.get(String.valueOf("leggings"))));
}
if(inventory.containsKey("boots")) {
inv.setBoots(ItemStack.deserialize((Map<String, Object>) inventory.get(String.valueOf("boots"))));
}
}
示例11: setPlayerInventory
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 static void setPlayerInventory(Player player, JSONObject inv, int format) {
try {
PlayerInventory inventory = player.getInventory();
ItemStack[] armor = getInventory(inv.getJSONArray("armor"), 4, format);
inventory.clear();
inventory.setArmorContents(armor);
setInventory(player, inv.getJSONArray("inventory"), format);
} catch (JSONException e) {
e.printStackTrace();
}
}
示例12: start
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
public void start() {
playing = true;
starting = true;
Title title = new Title("Tout le monde est prêt ?");
title.setTitleColor(ChatColor.DARK_AQUA);
title.setSubtitle("On ne bouge plus !");
title.setSubtitleColor(ChatColor.AQUA);
title.setFadeInTime(9);
title.setStayTime(20);
title.setFadeOutTime(9);
title.setTimingsToTicks();
title.broadcast();
RftdLogger.log(Level.INFO, "Starting game...");
RftdHelper.setDifficulty(Difficulty.HARD);
RftdHelper.canEveryoneWalk(false);
RftdHelper.setEveryoneGameMode(GameMode.ADVENTURE);
RftdHelper.setAnimalSpawnLimit(50);
Collection<? extends Player> players = Bukkit.getOnlinePlayers();
for(Player player : players) {
PlayerInventory inventory = player.getInventory();
inventory.clear();
inventory.setHelmet(null);
inventory.setChestplate(null);
inventory.setLeggings(null);
inventory.setBoots(null);
ItemStack endereyes = new ItemStack(Material.EYE_OF_ENDER, getEyeOfEnderQty());
inventory.setItem(4, endereyes);
}
task = Bukkit.getScheduler().runTaskTimer(plugin, new StartTimer(), 40, 20);
}
示例13: saveState
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
/**
* Saves the current state of a player.
*
* @param p The {@link Player} to save the state of
*/
public void saveState(Player p) {
PlayerInventory i = p.getInventory();
states.put(p.getUniqueId(), new PlayerState(p));
i.clear();
i.setArmorContents(new ItemStack[4]);
}
示例14: remove
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
public static void remove(String playerName, int amount, ItemStack compareItem){
Player player = Bukkit.getPlayer(playerName);
if (player != null) {
PlayerInventory inventory = player.getInventory();
// Remove held item first:
if (isSameItem(compareItem, player.getItemInHand())) {
int heldAmount = player.getItemInHand().getAmount();
if (heldAmount <= amount) {
amount -= heldAmount;
inventory.clear(inventory.getHeldItemSlot());
} else {
player.getItemInHand().setAmount(heldAmount - amount);
amount = 0;
}
}
int counter = amount;
int leftover = 0;
// Remove from other stacks:
for (int invIndex = 0; invIndex < inventory.getSize(); invIndex++) {
ItemStack current = inventory.getItem(invIndex);
if (current == null || current.getAmount() <= 0)
continue;
if (!isSameItem(compareItem, current))
continue;
if (current.getAmount() > counter) {
leftover = current.getAmount() - counter;
}
if (leftover != 0) {
current.setAmount(leftover);
counter = 0;
break;
} else {
counter -= current.getAmount();
inventory.clear(invIndex);
}
}
}
}
示例15: clearInventory
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
public static void clearInventory(PlayerInventory pi)
{
pi.clear();
pi.setArmorContents(new ItemStack[] { null, null, null, null });
}