use of org.bukkit.inventory.Inventory in project askyblock by tastybento.
the class BiomesPanel method getBiomePanel.
/**
* Returns a customized panel of available Biomes for the player
*
* @param player
* @return custom Inventory object
*/
public Inventory getBiomePanel(Player player) {
// Go through the available biomes and check permission
int slot = 0;
List<BiomeItem> items = new ArrayList<BiomeItem>();
for (String biomeName : plugin.getConfig().getConfigurationSection("biomes").getKeys(false)) {
// Check the biome is actually real
try {
Biome biome = Biome.valueOf(biomeName);
// Check permission
String permission = plugin.getConfig().getString("biomes." + biomeName + ".permission", "");
if (permission.isEmpty() || VaultHelper.permission.has(player, permission)) {
// Build inventory item
// Get icon
String icon = plugin.getConfig().getString("biomes." + biomeName + ".icon", "SAPLING");
Material material = null;
try {
if (StringUtils.isNumeric(icon)) {
material = Material.getMaterial(Integer.parseInt(icon));
} else {
material = Material.valueOf(icon.toUpperCase());
}
} catch (Exception e) {
plugin.getLogger().warning("Error parsing biome icon value " + icon + ". Using default SAPLING.");
material = Material.SAPLING;
}
// Get cost
double cost = plugin.getConfig().getDouble("biomes." + biomeName + ".cost", Settings.biomeCost);
// Get friendly name
String name = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("biomes." + biomeName + ".friendlyname", Util.prettifyText(biomeName)));
// Get description
String description = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("biomes." + biomeName + ".description", ""));
// Get confirmation or not
boolean confirm = plugin.getConfig().getBoolean("biomes." + biomeName + ".confirm", false);
// Add item to list
// plugin.getLogger().info("DEBUG: " + description + name +
// confirm);
BiomeItem item = new BiomeItem(material, slot++, cost, description, name, confirm, biome);
// Add to item list
items.add(item);
}
} catch (Exception e) {
e.printStackTrace();
plugin.getLogger().severe("Could not recognize " + biomeName + " as valid Biome! Skipping...");
plugin.getLogger().severe("For V1.9, some biome names do not exist anymore. Change config.yml to the latest.");
}
}
// Now create the inventory panel
if (items.size() > 0) {
// Save the items for later retrieval when the player clicks on them
biomeItems.put(player.getUniqueId(), items);
// Make sure size is a multiple of 9
int size = items.size() + 8;
size -= (size % 9);
Inventory newPanel = Bukkit.createInventory(null, size, plugin.myLocale().biomePanelTitle);
// Fill the inventory and return
for (BiomeItem i : items) {
newPanel.addItem(i.getItem());
}
return newPanel;
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorCommandNotReady);
plugin.getLogger().warning("There are no biomes in config.yml so /island biomes will not work!");
}
return null;
}
use of org.bukkit.inventory.Inventory in project askyblock by tastybento.
the class WarpPanel method onInventoryClick.
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
// The inventory that was clicked in
Inventory inventory = event.getInventory();
if (inventory.getName() == null) {
return;
}
// The player that clicked the item
final Player player = (Player) event.getWhoClicked();
String title = inventory.getTitle();
if (!inventory.getTitle().startsWith(plugin.myLocale().warpsTitle + " #")) {
return;
}
event.setCancelled(true);
if (event.getSlotType().equals(SlotType.OUTSIDE)) {
player.closeInventory();
return;
}
if (event.getClick().equals(ClickType.SHIFT_RIGHT)) {
player.closeInventory();
player.updateInventory();
return;
}
// The item that was clicked
ItemStack clicked = event.getCurrentItem();
if (DEBUG)
plugin.getLogger().info("DEBUG: inventory size = " + inventory.getSize());
if (DEBUG)
plugin.getLogger().info("DEBUG: clicked = " + clicked);
if (DEBUG)
plugin.getLogger().info("DEBUG: rawslot = " + event.getRawSlot());
if (event.getRawSlot() >= event.getInventory().getSize() || clicked.getType() == Material.AIR) {
return;
}
int panelNumber = 0;
try {
panelNumber = Integer.valueOf(title.substring(title.indexOf('#') + 1));
} catch (Exception e) {
panelNumber = 0;
}
if (clicked.getItemMeta().hasDisplayName()) {
String command = ChatColor.stripColor(clicked.getItemMeta().getDisplayName());
if (DEBUG)
plugin.getLogger().info("DEBUG: command = " + command);
if (command != null) {
if (command.equalsIgnoreCase(ChatColor.stripColor(plugin.myLocale().warpsNext))) {
player.closeInventory();
Util.runCommand(player, Settings.ISLANDCOMMAND + " warps " + (panelNumber + 1));
} else if (command.equalsIgnoreCase(ChatColor.stripColor(plugin.myLocale().warpsPrevious))) {
player.closeInventory();
Util.runCommand(player, Settings.ISLANDCOMMAND + " warps " + (panelNumber - 1));
} else {
player.closeInventory();
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).warpswarpToPlayersSign.replace("<player>", command));
Util.runCommand(player, Settings.ISLANDCOMMAND + " warp " + command);
}
}
}
}
use of org.bukkit.inventory.Inventory in project TriggerReactor by wysohn.
the class JavaPluginBridge method createInterrupterForInv.
@Override
public ProcessInterrupter createInterrupterForInv(Object e, Interpreter interpreter, Map<UUID, Long> cooldowns, Map<IInventory, InventoryTrigger> inventoryMap) {
return new ProcessInterrupter() {
@Override
public boolean onNodeProcess(Node node) {
if (interpreter.isCooldown()) {
if (e instanceof InventoryInteractEvent) {
HumanEntity he = ((InventoryInteractEvent) e).getWhoClicked();
if (he instanceof Player) {
Player player = (Player) he;
UUID uuid = player.getUniqueId();
cooldowns.put(uuid, interpreter.getCooldownEnd());
}
}
return false;
}
// is still running after the inventory is closed.
if (e instanceof InventoryOpenEvent || e instanceof InventoryClickEvent) {
Inventory inv = ((InventoryEvent) e).getInventory();
// it's not GUI so stop execution
if (!inventoryMap.containsKey(new BukkitInventory(inv)))
return true;
}
return false;
}
@Override
public boolean onCommand(Object context, String command, Object[] args) {
if ("CALL".equals(command)) {
if (args.length < 1)
throw new RuntimeException("Need parameter [String] or [String, boolean]");
if (args[0] instanceof String) {
Trigger trigger = getNamedTriggerManager().getTriggerForName((String) args[0]);
if (trigger == null)
throw new RuntimeException("No trigger found for Named Trigger " + args[0]);
if (args.length > 1 && args[1] instanceof Boolean) {
trigger.setSync((boolean) args[1]);
} else {
trigger.setSync(true);
}
if (trigger.isSync()) {
trigger.activate(e, interpreter.getVars());
} else {
// use snapshot to avoid concurrent modification
trigger.activate(e, new HashMap<>(interpreter.getVars()));
}
return true;
} else {
throw new RuntimeException("Parameter type not match; it should be a String." + " Make sure to put double quotes, if you provided String literal.");
}
} else if ("CANCELEVENT".equals(command)) {
if (!interpreter.isSync())
throw new RuntimeException("CANCELEVENT is illegal in async mode!");
if (context instanceof Cancellable) {
((Cancellable) context).setCancelled(true);
return true;
} else {
throw new RuntimeException(context + " is not a Cancellable event!");
}
}
return false;
}
};
}
use of org.bukkit.inventory.Inventory in project TriggerReactor by wysohn.
the class BukkitPlayer method openInventory.
@Override
public void openInventory(IInventory inventory) {
Inventory inv = inventory.get();
player.openInventory(inv);
}
use of org.bukkit.inventory.Inventory in project askyblock by tastybento.
the class TopTen method onInventoryClick.
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
// The inventory that was clicked in
Inventory inventory = event.getInventory();
if (inventory.getName() == null) {
return;
}
// The player that clicked the item
Player player = (Player) event.getWhoClicked();
if (!inventory.getTitle().equals(plugin.myLocale(player.getUniqueId()).topTenGuiTitle)) {
return;
}
event.setCancelled(true);
player.updateInventory();
if (event.getCurrentItem() != null && event.getCurrentItem().getType().equals(Material.SKULL_ITEM) && event.getCurrentItem().hasItemMeta()) {
if (((SkullMeta) event.getCurrentItem().getItemMeta()).hasOwner()) {
Util.runCommand(player, "is warp " + ((SkullMeta) event.getCurrentItem().getItemMeta()).getOwner());
player.closeInventory();
}
return;
}
if (event.getSlotType().equals(SlotType.OUTSIDE)) {
player.closeInventory();
return;
}
if (event.getClick().equals(ClickType.SHIFT_RIGHT)) {
player.closeInventory();
return;
}
}
Aggregations