use of org.bukkit.inventory.Inventory in project Village_Defense by Plajer.
the class SpectatorItemEvents method openSpectatorMenu.
private void openSpectatorMenu(World world, Player p) {
Inventory inventory = plugin.getServer().createInventory(null, Util.serializeInt(ArenaRegistry.getArena(p).getPlayers().size()), ChatManager.colorMessage("In-Game.Spectator.Spectator-Menu-Name"));
for (Player player : world.getPlayers()) {
if (ArenaRegistry.getArena(player) != null && !UserManager.getUser(player.getUniqueId()).isFakeDead()) {
ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1);
SkullMeta meta = (SkullMeta) skull.getItemMeta();
meta.setOwner(player.getName());
meta.setDisplayName(player.getName());
meta.setLore(Collections.singletonList(ChatManager.colorMessage("In-Game.Spectator.Target-Player-Health").replaceAll("%health%", String.valueOf(Util.round(player.getHealth(), 2)))));
skull.setDurability((short) SkullType.PLAYER.ordinal());
skull.setItemMeta(meta);
inventory.addItem(skull);
}
}
p.openInventory(inventory);
}
use of org.bukkit.inventory.Inventory in project Village_Defense by Plajer.
the class InventoryManager method loadInventory.
public void loadInventory(Player player) {
File file = new File(plugin.getDataFolder() + File.separator + "inventorys" + File.separator + player.getUniqueId().toString() + ".invsave");
if (!file.exists() || file.isDirectory() || !file.getAbsolutePath().endsWith(".invsave"))
return;
try {
FileConfiguration invConfig = YamlConfiguration.loadConfiguration(file);
try {
ItemStack[] armor = new ItemStack[player.getInventory().getArmorContents().length];
for (int i = 0; i < player.getInventory().getArmorContents().length; i++) {
if (invConfig.contains("Armor " + i))
armor[i] = invConfig.getItemStack("Armor " + i);
else
armor[i] = new ItemStack(Material.AIR);
}
player.getInventory().setArmorContents(armor);
player.setMaxHealth(invConfig.getDouble("Max health"));
player.setHealth(invConfig.getDouble("Current health"));
player.setFoodLevel(invConfig.getInt("Food"));
player.setSaturation((float) invConfig.get("Saturation"));
player.setFireTicks(invConfig.getInt("Fire ticks"));
player.setGameMode(GameMode.valueOf(invConfig.getString("GameMode")));
player.setAllowFlight(invConfig.getBoolean("Allow flight"));
List<String> activePotions = invConfig.getStringList("Active potion effects");
for (String potion : activePotions) {
String[] splited = potion.split("#");
player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(splited[0]), Integer.valueOf(splited[1]), Integer.valueOf(splited[2])));
}
} catch (Exception ignored) {
}
} catch (Exception ignored) {
}
Inventory inventory = this.getInventoryFromFile(player.getUniqueId().toString());
for (Integer i = 0; i < inventory.getContents().length; i++) {
if (inventory.getItem(i) != null)
player.getInventory().setItem(i, inventory.getItem(i));
}
player.updateInventory();
player.setLevel(Integer.valueOf(inventory.getTitle()));
}
use of org.bukkit.inventory.Inventory in project Village_Defense by Plajer.
the class InventoryManager method getInventoryFromFile.
private Inventory getInventoryFromFile(String UUID) {
File file = new File(plugin.getDataFolder() + File.separator + "inventorys" + File.separator + UUID + ".invsave");
if (!file.exists() || file.isDirectory() || !file.getAbsolutePath().endsWith(".invsave"))
return null;
try {
FileConfiguration invConfig = YamlConfiguration.loadConfiguration(file);
Inventory inventory;
Integer invTitle = invConfig.getInt("Exp");
int invSize = invConfig.getInt("Size", 36);
int invMaxStackSize = invConfig.getInt("Max stack size", 64);
InventoryHolder invHolder = null;
if (invConfig.contains("Holder"))
invHolder = Bukkit.getPlayer(invConfig.getString("Holder"));
inventory = Bukkit.getServer().createInventory(invHolder, InventoryType.PLAYER, Integer.toString(invTitle));
inventory.setMaxStackSize(invMaxStackSize);
try {
ItemStack[] invContents = new ItemStack[invSize];
for (int i = 0; i < invSize; i++) {
if (invConfig.contains("Slot " + i))
invContents[i] = invConfig.getItemStack("Slot " + i);
else
invContents[i] = new ItemStack(Material.AIR);
}
inventory.setContents(invContents);
} catch (Exception ex) {
ex.printStackTrace();
BigTextUtils.errorOccured();
Bukkit.getConsoleSender().sendMessage("Cannot save inventory of player! Could not get armor!");
Bukkit.getConsoleSender().sendMessage("Disable inventory saving option in config.yml or restart the server!");
}
file.delete();
return inventory;
} catch (Exception ex) {
ex.printStackTrace();
BigTextUtils.errorOccured();
Bukkit.getConsoleSender().sendMessage("Cannot save inventory of player!");
Bukkit.getConsoleSender().sendMessage("Disable inventory saving option in config.yml or restart the server!");
return null;
}
}
use of org.bukkit.inventory.Inventory in project Village_Defense by Plajer.
the class TeleporterKit method openAndCreateTeleportationMenu.
private void openAndCreateTeleportationMenu(World world, Player p) {
Arena arena = ArenaRegistry.getArena(p);
Inventory inventory = plugin.getServer().createInventory(null, 18, ChatManager.colorMessage("Kits.Teleporter.Game-Item-Menu-Name"));
for (Player player : world.getPlayers()) {
if (ArenaRegistry.getArena(player) != null && !UserManager.getUser(player.getUniqueId()).isFakeDead()) {
ItemStack skull = new ItemStack(397, 1, (short) 3);
SkullMeta meta = (SkullMeta) skull.getItemMeta();
meta.setOwner(player.getName());
meta.setDisplayName(player.getName());
meta.setLore(Collections.singletonList(""));
skull.setItemMeta(meta);
inventory.addItem(skull);
}
}
for (Villager villager : arena.getVillagers()) {
ItemStack villagerItem = new ItemStack(Material.EMERALD);
this.setItemNameAndLore(villagerItem, villager.getCustomName(), new String[] { villager.getUniqueId().toString() });
inventory.addItem(villagerItem);
}
p.openInventory(inventory);
}
use of org.bukkit.inventory.Inventory in project TriggerReactor by wysohn.
the class InventoryTriggerManager method onClick.
@EventHandler(ignoreCancelled = true)
public void onClick(InventoryClickEvent e) {
Inventory inventory = e.getInventory();
if (!this.hasInventoryOpen(new BukkitInventory(inventory)))
return;
InventoryTrigger trigger = getTriggerForOpenInventory(new BukkitInventory(inventory));
// just always cancel if it's GUI
e.setCancelled(true);
if (!(e.getWhoClicked() instanceof Player))
return;
if (e.getRawSlot() < 0)
return;
Map<String, Object> varMap = getSharedVarsForInventory(new BukkitInventory(inventory));
if (e.getRawSlot() < trigger.getItems().length) {
if (trigger.getItems()[e.getRawSlot()] == null)
varMap.put("item", new ItemStack(Material.AIR));
else {
ItemStack item = trigger.getItems()[e.getRawSlot()].get();
varMap.put("item", item.clone());
}
}
varMap.put("slot", e.getRawSlot());
varMap.put("click", e.getClick().name());
varMap.put("hotbar", e.getHotbarButton());
varMap.put("trigger", "click");
trigger.activate(e, varMap);
}
Aggregations