Banner menu v3 (should work fully now :D)

This commit is contained in:
Lesley Dom committed 2020-09-10 19:11:39 +02:00
1 parent 4ebd4eb189
commit 4abd7644aa
4 files changed
+186 -52

No files matched your search

@@ -25,29 +25,58 @@
package net.arcaniax.buildersutilities.menus.bannermenus;
import net.arcaniax.buildersutilities.menus.Menus;
import net.arcaniax.buildersutilities.menus.inv.ClickableItem;
import net.arcaniax.buildersutilities.menus.inv.content.InventoryContents;
import net.arcaniax.buildersutilities.menus.inv.content.InventoryProvider;
import net.arcaniax.buildersutilities.utils.BannerUtil;
import net.arcaniax.buildersutilities.utils.Items;
import org.apache.commons.lang.StringUtils;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.block.banner.Pattern;
import org.bukkit.block.banner.PatternType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class BannerPatternMenuProvider implements InventoryProvider {
private static final ItemStack grayPane = Items
.create(Material.LIGHT_GRAY_STAINED_GLASS_PANE, (short) 0, 1, "&7", "");
.create(Material.GRAY_STAINED_GLASS_PANE, (short) 0, 1, "&7", "");
private static final ItemStack randomizeHead = Items.createHead(
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzk3OTU1NDYyZTRlNTc2NjY0NDk5YWM0YTFjNTcyZjYxNDNmMTlhZDJkNjE5NDc3NjE5OGY4ZDEzNmZkYjIifX19",
1, "&7Click to randomise", "");
// private static final ItemStack currentColor = BannerUtil.createBanner("&a", 1, DyeColor.WHITE, "");
private static final ItemStack closeButton = Items
.create(Material.BARRIER, (short) 0, 1, "&cClick to close", "");
private static final ItemStack whiteBanner = Items
.create(Material.WHITE_BANNER, (short) 0, 1, "&c", "");
@Override
public void init(Player player, InventoryContents contents) {
// for (int x = 0; x < 54; x++) {
// contents.set(x / 9, x % 9, ClickableItem.empty(grayPane));
// }
contents.fill(ClickableItem.empty(grayPane));
contents.set(0, 1, ClickableItem.of(randomizeHead, inventoryClickEvent -> selectRandomPattern(player)));
contents.set(0, 4, ClickableItem.of(BannerUtil.currentBanner.get(player.getUniqueId()), inventoryClickEvent -> getBanner(player)));
contents.set(0, 7, ClickableItem.of(closeButton, inventoryClickEvent -> contents.inventory().close(player)));
int row = 1;
int column = 0;
for (PatternType pattern : BannerUtil.allPatterns){
List<Pattern> patterns = new ArrayList<>();
patterns.add(new Pattern(BannerUtil.selectedColor.get(player.getUniqueId()), pattern));
contents.set(row, column, ClickableItem.of(BannerUtil.createBanner("&3" + StringUtils.capitalize(pattern.toString().toLowerCase().replace("_", " ")), BannerUtil.getOppositeBaseColor(BannerUtil.selectedColor.get(player.getUniqueId())), "&7__&7click to select", patterns), inventoryClickEvent -> selectPattern(player, pattern)));
column++;
if (column==9){
column = 0;
row++;
}
}
// contents.set(0, 1, ClickableItem.of(randomizeHead, NULL));
// contents.set(0, 4, ClickableItem.empty(currentColor));
// contents.set(0, 7, ClickableItem.of(closeButton, inventoryClickEvent -> contents.inventory().close(player)));
@@ -60,4 +89,44 @@ public class BannerPatternMenuProvider implements InventoryProvider {
// contents.set(x / 9, x % 9, ClickableItem.of(banner, NULL));
// }
}
private void selectRandomPattern(Player player){
ItemStack banner = BannerUtil.currentBanner.get(player.getUniqueId());
PatternType pattern = BannerUtil.getRandomPattern();
BannerUtil.currentBanner.put(player.getUniqueId(), BannerUtil.addPattern(
banner, new Pattern(BannerUtil.selectedColor.get(player.getUniqueId()), pattern)));
if (BannerUtil.getPatterns(banner).size()==15){
getBanner(player);
}
else{
Menus.BANNER_MENU_COLOR.open(player);
}
}
private void selectPattern(Player player, PatternType patternType){
ItemStack banner = BannerUtil.currentBanner.get(player.getUniqueId());
BannerUtil.currentBanner.put(player.getUniqueId(), BannerUtil.addPattern(
banner, new Pattern(BannerUtil.selectedColor.get(player.getUniqueId()), patternType)));
if (BannerUtil.getPatterns(banner).size()==15){
getBanner(player);
}
else{
Menus.BANNER_MENU_COLOR.open(player);
}
}
private void getBanner(Player player){
ItemStack banner = BannerUtil.currentBanner.get(player.getUniqueId());
ItemMeta meta = banner.getItemMeta();
meta.setDisplayName("");
meta.setLore(new ArrayList<>());
banner.setItemMeta(meta);
player.getInventory().addItem(banner);
player.closeInventory();
BannerUtil.currentBanner.remove(player.getUniqueId());
}
}