use of simple.brainsynder.storage.StorageList in project SimplePets by brainsynder-Dev.
the class SelectionMenu method open.
@Override
public void open(PetOwner owner, int page) {
if (!isEnabled())
return;
Player player = Bukkit.getPlayer(owner.getUuid());
pageSave.put(player.getName(), page);
Inventory inv = Bukkit.createInventory(new SelectionHolder(), getSize(), getTitle());
int placeHolder = inv.getSize();
int maxPets = 0;
while (placeHolder > 0) {
int slot = (placeHolder - 1);
if (getSlots().containsKey(slot)) {
Item item = getSlots().get(slot);
if (item instanceof Air) {
maxPets++;
} else {
inv.setItem(placeHolder - 1, PetCore.get().getItemLoaders().PLACEHOLDER.getItemBuilder().build());
}
} else {
inv.setItem(placeHolder - 1, PetCore.get().getItemLoaders().PLACEHOLDER.getItemBuilder().build());
}
placeHolder--;
}
boolean removeNoPerms = PetCore.get().getConfiguration().getBoolean("Remove-Item-If-No-Permission");
IStorage<PetTypeStorage> petTypes = new StorageList<>();
for (PetDefault type : availableTypes) {
if (type.hasPermission(player)) {
petTypes.add(new PetTypeStorage(type));
} else {
if (!removeNoPerms)
petTypes.add(new PetTypeStorage(type));
}
}
if ((petTypes.getSize() == 0) && (PetCore.get().getConfiguration().getBoolean("Needs-Pet-Permission-To-Open-GUI"))) {
player.sendMessage(PetCore.get().getMessages().getString("No-Permission"));
return;
}
ObjectPager<PetTypeStorage> pages = new ObjectPager<>(maxPets, petTypes.toArrayList());
pagerMap.put(player.getName(), pages);
getSlots().forEach((slot, item) -> {
if (item.isEnabled() && item.addItemToInv(owner, this))
inv.setItem(slot, item.getItemBuilder().build());
});
PetInventoryOpenEvent event = new PetInventoryOpenEvent(pages.getPage(page), player);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled())
return;
IStorage<ItemStack> types = event.getItems().copy();
while (types.hasNext()) {
inv.addItem(types.next());
}
petMap.put(player.getName(), event.getShownPetTypes());
player.openInventory(inv);
}
use of simple.brainsynder.storage.StorageList in project SimplePets by brainsynder-Dev.
the class PetEventListeners method openMenuSelector.
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void openMenuSelector(PetInventoryOpenEvent event) {
if (!PetCore.get().getConfiguration().getBoolean("UseVaultEconomy"))
return;
IStorage<ItemStack> items = new StorageList<>();
IStorage<PetTypeStorage> types = event.getShownPetTypes().copy();
PetOwner petOwner = PetOwner.getPetOwner(event.getPlayer());
JSONArray petArray = petOwner.getOwnedPets();
List<String> lore = economyFile.getStringList((economyFile.getBoolean("Pay-Per-Use.Enabled") ? "Pay-Per-Use.Lore-Lines" : "Lore-Lines"));
while (types.hasNext()) {
PetTypeStorage storage = types.next();
PetDefault type = storage.getType();
ItemBuilder maker = ItemBuilder.fromJSON(storage.getType().getItemBuilder().toJSON());
String price = String.valueOf(economyFile.getPrice(type));
if (price.equals("-1"))
price = economyFile.getString("Price-Free");
try {
if (price.isEmpty()) {
PetCore.get().debug("Price is empty for: 'Pet." + type.getConfigName() + ".Price'");
items.add(maker.build());
continue;
}
Double.parseDouble(price);
} catch (Exception e) {
PetCore.get().debug("Price is invalid for: 'Pet." + type.getConfigName() + ".Price'");
items.add(maker.build());
continue;
}
if (economyFile.getBoolean("Bypass.Hide-Price-If-Bypassed") && event.getPlayer().hasPermission("Pet.economy.bypass"))
price = economyFile.getString("Bypass.Price");
boolean contains = petArray.contains(type.getConfigName());
for (String line : lore) maker.addLore(line.replace("%cost%", price).replace("%contains%", String.valueOf(contains)));
items.add(maker.build());
storage.setItem(maker);
}
event.setItems(items);
}
Aggregations