use of me.RockinChaos.itemjoin.item.ItemMap in project ItemJoin by RockinChaos.
the class Menu method convertStack.
/**
* Converts the ItemStack that is attempting to be saved to a ItemMap.
*
* @param player - The Player saving the ItemStack.
* @param item - The ItemStack to be saved.
*/
private static void convertStack(final Player player, final ItemStack item, final String slot) {
ItemMap itemMap = new ItemMap("item_" + StringUtils.getPath(1), "ARBITRARY");
itemMap.setMaterial(item.getType());
if (!ServerUtils.hasSpecificUpdate("1_13")) {
itemMap.setDataValue((short) LegacyAPI.getDataValue(item));
}
itemMap.setCount(String.valueOf(item.getAmount()));
if (item.getType().getMaxDurability() > 30 && ItemHandler.getDurability(item) != 0 && ItemHandler.getDurability(item) != (item.getType().getMaxDurability())) {
itemMap.setDurability(ItemHandler.getDurability(item));
}
if (item.hasItemMeta()) {
if (item.getItemMeta().hasDisplayName()) {
itemMap.setCustomName(item.getItemMeta().getDisplayName().replace("�", "&"));
}
if (item.getItemMeta().hasLore()) {
List<String> newLore = new ArrayList<String>();
for (String lore : item.getItemMeta().getLore()) {
newLore.add(lore.replace("�", "&"));
}
itemMap.setCustomLore(newLore);
}
if (item.getItemMeta().hasEnchants()) {
Map<String, Integer> enchantList = new HashMap<String, Integer>();
for (Enchantment e : item.getItemMeta().getEnchants().keySet()) {
enchantList.put(ItemHandler.getEnchantName(e).toUpperCase(), item.getItemMeta().getEnchants().get(e));
}
itemMap.setEnchantments(enchantList);
}
}
if (StringUtils.containsIgnoreCase(item.getType().toString(), "LEATHER_")) {
LeatherArmorMeta meta = (LeatherArmorMeta) item.getItemMeta();
if (meta.getColor() != null) {
itemMap.setLeatherColor(DyeColor.getByColor(meta.getColor()).name());
}
} else if (item.getType().toString().equalsIgnoreCase("SKULL_ITEM") || item.getType().toString().equalsIgnoreCase("PLAYER_HEAD")) {
if (!PlayerHandler.getSkullOwner(item).equalsIgnoreCase("NULL")) {
itemMap.setSkull(PlayerHandler.getSkullOwner(item));
} else if (!ItemHandler.getSkullTexture(item.getItemMeta()).isEmpty()) {
itemMap.setSkullTexture(ItemHandler.getSkullTexture(item.getItemMeta()));
}
} else if (itemMap.getMaterial().toString().contains("CHARGE") || itemMap.getMaterial().toString().equalsIgnoreCase("FIREWORK_STAR")) {
itemMap.setChargeColor(DyeColor.getByFireworkColor(((FireworkEffectMeta) item.getItemMeta()).getEffect().getColors().get(0)));
} else if (itemMap.getMaterial().toString().contains("BANNER")) {
itemMap.setBannerPatterns(((BannerMeta) item.getItemMeta()).getPatterns());
} else if (itemMap.getMaterial().toString().equalsIgnoreCase("FIREWORK") || itemMap.getMaterial().toString().equalsIgnoreCase("FIREWORK_ROCKET")) {
List<DyeColor> colors = new ArrayList<DyeColor>();
for (Color color : ((FireworkMeta) item.getItemMeta()).getEffects().get(0).getColors()) {
colors.add(DyeColor.getByFireworkColor(color));
}
itemMap.setFirework(((FireworkMeta) item.getItemMeta()).getEffects().get(0));
itemMap.setFireworkColor(colors);
itemMap.setFireworkFlicker(((FireworkMeta) item.getItemMeta()).getEffects().get(0).hasFlicker());
itemMap.setFireworkTrail(((FireworkMeta) item.getItemMeta()).getEffects().get(0).hasTrail());
itemMap.setFireworkType(((FireworkMeta) item.getItemMeta()).getEffects().get(0).getType());
itemMap.setFireworkPower(((FireworkMeta) item.getItemMeta()).getPower());
} else if (itemMap.getMaterial() == Material.WRITTEN_BOOK) {
itemMap.setAuthor(((BookMeta) item.getItemMeta()).getAuthor().replace("�", "&"));
itemMap.setTitle(((BookMeta) item.getItemMeta()).getTitle().replace("�", "&"));
if (ServerUtils.hasSpecificUpdate("1_10")) {
itemMap.setGeneration(((BookMeta) item.getItemMeta()).getGeneration());
}
List<String> newPages = new ArrayList<String>();
for (String page : ((BookMeta) item.getItemMeta()).getPages()) {
newPages.add(page.replace("�", "&"));
}
itemMap.setPages(newPages);
List<List<String>> savePages = new ArrayList<List<String>>();
for (String page : ((BookMeta) item.getItemMeta()).getPages()) {
List<String> pageList = new ArrayList<String>();
for (String splitPage : page.split("\n")) {
pageList.add(splitPage.replace("�", "&"));
}
savePages.add(pageList);
}
itemMap.setListPages(savePages);
}
if (slot == null) {
switchPane(player, itemMap, 0);
} else {
itemMap.setSlot(slot);
itemMap.saveToConfig();
String[] placeHolders = LanguageAPI.getLang(false).newString();
placeHolders[3] = (item.hasItemMeta() && item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : itemMap.getConfigName());
LanguageAPI.getLang(false).sendLangMessage("commands.menu.itemSaved", player, placeHolders);
}
itemMap.renderItemStack();
}
use of me.RockinChaos.itemjoin.item.ItemMap in project ItemJoin by RockinChaos.
the class Menu method bannerPane.
/**
* Opens the Pane for the Player.
* This Pane is for modifying banner items.
*
* @param player - The Player to have the Pane opened.
* @param itemMap - The ItemMap currently being modified.
*/
private static void bannerPane(final Player player, final ItemMap itemMap) {
Interface bannerPane = new Interface(true, 6, GUIName, player);
SchedulerUtils.runAsync(() -> {
bannerPane.setReturnButton(new Button(ItemHandler.getItem("BARRIER", 1, false, "&c&l&nReturn", "&7", "&7*Returns you to the item definition menu."), event -> creatingPane(player, itemMap)));
for (PatternType pattern : PatternType.values()) {
String patternString = "NONE";
if (StringUtils.nullCheck(itemMap.getBannerPatterns().toString()) != "NONE") {
for (Pattern patterns : itemMap.getBannerPatterns()) {
if (patterns.getPattern() == pattern) {
patternString = patterns.getColor() + ":" + patterns.getPattern().name().toUpperCase();
break;
}
}
}
final String checkPattern = patternString;
bannerPane.addButton(new Button(ItemHandler.getItem("PAPER", 1, (checkPattern != "NONE" ? true : false), "&f" + pattern.name(), "&7", "&7*Click to add this as", "&7a banner pattern.", (checkPattern != "NONE" ? "&9&lInformation: &a" + checkPattern : "")), event -> {
if (checkPattern != "NONE") {
List<Pattern> patternList = itemMap.getBannerPatterns();
if (StringUtils.nullCheck(itemMap.getBannerPatterns().toString()) != "NONE") {
for (Pattern patterns : patternList) {
if (patterns.getPattern() == pattern) {
patternList.remove(patterns);
itemMap.setBannerPatterns(patternList);
break;
}
}
}
bannerPane(player, itemMap);
} else {
patternPane(player, itemMap, pattern);
}
}));
}
});
bannerPane.open(player);
}
use of me.RockinChaos.itemjoin.item.ItemMap in project ItemJoin by RockinChaos.
the class Menu method modifyLoreLinePane.
/**
* Opens the Pane for the Player.
* This Pane is for modifying a specific lore line.
*
* @param player - The Player to have the Pane opened.
* @param itemMap - The ItemMap currently being modified.
*/
private static void modifyLoreLinePane(final Player player, final ItemMap itemMap, final int position) {
Interface modifyLorePane = new Interface(false, 2, GUIName, player);
SchedulerUtils.runAsync(() -> {
modifyLorePane.addButton(new Button(fillerPaneGItem), 3);
modifyLorePane.addButton(new Button(ItemHandler.getItem("WRITABLE_BOOK", 1, false, "&e&l&nModify", "&7", "&7*Change the lore line.", "&9&lLore: &a" + itemMap.getCustomLore().get(position)), event -> {
player.closeInventory();
String[] placeHolders = LanguageAPI.getLang(false).newString();
placeHolders[16] = "LORE LINE";
placeHolders[15] = "&bThis is a new lore line.";
LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputType", player, placeHolders);
LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputExample", player, placeHolders);
}, event -> {
List<String> lore = itemMap.getCustomLore();
lore.set(position, ChatColor.stripColor(event.getMessage()));
itemMap.setCustomLore(lore);
String[] placeHolders = LanguageAPI.getLang(false).newString();
placeHolders[16] = "LORE LINE";
LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputSet", player, placeHolders);
modifyLoreLinePane(event.getPlayer(), itemMap, position);
}));
modifyLorePane.addButton(new Button(fillerPaneGItem));
modifyLorePane.addButton(new Button(ItemHandler.getItem("REDSTONE", 1, false, "&c&l&nDelete", "&7", "&7*Delete this lore line."), event -> {
List<String> lore = itemMap.getCustomLore();
lore.remove(position);
itemMap.setCustomLore(lore);
lorePane(player, itemMap);
}));
modifyLorePane.addButton(new Button(fillerPaneGItem), 3);
modifyLorePane.addButton(new Button(ItemHandler.getItem("BARRIER", 1, false, "&c&l&nReturn", "&7", "&7*Returns you to the item definition menu."), event -> lorePane(player, itemMap)));
modifyLorePane.addButton(new Button(fillerPaneBItem), 7);
modifyLorePane.addButton(new Button(ItemHandler.getItem("BARRIER", 1, false, "&c&l&nReturn", "&7", "&7*Returns you to the item definition menu."), event -> lorePane(player, itemMap)));
});
modifyLorePane.open(player);
}
use of me.RockinChaos.itemjoin.item.ItemMap in project ItemJoin by RockinChaos.
the class Menu method soundPane.
/**
* Opens the Pane for the Player.
* This Pane is for setting an items command sound.
*
* @param player - The Player to have the Pane opened.
* @param itemMap - The ItemMap currently being modified.
*/
private static void soundPane(final Player player, final ItemMap itemMap, final int stage) {
Interface soundPane = new Interface(true, 6, GUIName, player);
SchedulerUtils.runAsync(() -> {
if (stage != 3) {
soundPane.setReturnButton(new Button(ItemHandler.getItem("BARRIER", 1, false, "&c&l&nReturn", "&7", "&7*Returns you to the teleport menu."), event -> teleportPane(player, itemMap, stage)));
} else {
soundPane.setReturnButton(new Button(ItemHandler.getItem("BARRIER", 1, false, "&c&l&nReturn", "&7", "&7*Returns you to the item commands menu."), event -> commandPane(player, itemMap)));
}
for (Sound sound : Sound.values()) {
if (stage != 3) {
soundPane.addButton(new Button(ItemHandler.getItem((ServerUtils.hasSpecificUpdate("1_13") ? "MUSIC_DISC_MELLOHI" : "2262"), 1, false, "&f" + sound.name(), "&7", "&7*Click to set the", "&7teleport-sound of the item."), event -> {
itemMap.setTeleportSound(sound.name());
soundVolumePane(player, itemMap, stage);
}));
} else {
soundPane.addButton(new Button(ItemHandler.getItem((ServerUtils.hasSpecificUpdate("1_13") ? "MUSIC_DISC_MELLOHI" : "2262"), 1, false, "&f" + sound.name(), "&7", "&7*Click to set the", "&7commands-sound of the item."), event -> {
itemMap.setCommandSound(sound);
soundVolumePane(player, itemMap, stage);
}));
}
}
});
soundPane.open(player);
}
use of me.RockinChaos.itemjoin.item.ItemMap in project ItemJoin by RockinChaos.
the class Menu method mobsPane.
/**
* Opens the Pane for the Player.
* This Pane is for setting the mobs drop chances.
*
* @param player - The Player to have the Pane opened.
* @param itemMap - The ItemMap currently being modified.
*/
private static void mobsPane(final Player player, final ItemMap itemMap) {
Interface dropsPane = new Interface(true, 6, GUIName, player);
SchedulerUtils.runAsync(() -> {
dropsPane.setReturnButton(new Button(ItemHandler.getItem("BARRIER", 1, false, "&c&l&nReturn", "&7", "&7*Returns you to the drop chances menu."), event -> dropsPane(player, itemMap)));
for (EntityType entity : EntityType.values()) {
if (itemMap.getMobsDrop().containsKey(entity) && entity.isAlive()) {
dropsPane.addButton(new Button(ItemHandler.getItem("EGG", 1, (itemMap.getMobsDrop().containsKey(entity)), "&f" + entity.name(), "&7", "&7*Click to add this as", "&7a banner pattern.", (itemMap.getMobsDrop().containsKey(entity) ? "&9&lChance: &a" + itemMap.getMobsDrop().get(entity) : "")), event -> {
if (itemMap.getMobsDrop().containsKey(entity)) {
Map<EntityType, Double> mobsDrop = itemMap.getMobsDrop();
mobsDrop.remove(entity);
itemMap.setMobsDrop(mobsDrop);
mobsPane(player, itemMap);
} else {
chancePane(player, itemMap, entity, null);
}
}));
}
}
for (EntityType entity : EntityType.values()) {
if (!itemMap.getMobsDrop().containsKey(entity) && entity.isAlive()) {
dropsPane.addButton(new Button(ItemHandler.getItem("EGG", 1, (itemMap.getMobsDrop().containsKey(entity)), "&f" + entity.name(), "&7", "&7*Click to add this as", "&7a banner pattern.", (itemMap.getMobsDrop().containsKey(entity) ? "&9&lChance: &a" + itemMap.getMobsDrop().get(entity) : "")), event -> {
if (itemMap.getMobsDrop().containsKey(entity)) {
Map<EntityType, Double> mobsDrop = itemMap.getMobsDrop();
mobsDrop.remove(entity);
itemMap.setMobsDrop(mobsDrop);
mobsPane(player, itemMap);
} else {
chancePane(player, itemMap, entity, null);
}
}));
}
}
});
dropsPane.open(player);
}
Aggregations