use of fr.minuskube.inv.content.InventoryContents in project WereWolfPlugin by Ph1Lou.
the class RandomEvents method update.
@Override
public void update(Player player, InventoryContents contents) {
Main main = JavaPlugin.getPlugin(Main.class);
GameManager game = (GameManager) main.getWereWolfAPI();
IConfiguration config = game.getConfig();
Pagination pagination = contents.pagination();
List<ClickableItem> items = new ArrayList<>();
main.getRegisterManager().getRandomEventsRegister().forEach(randomEventRegister -> {
String key = randomEventRegister.getKey();
ItemStack itemStack = getItemStack(game, randomEventRegister);
items.add(ClickableItem.of((itemStack), e -> {
if (e.isLeftClick()) {
int probability = config.getProbability(key);
config.setProbability(key, (probability + 1) % 101);
if (probability == 0) {
if (!game.isState(StateGame.LOBBY)) {
randomEventRegister.getRandomEvent().register(game.getRandom().nextDouble() * 100 < game.getConfig().getProbability(key));
}
}
e.setCurrentItem(getItemStack(game, randomEventRegister));
}
if (e.isRightClick()) {
int probability = config.getProbability(key);
config.setProbability(key, ((probability - 1) + 101) % 101);
if (probability == 1) {
randomEventRegister.getRandomEvent().register(false);
}
e.setCurrentItem(getItemStack(game, randomEventRegister));
}
}));
if (items.size() > 45) {
pagination.setItems(items.toArray(new ClickableItem[0]));
pagination.setItemsPerPage(36);
pagination.addToIterator(contents.newIterator(SlotIterator.Type.HORIZONTAL, 1, 0));
int page = pagination.getPage() + 1;
contents.set(5, 0, null);
contents.set(5, 1, null);
contents.set(5, 3, null);
contents.set(5, 5, null);
contents.set(5, 7, null);
contents.set(5, 8, null);
contents.set(5, 2, ClickableItem.of(new ItemBuilder(Material.ARROW).setDisplayName(game.translate("werewolf.menu.roles.previous", Formatter.format("¤t&", page), Formatter.format("&previous&", pagination.isFirst() ? page : page - 1))).build(), e -> INVENTORY.open(player, pagination.previous().getPage())));
contents.set(5, 6, ClickableItem.of(new ItemBuilder(Material.ARROW).setDisplayName(game.translate("werewolf.menu.roles.next", Formatter.format("¤t&", page), Formatter.format("&next&", pagination.isLast() ? page : page + 1))).build(), e -> INVENTORY.open(player, pagination.next().getPage())));
contents.set(5, 4, ClickableItem.empty(new ItemBuilder(UniversalMaterial.SIGN.getType()).setDisplayName(game.translate("werewolf.menu.roles.current", Formatter.format("¤t&", page), Formatter.format("&sum&", items.size() / 36 + 1))).build()));
} else {
int i = 0;
for (ClickableItem clickableItem : items) {
contents.set(i / 9 + 1, i % 9, clickableItem);
i++;
}
for (int k = i; k < (i / 9 + 1) * 9; k++) {
contents.set(k / 9 + 1, k % 9, null);
}
}
});
}
use of fr.minuskube.inv.content.InventoryContents in project WereWolfPlugin by Ph1Lou.
the class RandomEvents method init.
@Override
public void init(Player player, InventoryContents contents) {
Main main = JavaPlugin.getPlugin(Main.class);
WereWolfAPI game = main.getWereWolfAPI();
contents.set(0, 0, ClickableItem.of((new ItemBuilder(UniversalMaterial.COMPASS.getType()).setDisplayName(game.translate("werewolf.menu.return")).build()), e -> Config.INVENTORY.open(player)));
}
use of fr.minuskube.inv.content.InventoryContents in project WereWolfPlugin by Ph1Lou.
the class Roles method update.
@Override
public void update(Player player, InventoryContents contents) {
Main main = JavaPlugin.getPlugin(Main.class);
GameManager game = (GameManager) main.getWereWolfAPI();
IConfiguration config = game.getConfig();
Pagination pagination = contents.pagination();
List<String> lore = new ArrayList<>(Arrays.asList(game.translate("werewolf.menu.left"), game.translate("werewolf.menu.right")));
if (config.getLoverCount(LoverType.LOVER.getKey()) > 0) {
contents.set(0, 2, ClickableItem.of((new ItemBuilder(UniversalMaterial.GREEN_TERRACOTTA.getStack(config.getLoverCount(LoverType.LOVER.getKey()))).setDisplayName(game.translate(LoverType.LOVER.getKey()) + game.translate("werewolf.role.lover.random")).setLore(lore).build()), e -> {
if (e.isLeftClick()) {
config.addOneLover(LoverType.LOVER.getKey());
} else if (e.isRightClick()) {
int LoverNumber = config.getLoverCount(LoverType.LOVER.getKey());
if (LoverNumber > 0) {
config.removeOneLover(LoverType.LOVER.getKey());
}
}
}));
} else
contents.set(0, 2, ClickableItem.of((new ItemBuilder(UniversalMaterial.RED_TERRACOTTA.getStack()).setDisplayName(game.translate(LoverType.LOVER.getKey()) + game.translate("werewolf.role.lover.random")).setLore(lore).build()), e -> {
if (e.isLeftClick()) {
config.addOneLover(LoverType.LOVER.getKey());
}
}));
if (config.getLoverCount(LoverType.AMNESIAC_LOVER.getKey()) > 0) {
contents.set(0, 4, ClickableItem.of((new ItemBuilder(UniversalMaterial.GREEN_TERRACOTTA.getStack(config.getLoverCount(LoverType.AMNESIAC_LOVER.getKey()))).setDisplayName(game.translate(LoverType.AMNESIAC_LOVER.getKey())).setLore(lore).build()), e -> {
if (e.isLeftClick()) {
config.addOneLover(LoverType.AMNESIAC_LOVER.getKey());
} else if (e.isRightClick()) {
int AmnesiacLoverNumber = config.getLoverCount(LoverType.AMNESIAC_LOVER.getKey());
if (AmnesiacLoverNumber > 0) {
config.removeOneLover(LoverType.AMNESIAC_LOVER.getKey());
}
}
}));
} else
contents.set(0, 4, ClickableItem.of((new ItemBuilder(UniversalMaterial.RED_TERRACOTTA.getStack()).setDisplayName(game.translate(LoverType.AMNESIAC_LOVER.getKey())).setLore(lore).build()), e -> {
if (e.isLeftClick()) {
config.addOneLover(LoverType.AMNESIAC_LOVER.getKey());
}
}));
if (config.getLoverCount(LoverType.CURSED_LOVER.getKey()) > 0) {
contents.set(0, 6, ClickableItem.of((new ItemBuilder(UniversalMaterial.GREEN_TERRACOTTA.getStack(config.getLoverCount(LoverType.CURSED_LOVER.getKey()))).setDisplayName(game.translate(LoverType.CURSED_LOVER.getKey())).setLore(lore).build()), e -> {
if (e.isLeftClick()) {
config.addOneLover(LoverType.CURSED_LOVER.getKey());
} else if (e.isRightClick()) {
int cursedLoverNumber = config.getLoverCount(LoverType.CURSED_LOVER.getKey());
if (cursedLoverNumber > 0) {
config.removeOneLover(LoverType.CURSED_LOVER.getKey());
}
}
}));
} else
contents.set(0, 6, ClickableItem.of((new ItemBuilder(UniversalMaterial.RED_TERRACOTTA.getStack()).setDisplayName(game.translate(LoverType.CURSED_LOVER.getKey())).setLore(lore).build()), e -> {
if (e.isLeftClick()) {
config.addOneLover(LoverType.CURSED_LOVER.getKey());
}
}));
contents.set(5, 1, ClickableItem.of((new ItemBuilder(Category.WEREWOLF == this.category ? Material.EMERALD_BLOCK : Material.REDSTONE_BLOCK).setDisplayName(game.translate(Camp.WEREWOLF.getKey())).setAmount(Math.max(1, count(main, Category.WEREWOLF))).build()), e -> this.category = Category.WEREWOLF));
contents.set(5, 3, ClickableItem.of((new ItemBuilder(Category.VILLAGER == this.category ? Material.EMERALD_BLOCK : Material.REDSTONE_BLOCK).setDisplayName(game.translate(Camp.VILLAGER.getKey())).setAmount(Math.max(1, count(main, Category.VILLAGER))).build()), e -> this.category = Category.VILLAGER));
contents.set(5, 5, ClickableItem.of((new ItemBuilder(Category.NEUTRAL == this.category ? Material.EMERALD_BLOCK : Material.REDSTONE_BLOCK).setDisplayName(game.translate(Camp.NEUTRAL.getKey())).setAmount(Math.max(1, count(main, Category.NEUTRAL))).build()), e -> this.category = Category.NEUTRAL));
contents.set(5, 7, ClickableItem.of((new ItemBuilder(Category.ADDONS == this.category ? Material.EMERALD_BLOCK : Material.REDSTONE_BLOCK).setDisplayName(game.translate("werewolf.categories.addons")).setAmount(Math.max(1, count(main, Category.ADDONS))).build()), e -> this.category = Category.ADDONS));
lore.add(game.translate("werewolf.menu.shift"));
List<ClickableItem> items = new ArrayList<>();
for (RoleRegister roleRegister : main.getRegisterManager().getRolesRegister()) {
if (roleRegister.getCategories().contains(this.category)) {
String key = roleRegister.getKey();
AtomicBoolean unRemovable = new AtomicBoolean(false);
List<String> lore2 = new ArrayList<>(lore);
roleRegister.getLoreKey().stream().map(game::translate).map(s -> Arrays.stream(s.split("\\n")).collect(Collectors.toList())).forEach(lore2::addAll);
roleRegister.getRequireRole().ifPresent(roleKey -> lore2.add(game.translate("werewolf.menu.roles.need", Formatter.role(game.translate(roleKey)))));
main.getRegisterManager().getRolesRegister().stream().filter(roleRegister1 -> roleRegister1.getRequireRole().isPresent()).filter(roleRegister1 -> game.getConfig().getRoleCount(roleRegister1.getKey()) > 0).filter(roleRegister1 -> roleRegister1.getRequireRole().get().equals(key)).map(RoleRegister::getKey).findFirst().ifPresent(role -> {
lore2.add(game.translate("werewolf.menu.roles.dependant_load", Formatter.role(game.translate(role))));
unRemovable.set(true);
});
Optional<String> incompatible = roleRegister.getIncompatibleRoles().stream().filter(s -> game.getConfig().getRoleCount(s) > 0).map(game::translate).findFirst();
incompatible.ifPresent(role -> lore2.add(game.translate("werewolf.menu.roles.incompatible", Formatter.role(role))));
if (config.getRoleCount(key) > 0) {
items.add(ClickableItem.of((new ItemBuilder(roleRegister.getItem().isPresent() ? roleRegister.getItem().get() : UniversalMaterial.GREEN_TERRACOTTA.getStack()).setAmount(config.getRoleCount(key)).setLore(lore2).setDisplayName(game.translate(roleRegister.getKey())).build()), e -> {
if (e.isShiftClick()) {
AdvancedRoleMenu.getInventory(roleRegister).open(player);
} else if (e.isLeftClick()) {
selectPlus(game, key);
} else if (e.isRightClick()) {
int count = game.getConfig().getRoleCount(key);
if (!unRemovable.get() || count > 1) {
if (roleRegister.isRequireDouble() && count == 2) {
selectMinus(game, key);
}
selectMinus(game, key);
}
}
}));
} else {
if (roleRegister.getItem().isPresent()) {
lore2.add(0, game.translate("werewolf.utils.none"));
}
items.add(ClickableItem.of((new ItemBuilder(roleRegister.getItem().isPresent() ? roleRegister.getItem().get() : UniversalMaterial.RED_TERRACOTTA.getStack()).setAmount(1).setLore(lore2).setDisplayName(game.translate(roleRegister.getKey())).build()), e -> {
if (e.isShiftClick()) {
AdvancedRoleMenu.getInventory(roleRegister).open(player);
} else if (e.isLeftClick()) {
if (incompatible.isPresent()) {
return;
}
if (roleRegister.getRequireRole().isPresent()) {
if (game.getConfig().getRoleCount(roleRegister.getRequireRole().get()) == 0) {
return;
}
}
if (roleRegister.isRequireDouble()) {
selectPlus(game, key);
}
selectPlus(game, key);
}
}));
}
}
}
if (items.size() > 36) {
pagination.setItems(items.toArray(new ClickableItem[0]));
pagination.setItemsPerPage(27);
pagination.addToIterator(contents.newIterator(SlotIterator.Type.HORIZONTAL, 1, 0));
int page = pagination.getPage() + 1;
contents.set(4, 0, null);
contents.set(4, 1, null);
contents.set(4, 3, null);
contents.set(4, 5, null);
contents.set(4, 7, null);
contents.set(4, 8, null);
contents.set(4, 2, ClickableItem.of(new ItemBuilder(Material.ARROW).setDisplayName(game.translate("werewolf.menu.roles.previous", Formatter.format("¤t&", page), Formatter.format("&previous&", pagination.isFirst() ? page : page - 1))).build(), e -> getInventory(player, this.category).open(player, pagination.previous().getPage())));
contents.set(4, 6, ClickableItem.of(new ItemBuilder(Material.ARROW).setDisplayName(game.translate("werewolf.menu.roles.next", Formatter.format("¤t&", page), Formatter.format("&next&", pagination.isLast() ? page : page + 1))).build(), e -> getInventory(player, this.category).open(player, pagination.next().getPage())));
contents.set(4, 4, ClickableItem.empty(new ItemBuilder(UniversalMaterial.SIGN.getType()).setDisplayName(game.translate("werewolf.menu.roles.current", Formatter.format("¤t&", page), Formatter.format("&sum&", items.size() / 27 + 1))).build()));
} else {
int i = 0;
for (ClickableItem clickableItem : items) {
contents.set(i / 9 + 1, i % 9, clickableItem);
i++;
}
for (int k = i; k < 36; k++) {
contents.set(k / 9 + 1, k % 9, null);
}
}
}
use of fr.minuskube.inv.content.InventoryContents in project WereWolfPlugin by Ph1Lou.
the class Save method init.
@Override
public void init(Player player, InventoryContents contents) {
Main main = JavaPlugin.getPlugin(Main.class);
WereWolfAPI game = main.getWereWolfAPI();
contents.set(0, 0, ClickableItem.of((new ItemBuilder(UniversalMaterial.COMPASS.getType()).setDisplayName(game.translate("werewolf.menu.return")).build()), e -> Config.INVENTORY.open(player)));
}
use of fr.minuskube.inv.content.InventoryContents in project WereWolfPlugin by Ph1Lou.
the class Save method update.
@Override
public void update(Player player, InventoryContents contents) {
Main main = JavaPlugin.getPlugin(Main.class);
WereWolfAPI game = main.getWereWolfAPI();
File repertoire = new File(main.getDataFolder() + File.separator + "configs");
File[] files = repertoire.listFiles();
if (files == null)
return;
if (j >= files.length) {
j = Math.max(0, Math.min(8, files.length) - 1);
}
for (int i = 0; i < 8; i++) {
if (i >= Math.min(files.length, 8)) {
contents.set(0, i + 1, null);
} else if (i == j) {
contents.set(0, i + 1, ClickableItem.empty((new ItemBuilder(UniversalMaterial.FEATHER.getType()).setDisplayName(game.translate("werewolf.menu.save.configuration", Formatter.format("&save&", files[i].getName()))).build())));
} else {
int finalI = i;
contents.set(0, i + 1, ClickableItem.of((new ItemBuilder(UniversalMaterial.PAPER.getType()).setDisplayName(game.translate("werewolf.menu.save.configuration", Formatter.format("&save&", files[i].getName()))).build()), e -> j = finalI));
}
}
contents.set(1, 0, ClickableItem.of((new ItemBuilder(Material.EMERALD_BLOCK).setDisplayName(game.translate("werewolf.menu.save.new")).build()), e -> new AnvilGUI.Builder().onComplete((player2, text) -> {
save(main, text, player);
return AnvilGUI.Response.close();
}).preventClose().text(" ").title(game.translate("werewolf.menu.save.save_menu")).itemLeft(new ItemStack(Material.EMERALD_BLOCK)).plugin(main).onClose((player2) -> BukkitUtils.scheduleSyncDelayedTask(() -> Save.INVENTORY.open(player))).open(player)));
if (files.length != 0) {
contents.set(1, 3, ClickableItem.of((new ItemBuilder(UniversalMaterial.BED.getType()).setDisplayName(game.translate("werewolf.menu.save.load", Formatter.format("&save&", files[j].getName()))).build()), e -> {
load(main);
player.sendMessage(game.translate(Prefix.GREEN.getKey(), "werewolf.menu.save.load_message", Formatter.format("&save&", files[j].getName())));
}));
contents.set(1, 5, ClickableItem.of((new ItemBuilder(UniversalMaterial.BARRIER.getType()).setDisplayName(game.translate("werewolf.menu.save.delete", Formatter.format("&save&", files[j].getName()))).build()), e -> {
player.sendMessage(game.translate(Prefix.RED.getKey(), "werewolf.menu.save.delete_message", Formatter.format("&save&", files[j].getName())));
erase(main);
}));
} else {
contents.set(1, 3, null);
contents.set(1, 5, null);
}
}
Aggregations