mirror of
https://github.com/darksaid98/Builders-Utilities.git
synced 2026-12-01 14:38:46 +00:00
Banner menu v3 (should work fully now :D)
This commit is contained in:
1 parent
4ebd4eb189
commit
4abd7644aa
4 files changed
+186
-52
No files matched your search
+62
-14
@@ -25,38 +25,86 @@
|
||||
|
||||
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.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public class BannerColorMenuProvider implements InventoryProvider {
|
||||
|
||||
|
||||
private static final ItemStack grayPane = Items
|
||||
.create(Material.LIGHT_GRAY_STAINED_GLASS_PANE, (short) 0, 1, "&7", "");
|
||||
private static final ItemStack head = Items.createHead(
|
||||
.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, grayPane);
|
||||
// }
|
||||
// inv1.setItem(1, );
|
||||
// if (first) {
|
||||
// inv1.setItem(4, bU.createBanner("&aClick to get the banner", 1, DyeColor.valueOf(clicked.getType().toString().replace("_BANNER", "")), ""));
|
||||
// } else {
|
||||
// inv1.setItem(4, bU.addPattern(inv.getItem(4), new Pattern(bU.getColorFromBanner(clicked), bU.getPatternType(clicked))));
|
||||
// }
|
||||
// inv1.setItem(7, i.create(Material.BARRIER, (short) 0, 1, "&cClick to close", ""));
|
||||
contents.fill(ClickableItem.empty(grayPane));
|
||||
contents.set(0, 1, ClickableItem.of(randomizeHead, inventoryClickEvent -> selectRandomColor(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 = 2;
|
||||
int column = 1;
|
||||
for (DyeColor color : BannerUtil.allColors){
|
||||
contents.set(row, column, ClickableItem.of(BannerUtil.createDye("&3" + StringUtils.capitalize(color.toString().toLowerCase().replace("_", " ")), color, "&7__&7click to select"), inventoryClickEvent -> selectColor(player, color)));
|
||||
column++;
|
||||
if (column==9){
|
||||
column = 1;
|
||||
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)));
|
||||
// for (int x = 19; x < 27; x++) {
|
||||
// inv1.setItem(x, i.create(Material.LEGACY_INK_SACK, (short) (x - 19), 1, "&3" + bU.getAllColors().get(x - 19).toString().toLowerCase().replace("_", " "), "&7__&7click to select"));
|
||||
// ItemStack banner = BannerUtil.createBanner("&3" + BannerUtil.allColors.get(x - 19).toString().toLowerCase().replace("_", " "), 1, BannerUtil.allColors.get(x - 19), "&7__&7click to select");
|
||||
// contents.set(x / 9, x % 9, ClickableItem.of(banner, NULL));
|
||||
// }
|
||||
// for (int x = 28; x < 36; x++) {
|
||||
// inv1.setItem(x, i.create(Material.LEGACY_INK_SACK, (short) (x - 20), 1, "&3" + bU.getAllColors().get(x - 20).toString().toLowerCase().replace("_", " "), "&7__&7click to select"));
|
||||
// ItemStack banner = BannerUtil.createBanner("&3" + BannerUtil.allColors.get(x - 28 + 8).toString().toLowerCase().replace("_", " "), 1, BannerUtil.allColors.get(x - 28 + 8), "&7__&7click to select");
|
||||
// contents.set(x / 9, x % 9, ClickableItem.of(banner, NULL));
|
||||
// }
|
||||
}
|
||||
|
||||
private void selectRandomColor(Player player){
|
||||
DyeColor dyeColor = BannerUtil.getRandomDye();
|
||||
BannerUtil.selectedColor.put(player.getUniqueId(), dyeColor);
|
||||
Menus.BANNER_MENU_PATTERN.open(player);
|
||||
}
|
||||
|
||||
private void selectColor(Player player, DyeColor dyeColor){
|
||||
BannerUtil.selectedColor.put(player.getUniqueId(), dyeColor);
|
||||
Menus.BANNER_MENU_PATTERN.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());
|
||||
}
|
||||
}
|
||||
+6
-5
@@ -33,11 +33,13 @@ import net.arcaniax.buildersutilities.menus.inv.content.InventoryProvider;
|
||||
import net.arcaniax.buildersutilities.menus.inv.content.SlotPos;
|
||||
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.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@@ -64,7 +66,7 @@ public class BannerMenuProvider implements InventoryProvider {
|
||||
int row = 2;
|
||||
int column = 1;
|
||||
for (DyeColor color : BannerUtil.allColors){
|
||||
contents.set(row, column, ClickableItem.of(BannerUtil.createBanner("&3" + color.toString().toLowerCase().replace("_", " "), color, "&7__&7click to select"), inventoryClickEvent -> selectColor(player, color)));
|
||||
contents.set(row, column, ClickableItem.of(BannerUtil.createBanner("&3" + StringUtils.capitalize(color.toString().toLowerCase().replace("_", " ")), color, "&7__&7Click to select"),inventoryClickEvent -> selectColor(player, color)));
|
||||
column++;
|
||||
if (column==9){
|
||||
column = 1;
|
||||
@@ -86,14 +88,13 @@ public class BannerMenuProvider implements InventoryProvider {
|
||||
}
|
||||
|
||||
private void selectRandomColor(Player player){
|
||||
Random random = new Random();
|
||||
DyeColor dyeColor = BannerUtil.allColors.get(random.nextInt(BannerUtil.allColors.size()-1));
|
||||
BannerUtil.currentBanner.put(player.getUniqueId(), BannerUtil.createBanner("&3" + dyeColor.toString().toLowerCase().replace("_", " "), dyeColor, "&7__&7click to select"));
|
||||
DyeColor dyeColor = BannerUtil.getRandomDye();
|
||||
BannerUtil.currentBanner.put(player.getUniqueId(), BannerUtil.createBanner("&6Banner", dyeColor, "&7__&7Click to get banner"));
|
||||
Menus.BANNER_MENU_COLOR.open(player);
|
||||
}
|
||||
|
||||
private void selectColor(Player player, DyeColor dyeColor){
|
||||
BannerUtil.currentBanner.put(player.getUniqueId(), BannerUtil.createBanner("&3" + dyeColor.toString().toLowerCase().replace("_", " "), dyeColor, "&7__&7click to select"));
|
||||
BannerUtil.currentBanner.put(player.getUniqueId(), BannerUtil.createBanner("&6Banner", dyeColor, "&7__&7Click to get banner"));
|
||||
Menus.BANNER_MENU_COLOR.open(player);
|
||||
}
|
||||
}
|
||||
+73
-4
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -32,11 +32,13 @@ import org.bukkit.block.banner.Pattern;
|
||||
import org.bukkit.block.banner.PatternType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BannerMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class BannerUtil {
|
||||
public static final HashMap<UUID, ItemStack> currentBanner = new HashMap<>();
|
||||
public static final HashMap<UUID, DyeColor> selectedColor = new HashMap<>();
|
||||
|
||||
public static final List<DyeColor> allColors = new ArrayList<>();
|
||||
public static final List<PatternType> allPatterns = new ArrayList<>();
|
||||
@@ -72,11 +74,6 @@ public class BannerUtil {
|
||||
public static ItemStack createBanner(String name, DyeColor base, String lore, List<Pattern> patterns) {
|
||||
ItemStack item = Items.create(XMaterial.matchXMaterial(base.toString() + "_BANNER").get().parseMaterial(), (short) 0, 1, name, "");
|
||||
BannerMeta meta = (BannerMeta) item.getItemMeta();
|
||||
if (Main.getInstance().getNmsManager().isAtLeastVersion(1, 11, 0)) {
|
||||
item.setDurability((short) allColors.indexOf(base));
|
||||
} else {
|
||||
meta.setBaseColor(base);
|
||||
}
|
||||
|
||||
meta.setPatterns(patterns);
|
||||
if (!lore.equals("")) {
|
||||
@@ -91,6 +88,21 @@ public class BannerUtil {
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack createDye(String name, DyeColor base, String lore) {
|
||||
ItemStack item = Items.create(XMaterial.matchXMaterial(base.toString() + "_DYE").get().parseMaterial(), (short) 0, 1, name, "");
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (!lore.equals("")) {
|
||||
String[] loreListArray = lore.split("__");
|
||||
List<String> loreList = new ArrayList<>();
|
||||
for (String s : loreListArray) {
|
||||
loreList.add(s.replace('&', ChatColor.COLOR_CHAR));
|
||||
}
|
||||
meta.setLore(loreList);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack createBanner(String name, DyeColor base, String lore) {
|
||||
XMaterial.matchXMaterial(base.toString() + "_BANNER").get().parseMaterial();
|
||||
|
||||
@@ -136,33 +148,13 @@ public class BannerUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static DyeColor getBaseColor(ItemStack i) {
|
||||
public static List<Pattern> getPatterns(ItemStack i) {
|
||||
if (i.getType().toString().contains("BANNER")) {
|
||||
BannerMeta meta = (BannerMeta) i.getItemMeta();
|
||||
if (Main.getInstance().getNmsManager().isAtLeastVersion(1, 11, 0)) {
|
||||
return allColors.get(i.getDurability());
|
||||
} else {
|
||||
return meta.getBaseColor();
|
||||
}
|
||||
|
||||
List<Pattern> patterns = meta.getPatterns();
|
||||
return patterns;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static PatternType getPatternType(ItemStack i) {
|
||||
if (i.getType().toString().contains("BANNER")) {
|
||||
BannerMeta meta = (BannerMeta) i.getItemMeta();
|
||||
return meta.getPattern(0).getPattern();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static DyeColor getColorFromBanner(ItemStack i) {
|
||||
if (i.getType().toString().contains("BANNER")) {
|
||||
BannerMeta meta = (BannerMeta) i.getItemMeta();
|
||||
return meta.getPattern(0).getColor();
|
||||
}
|
||||
return null;
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public static DyeColor getRandomDye() {
|
||||
@@ -172,5 +164,29 @@ public class BannerUtil {
|
||||
public static PatternType getRandomPattern() {
|
||||
return allPatterns.get(random.nextInt(allPatterns.size()));
|
||||
}
|
||||
|
||||
public static DyeColor getOppositeBaseColor(DyeColor dyeColor){
|
||||
switch (dyeColor){
|
||||
case RED:
|
||||
case BLUE:
|
||||
case CYAN:
|
||||
case GRAY:
|
||||
case BLACK:
|
||||
case BROWN:
|
||||
case GREEN:
|
||||
case PURPLE:
|
||||
return DyeColor.WHITE;
|
||||
case PINK:
|
||||
case WHITE:
|
||||
case ORANGE:
|
||||
case YELLOW:
|
||||
case MAGENTA:
|
||||
case LIGHT_BLUE:
|
||||
case LIGHT_GRAY:
|
||||
case LIME:
|
||||
default:
|
||||
return DyeColor.BLACK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user