From b220f3a39e4daa7208edde5bc125e12406fe97f6 Mon Sep 17 00:00:00 2001 From: J3fftw1 <44972470+J3fftw1@users.noreply.github.com> Date: Tue, 26 Nov 2019 19:00:35 +0100 Subject: [PATCH 1/4] added cscorelib version to the guide --- .../mrCookieSlime/Slimefun/SlimefunGuide.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/mrCookieSlime/Slimefun/SlimefunGuide.java b/src/main/java/me/mrCookieSlime/Slimefun/SlimefunGuide.java index 24dc96c9b..b6cb5127d 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/SlimefunGuide.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/SlimefunGuide.java @@ -9,6 +9,7 @@ import java.util.Optional; import java.util.logging.Level; import java.util.stream.Collectors; +import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameMode; @@ -143,7 +144,15 @@ public final class SlimefunGuide { }); } - menu.addItem(1, new CustomItem(new ItemStack(Material.WRITABLE_BOOK), "&aCredits", "", "&7Version: &a" + SlimefunPlugin.instance.getDescription().getVersion(), "&7Contributors: &e" + SlimefunPlugin.getUtilities().contributors.size(), "", "&7\u21E8 Click to see the people behind this Plugin")); + menu.addItem(1, new CustomItem(new ItemStack(Material.WRITABLE_BOOK), + "&aCredits", + "", + "&7Slimefun Version: &a" + SlimefunPlugin.instance.getDescription().getVersion(), + "&7CSCore-Lib Version: &a" + CSCoreLib.getLib().getDescription().getVersion(), + "&7Contributors: &e" + SlimefunPlugin.getUtilities().contributors.size(), + "", + "&7\u21E8 Click to see the people behind this Plugin" + )); menu.addMenuClickHandler(1, (pl, slot, item, action) -> { openCredits(pl, guide); return false; @@ -159,7 +168,7 @@ public final class SlimefunGuide { return false; }); } catch (Exception x) { - Slimefun.getLogger().log(Level.SEVERE, "An Error occured while creating the Info-Panel for Slimefun " + Slimefun.getVersion(), x); + Slimefun.getLogger().log(Level.SEVERE, "An Error occurred while creating the Info-Panel for Slimefun " + Slimefun.getVersion(), x); } menu.addItem(7, new CustomItem(new ItemStack(Material.REDSTONE), "&4Bug Tracker", "", "&7Unsolved Issues: &a" + SlimefunPlugin.getUtilities().issues, "", "&7\u21E8 Click to go to the Slimefun Bug Tracker")); @@ -204,7 +213,7 @@ public final class SlimefunGuide { String texture = contributor.getTexture(); if (texture != null) skull = CustomSkull.getItem(texture); } catch (Exception x) { - Slimefun.getLogger().log(Level.SEVERE, "An Error occured while fetching a Contributor Head for Slimefun " + Slimefun.getVersion(), x); + Slimefun.getLogger().log(Level.SEVERE, "An Error occurred while fetching a Contributor Head for Slimefun " + Slimefun.getVersion(), x); } SkullMeta meta = (SkullMeta) skull.getItemMeta(); @@ -388,7 +397,7 @@ public final class SlimefunGuide { pages.add(page); } - new CustomBookOverlay("Slimefun Guide", "TheBusyBiscuit", pages.toArray(new TellRawMessage[pages.size()])).open(p); + new CustomBookOverlay("Slimefun Guide", "TheBusyBiscuit", pages.toArray(new TellRawMessage[0])).open(p); } else { final ChestMenu menu = new ChestMenu("Slimefun Guide"); @@ -971,7 +980,7 @@ public final class SlimefunGuide { return false; }); } catch (Exception x) { - Slimefun.getLogger().log(Level.SEVERE, "An Error occured while adding a Wiki Page for Slimefun " + Slimefun.getVersion(), x); + Slimefun.getLogger().log(Level.SEVERE, "An Error occurred while adding a Wiki Page for Slimefun " + Slimefun.getVersion(), x); } } @@ -986,7 +995,7 @@ public final class SlimefunGuide { return false; }); } catch (Exception x) { - Slimefun.getLogger().log(Level.SEVERE, "An Error occured while adding a Youtube Video for Slimefun " + Slimefun.getVersion(), x); + Slimefun.getLogger().log(Level.SEVERE, "An Error occurred while adding a Youtube Video for Slimefun " + Slimefun.getVersion(), x); } } } From 334a1058b4d2c32b2f467e30c29bfef6597c9c07 Mon Sep 17 00:00:00 2001 From: J3fftw1 <44972470+J3fftw1@users.noreply.github.com> Date: Tue, 26 Nov 2019 19:16:39 +0100 Subject: [PATCH 2/4] merged latest master --- .../Slimefun/guides/ChestSlimefunGuide.java | 681 ++++++++++++++++++ .../Slimefun/guides/GuideSettings.java | 245 +++++++ 2 files changed, 926 insertions(+) create mode 100644 src/main/java/me/mrCookieSlime/Slimefun/guides/ChestSlimefunGuide.java create mode 100644 src/main/java/me/mrCookieSlime/Slimefun/guides/GuideSettings.java diff --git a/src/main/java/me/mrCookieSlime/Slimefun/guides/ChestSlimefunGuide.java b/src/main/java/me/mrCookieSlime/Slimefun/guides/ChestSlimefunGuide.java new file mode 100644 index 000000000..568edfebe --- /dev/null +++ b/src/main/java/me/mrCookieSlime/Slimefun/guides/ChestSlimefunGuide.java @@ -0,0 +1,681 @@ +package me.mrCookieSlime.Slimefun.guides; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.logging.Level; +import java.util.stream.Collectors; + +import org.bukkit.ChatColor; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.Recipe; +import org.bukkit.inventory.RecipeChoice; + +import io.github.thebusybiscuit.cscorelib2.chat.ChatInput; +import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; +import io.github.thebusybiscuit.cscorelib2.item.CustomItem; +import io.github.thebusybiscuit.cscorelib2.recipes.MinecraftRecipe; +import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu; +import me.mrCookieSlime.CSCoreLibPlugin.general.String.StringUtils; +import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull; +import me.mrCookieSlime.Slimefun.SlimefunGuide; +import me.mrCookieSlime.Slimefun.SlimefunPlugin; +import me.mrCookieSlime.Slimefun.Lists.RecipeType; +import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.Objects.LockedCategory; +import me.mrCookieSlime.Slimefun.Objects.Research; +import me.mrCookieSlime.Slimefun.Objects.SeasonalCategory; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.RecipeDisplayItem; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.multiblocks.MultiBlockMachine; +import me.mrCookieSlime.Slimefun.api.GuideHandler; +import me.mrCookieSlime.Slimefun.api.PlayerProfile; +import me.mrCookieSlime.Slimefun.api.Slimefun; + +public class ChestSlimefunGuide implements ISlimefunGuide { + + private static final int CATEGORY_SIZE = 36; + + @Override + public SlimefunGuideLayout getLayout() { + return SlimefunGuideLayout.CHEST; + } + + @Override + public ItemStack getItem() { + return new CustomItem(new ItemStack(Material.ENCHANTED_BOOK), "&aSlimefun Guide &7(Chest GUI)", "", "&eRight Click &8\u21E8 &7Browse Items", "&eShift + Right Click &8\u21E8 &7Open Settings / Credits"); + } + + @Override + public void openMainMenu(PlayerProfile profile, boolean survival, int page) { + Player p = profile.getPlayer(); + if (p == null) return; + + if (survival) { + profile.getGuideHistory().clear(); + } + + final ChestMenu menu = create(); + + List categories = SlimefunPlugin.getUtilities().enabledCategories; + List handlers = SlimefunPlugin.getUtilities().guideHandlers.values().stream().flatMap(List::stream).collect(Collectors.toList()); + + int index = 9; + int pages = 1; + + fillInv(profile, p, menu, survival); + + int target = (CATEGORY_SIZE * (page - 1)) - 1; + + while (target < (categories.size() + handlers.size() - 1)) { + if (index >= CATEGORY_SIZE + 9) { + pages++; + break; + } + + target++; + + if (target >= categories.size()) { + if (!survival) { + break; + } + + index = handlers.get(target - categories.size()).next(p, index, menu); + } + else { + Category category = categories.get(target); + boolean locked = true; + + for (SlimefunItem item: category.getItems()) { + if (Slimefun.isEnabled(p, item, false)) { + locked = false; + break; + } + } + + if (!locked) { + if (!(category instanceof LockedCategory)) { + if (!(category instanceof SeasonalCategory)) { + menu.addItem(index, category.getItem()); + menu.addMenuClickHandler(index, (pl, slot, item, action) -> { + openCategory(profile, category, survival, 1); + return false; + }); + index++; + } + else { + if (((SeasonalCategory) category).isUnlocked()) { + menu.addItem(index, category.getItem()); + menu.addMenuClickHandler(index, (pl, slot, item, action) -> { + openCategory(profile, category, survival, 1); + return false; + }); + index++; + } + } + } + else if (!survival || ((LockedCategory) category).hasUnlocked(p, profile)) { + menu.addItem(index, category.getItem()); + menu.addMenuClickHandler(index, (pl, slot, item, action) -> { + openCategory(profile, category, survival, 1); + return false; + }); + index++; + } + else { + List parents = new ArrayList<>(); + parents.add(""); + parents.add(ChatColor.translateAlternateColorCodes('&', "&rYou need to unlock all Items")); + parents.add(ChatColor.translateAlternateColorCodes('&', "&rfrom the following Categories first:")); + parents.add(""); + + for (Category parent : ((LockedCategory) category).getParents()) { + parents.add(parent.getItem().getItemMeta().getDisplayName()); + } + + menu.addItem(index, new CustomItem(Material.BARRIER, "&4LOCKED &7- &r" + category.getItem().getItemMeta().getDisplayName(), parents.toArray(new String[0]))); + menu.addMenuClickHandler(index, (pl, slot, item, action) -> false); + index++; + } + } + } + } + + final int finalPages = pages; + + menu.addItem(46, new CustomItem(new ItemStack(Material.LIME_STAINED_GLASS_PANE), "&r\u21E6 Previous Page", "", "&7(" + page + " / " + pages + ")")); + menu.addMenuClickHandler(46, (pl, slot, item, action) -> { + int next = page - 1; + if (next < 1) next = finalPages; + if (next != page) openMainMenu(profile, survival, next); + return false; + }); + + menu.addItem(52, new CustomItem(new ItemStack(Material.LIME_STAINED_GLASS_PANE), "&rNext Page \u21E8", "", "&7(" + page + " / " + pages + ")")); + menu.addMenuClickHandler(52, (pl, slot, item, action) -> { + int next = page + 1; + if (next > finalPages) next = 1; + if (next != page) openMainMenu(profile, survival, next); + return false; + }); + + menu.open(p); + } + + @Override + public void openCategory(PlayerProfile profile, Category category, boolean survival, int page) { + Player p = profile.getPlayer(); + if (p == null) return; + + if (survival) { + profile.getGuideHistory().add(category); + } + + final ChestMenu menu = create(); + + int index = 9; + final int pages = (category.getItems().size() - 1) / CATEGORY_SIZE + 1; + for (int i = 0; i < 4; i++) { + menu.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " ")); + menu.addMenuClickHandler(i, (pl, slot, item, action) -> false); + } + + menu.addItem(4, new CustomItem(new ItemStack(Material.ENCHANTED_BOOK), "&7\u21E6 Back")); + menu.addMenuClickHandler(4, (pl, slot, item, action) -> { + openMainMenu(profile, survival, 1); + return false; + }); + + for (int i = 5; i < 9; i++) { + menu.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " ")); + menu.addMenuClickHandler(i, (pl, slot, item, action) -> false); + } + + for (int i = 45; i < 54; i++) { + menu.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " ")); + menu.addMenuClickHandler(i, (pl, slot, item, action) -> false); + } + + menu.addItem(46, new CustomItem(new ItemStack(Material.LIME_STAINED_GLASS_PANE), "&r\u21E6 Previous Page", "", "&7(" + page + " / " + pages + ")")); + menu.addMenuClickHandler(46, (pl, slot, item, action) -> { + int next = page - 1; + if (next < 1) next = pages; + if (next != page) openCategory(profile, category, survival, next); + return false; + }); + + menu.addItem(52, new CustomItem(new ItemStack(Material.LIME_STAINED_GLASS_PANE), "&rNext Page \u21E8", "", "&7(" + page + " / " + pages + ")")); + menu.addMenuClickHandler(52, (pl, slot, item, action) -> { + int next = page + 1; + if (next > pages) next = 1; + if (next != page) openCategory(profile, category, survival, next); + return false; + }); + + int categoryIndex = CATEGORY_SIZE * (page - 1); + for (int i = 0; i < CATEGORY_SIZE; i++) { + int target = categoryIndex + i; + if (target >= category.getItems().size()) break; + final SlimefunItem sfitem = category.getItems().get(target); + + if (Slimefun.isEnabled(p, sfitem, false)) { + final Research research = sfitem.getResearch(); + if (survival && research != null && !profile.hasUnlocked(research)) { + if (Slimefun.hasPermission(p, sfitem, false)) { + menu.addItem(index, new CustomItem(Material.BARRIER, "&r" + ItemUtils.getItemName(sfitem.getItem()), "&4&lLOCKED", "", "&a> Click to unlock", "", "&7Cost: &b" + research.getCost() + " Level")); + menu.addMenuClickHandler(index, (pl, slot, item, action) -> { + if (!Research.isResearching(pl)) { + if (research.canUnlock(pl)) { + + if (profile.hasUnlocked(research)) { + openCategory(profile, category, true, page); + } + else { + if (!(pl.getGameMode() == GameMode.CREATIVE && SlimefunPlugin.getSettings().researchesFreeInCreative)) { + pl.setLevel(pl.getLevel() - research.getCost()); + } + + if (pl.getGameMode() == GameMode.CREATIVE) { + research.unlock(pl, SlimefunPlugin.getSettings().researchesFreeInCreative); + openCategory(profile, category, survival, page); + } + else { + research.unlock(pl, false); + Slimefun.runSync(() -> openCategory(profile, category, survival, page), 103L); + } + } + } + else SlimefunPlugin.getLocal().sendMessage(pl, "messages.not-enough-xp", true); + } + return false; + }); + + index++; + } + else { + List message = sfitem.getNoPermissionTooltip(); + menu.addItem(index, new CustomItem(Material.BARRIER, StringUtils.formatItemName(sfitem.getItem(), false), message.toArray(new String[message.size()]))); + menu.addMenuClickHandler(index, (pl, slot, item, action) -> false); + index++; + } + } + else { + menu.addItem(index, sfitem.getItem()); + menu.addMenuClickHandler(index, (pl, slot, item, action) -> { + if (survival) { + displayItem(profile, sfitem, true); + } + else { + if (sfitem instanceof MultiBlockMachine) { + SlimefunPlugin.getLocal().sendMessage(pl, "guide.cheat.no-multiblocks"); + } + else { + pl.getInventory().addItem(sfitem.getItem().clone()); + } + } + return false; + }); + index++; + } + } + } + + menu.open(p); + } + + @Override + public void openSearch(PlayerProfile profile, String input, boolean survival, boolean addToHistory) { + Player p = profile.getPlayer(); + if (p == null) return; + + final ChestMenu menu = new ChestMenu("Searching for: " + shorten("", input)); + String searchTerm = input.toLowerCase(); + + if (addToHistory) { + profile.getGuideHistory().add(searchTerm); + } + + menu.setEmptySlotsClickable(false); + fillInv(profile, p, menu, survival); + addBackButton(menu, 1, profile, survival); + + int index = 9; + // Find items and add them + for (SlimefunItem item : SlimefunItem.list()) { + final String itemName = ChatColor.stripColor(item.getItemName()).toLowerCase(); + + if (index == 44) break; + + if (!itemName.isEmpty()) { + if (itemName.equals(searchTerm) || itemName.contains(searchTerm)) { + menu.addItem(index, item.getItem()); + menu.addMenuClickHandler(index, (pl, slot, itm, action) -> { + if (!survival) { + pl.getInventory().addItem(item.getItem().clone()); + } + else { + displayItem(profile, item, true); + } + + return false; + }); + + index++; + } + } + } + + menu.open(p); + } + + @Override + public void displayItem(PlayerProfile profile, ItemStack item, boolean addToHistory) { + Player p = profile.getPlayer(); + if (p == null) return; + + if (item == null || item.getType() == Material.AIR) return; + + final SlimefunItem sfItem = SlimefunItem.getByItem(item); + + if (sfItem != null) { + displayItem(profile, sfItem, addToHistory); + return; + } + + if (!SlimefunPlugin.getSettings().guideShowVanillaRecipes) { + return; + } + + Set recipes = SlimefunPlugin.getMinecraftRecipes().getRecipesFor(item.getType()); + + ItemStack[] recipe = new ItemStack[9]; + RecipeType recipeType = null; + ItemStack result = null; + + for (Recipe r : recipes) { + Optional> optional = MinecraftRecipe.of(r); + + if (optional.isPresent()) { + MinecraftRecipe mcRecipe = optional.get(); + + RecipeChoice[] choices = SlimefunPlugin.getMinecraftRecipes().getRecipeInput(r); + + if (choices.length == 1) { + recipe[4] = choices[0].getItemStack(); + } + else { + for (int i = 0; i < choices.length; i++) { + if (choices[i] != null) { + recipe[i] = choices[i].getItemStack(); + } + } + } + + if (mcRecipe == MinecraftRecipe.SHAPED_CRAFTING) { + recipeType = new RecipeType(new CustomItem(mcRecipe.getMachine(), null, "&7Shaped Recipe")); + } + else if (mcRecipe == MinecraftRecipe.SHAPELESS_CRAFTING) { + recipeType = new RecipeType(new CustomItem(mcRecipe.getMachine(), null, "&7Shapeless Recipe")); + } + else { + recipeType = new RecipeType(mcRecipe); + } + + result = r.getResult(); + + break; + } + } + + if (recipeType == null) { + return; + } + + ChestMenu menu = create(); + displayItem(menu, profile, p, item, result, recipeType, recipe, addToHistory); + menu.open(p); + } + + @Override + public void displayItem(PlayerProfile profile, SlimefunItem item, boolean addToHistory) { + Player p = profile.getPlayer(); + if (p == null) return; + + ItemStack result = item.getRecipeOutput() != null ? item.getRecipeOutput(): item.getItem(); + RecipeType recipeType = item.getRecipeType(); + ItemStack[] recipe = item.getRecipe(); + + ChestMenu menu = create(); + + if (item.hasWiki()) { + try { + menu.addItem(8, new CustomItem(Material.KNOWLEDGE_BOOK, "&rView this Item on our Wiki &7(Slimefun Wiki)", "", "&7\u21E8 Click to open")); + menu.addMenuClickHandler(8, (pl, slot, itemstack, action) -> { + pl.closeInventory(); + pl.sendMessage(""); + pl.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7&o" + item.getWiki())); + pl.sendMessage(""); + return false; + }); + } catch (Exception x) { + Slimefun.getLogger().log(Level.SEVERE, "An Error occurred while adding a Wiki Page for Slimefun " + Slimefun.getVersion(), x); + } + } + + if (Slimefun.getItemConfig().contains(item.getID() + ".youtube")) { + try { + menu.addItem(7, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjQzNTNmZDBmODYzMTQzNTM4NzY1ODYwNzViOWJkZjBjNDg0YWFiMDMzMWI4NzJkZjExYmQ1NjRmY2IwMjllZCJ9fX0="), "&rDemonstration Video &7(Youtube)", "", "&7\u21E8 Click to watch")); + menu.addMenuClickHandler(7, (pl, slot, itemstack, action) -> { + pl.closeInventory(); + pl.sendMessage(""); + pl.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7&o" + Slimefun.getItemConfig().getString(item.getID() + ".youtube"))); + pl.sendMessage(""); + return false; + }); + } catch (Exception x) { + Slimefun.getLogger().log(Level.SEVERE, "An Error occurred while adding a Youtube Video for Slimefun " + Slimefun.getVersion(), x); + } + } + + displayItem(menu, profile, p, item, result, recipeType, recipe, addToHistory); + + if (item instanceof RecipeDisplayItem) { + displayRecipes(profile, menu, (RecipeDisplayItem) item, 0); + } + + menu.open(p); + } + + private void displayItem(ChestMenu menu, PlayerProfile profile, Player p, Object obj, ItemStack output, RecipeType recipeType, ItemStack[] recipe, boolean addToHistory) { + LinkedList history = profile.getGuideHistory(); + boolean isSlimefunRecipe = obj instanceof SlimefunItem; + + if (addToHistory) { + history.add(obj); + } + + addBackButton(menu, 0, profile, true); + + menu.addItem(3, getDisplayItem(p, isSlimefunRecipe, recipe[0])); + menu.addMenuClickHandler(3, (pl, slot, itemstack, action) -> { + displayItem(profile, itemstack, true); + return false; + }); + + menu.addItem(4, getDisplayItem(p, isSlimefunRecipe, recipe[1])); + menu.addMenuClickHandler(4, (pl, slot, itemstack, action) -> { + displayItem(profile, itemstack, true); + return false; + }); + + menu.addItem(5, getDisplayItem(p, isSlimefunRecipe, recipe[2])); + menu.addMenuClickHandler(5, (pl, slot, itemstack, action) -> { + displayItem(profile, itemstack, true); + return false; + }); + + menu.addItem(10, recipeType.toItem()); + menu.addMenuClickHandler(10, (pl, slot, itemstack, action) -> false); + + menu.addItem(12, getDisplayItem(p, isSlimefunRecipe, recipe[3])); + menu.addMenuClickHandler(12, (pl, slot, itemstack, action) -> { + displayItem(profile, itemstack, true); + return false; + }); + + menu.addItem(13, getDisplayItem(p, isSlimefunRecipe, recipe[4])); + menu.addMenuClickHandler(13, (pl, slot, itemstack, action) -> { + displayItem(profile, itemstack, true); + return false; + }); + + menu.addItem(14, getDisplayItem(p, isSlimefunRecipe, recipe[5])); + menu.addMenuClickHandler(14, (pl, slot, itemstack, action) -> { + displayItem(profile, itemstack, true); + return false; + }); + + menu.addItem(16, output); + menu.addMenuClickHandler(16, (pl, slot, itemstack, action) -> false); + + menu.addItem(21, getDisplayItem(p, isSlimefunRecipe, recipe[6])); + menu.addMenuClickHandler(21, (pl, slot, itemstack, action) -> { + displayItem(profile, itemstack, true); + return false; + }); + + menu.addItem(22, getDisplayItem(p, isSlimefunRecipe, recipe[7])); + menu.addMenuClickHandler(22, (pl, slot, itemstack, action) -> { + displayItem(profile, itemstack, true); + return false; + }); + + menu.addItem(23, getDisplayItem(p, isSlimefunRecipe, recipe[8])); + menu.addMenuClickHandler(23, (pl, slot, itemstack, action) -> { + displayItem(profile, itemstack, true); + return false; + }); + } + + private void fillInv(PlayerProfile profile, Player p, ChestMenu menu, boolean survival) { + for (int i = 0; i < 9; i++) { + menu.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " ")); + menu.addMenuClickHandler(i, (pl, s, itemstack, action) -> false); + } + + // Settings Panel + menu.addItem(1, new CustomItem(SlimefunGuide.getItem(SlimefunGuideLayout.CHEST), "&eSettings / Info", "", "&7\u21E8 Click to see more")); + menu.addMenuClickHandler(1, (player, i, itemStack, clickAction) -> { + GuideSettings.openSettings(player, player.getInventory().getItemInMainHand()); + return false; + }); + + /* + // Stats + menu.addItem(4, new CustomItem(SkullItem.fromPlayer(p), "&7Player Stats: &e" + p.getName(), "", "&7Progress: &a" + Math.round(((profile.getResearches().size() * 100.0F) / Research.list().size()) * 100.0F) / 100.0F + "% &e(" + profile.getResearches().size() + " / " + Research.list().size() + ")", "", "&7\u21E8 Click for a full summary")); + menu.addMenuClickHandler(4, (player, i, itemStack, clickAction) -> { + player.closeInventory(); + profile.sendStats(player); + return false; + }); + */ + + // Search feature! + menu.addItem(7, new CustomItem(Material.NAME_TAG, SlimefunPlugin.getLocal().getMessage("guide.search.name"), SlimefunPlugin.getLocal().getMessagesArray("guide.search.lore"))); + menu.addMenuClickHandler(7, (player, i, itemStack, clickAction) -> { + player.closeInventory(); + SlimefunPlugin.getLocal().sendMessage(player, "search.message"); + + ChatInput.waitForPlayer(SlimefunPlugin.instance, player, msg -> + SlimefunGuide.openSearch(profile, msg, survival, true) + ); + + return false; + }); + + for (int i = 45; i < 54; i++) { + menu.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " ")); + menu.addMenuClickHandler(i, (pl, s, itemstack, action) -> false); + } + } + + private void addBackButton(ChestMenu menu, int slot, PlayerProfile profile, boolean survival) { + List playerHistory = profile.getGuideHistory(); + + if (playerHistory.size() > 1) { + + menu.addItem(slot, new CustomItem(new ItemStack(Material.ENCHANTED_BOOK), + "&7\u21E6 Back", "", + "&rLeft Click: &7Go back to previous Page", + "&rShift + left Click: &7Go back to Main Menu") + ); + + menu.addMenuClickHandler(slot, (pl, s, is, action) -> { + if (action.isShiftClicked()) { + openMainMenu(profile, survival, 1); + } + else { + Object last = getLastEntry(profile, true); + handleHistory(profile, last, survival); + } + return false; + }); + + } + else { + menu.addItem(slot, new CustomItem(new ItemStack(Material.ENCHANTED_BOOK), "&7\u21E6 Back", "", "&rLeft Click: &7Go back to Main Menu")); + menu.addMenuClickHandler(slot, (pl, s, is, action) -> { + openMainMenu(profile, survival, 1); + return false; + }); + } + } + + private static ItemStack getDisplayItem(Player p, boolean isSlimefunRecipe, ItemStack item) { + if (isSlimefunRecipe) { + SlimefunItem slimefunItem = SlimefunItem.getByItem(item); + if (slimefunItem == null) return item; + + String lore = Slimefun.hasPermission(p, slimefunItem, false) ? "&rNeeds to be unlocked elsewhere" : "&rNo Permission"; + return Slimefun.hasUnlocked(p, slimefunItem, false) ? item: new CustomItem(Material.BARRIER, ItemUtils.getItemName(item), "&4&lLOCKED", "", lore); + } + else { + return item; + } + } + + private void displayRecipes(PlayerProfile profile, ChestMenu menu, RecipeDisplayItem sfItem, int page) { + List recipes = sfItem.getDisplayRecipes(); + + if (!recipes.isEmpty()) { + menu.addItem(53, null); + + if (page == 0) { + for (int i = 27; i < 36; i++) { + menu.replaceExistingItem(i, new CustomItem(Material.GRAY_STAINED_GLASS_PANE, sfItem.getRecipeSectionLabel())); + menu.addMenuClickHandler(i, (pl, slot, itemstack, action) -> false); + } + } + else { + menu.replaceExistingItem(28, new CustomItem(Material.LIME_STAINED_GLASS_PANE, "&a\u21E6 Previous Page")); + menu.addMenuClickHandler(28, (pl, slot, itemstack, action) -> { + displayRecipes(profile, menu, sfItem, page - 1); + pl.playSound(pl.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1, 1); + return false; + }); + } + + if (recipes.size() > (18 * (page + 1))) { + menu.replaceExistingItem(34, new CustomItem(Material.LIME_STAINED_GLASS_PANE, "&aNext Page \u21E8")); + menu.addMenuClickHandler(34, (pl, slot, itemstack, action) -> { + displayRecipes(profile, menu, sfItem, page + 1); + pl.playSound(pl.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1, 1); + return false; + }); + } + else { + menu.replaceExistingItem(34, new CustomItem(Material.GRAY_STAINED_GLASS_PANE, sfItem.getRecipeSectionLabel())); + menu.addMenuClickHandler(34, (pl, slot, itemstack, action) -> false); + } + + int inputs = 36; + int outputs = 45; + + for (int i = 0; i < 18; i++) { + int slot = i % 2 == 0 ? inputs++: outputs++; + + if ((i + (page * 18)) < recipes.size()) { + if (page == 0) { + menu.replaceExistingItem(slot, recipes.get(i + (page * 18))); + menu.addMenuClickHandler(slot, (pl, s, itemstack, action) -> { + displayItem(profile, itemstack, true); + return false; + }); + } + else { + menu.replaceExistingItem(slot, recipes.get(i + (page * 18))); + } + } + else { + menu.replaceExistingItem(slot, null); + menu.addMenuClickHandler(slot, (pl, s, itemstack, action) -> false); + } + } + } + } + + private static ChestMenu create() { + ChestMenu menu = new ChestMenu("Slimefun Guide"); + + menu.setEmptySlotsClickable(false); + menu.addMenuOpeningHandler(pl -> pl.playSound(pl.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1, 1)); + return menu; + } + +} diff --git a/src/main/java/me/mrCookieSlime/Slimefun/guides/GuideSettings.java b/src/main/java/me/mrCookieSlime/Slimefun/guides/GuideSettings.java new file mode 100644 index 000000000..67f938dc1 --- /dev/null +++ b/src/main/java/me/mrCookieSlime/Slimefun/guides/GuideSettings.java @@ -0,0 +1,245 @@ +package me.mrCookieSlime.Slimefun.guides; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; + +import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.SkullMeta; + +import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; +import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu; +import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem; +import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull; +import me.mrCookieSlime.Slimefun.SlimefunGuide; +import me.mrCookieSlime.Slimefun.SlimefunPlugin; +import me.mrCookieSlime.Slimefun.Setup.SlimefunManager; +import me.mrCookieSlime.Slimefun.api.Slimefun; +import me.mrCookieSlime.Slimefun.hooks.github.Contributor; +import me.mrCookieSlime.Slimefun.hooks.github.IntegerFormat; +import me.mrCookieSlime.Slimefun.utils.ChatUtils; + +public final class GuideSettings { + + private static final int[] SLOTS = new int[] {0, 2, 4, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35}; + + private GuideSettings() {} + + public static void openSettings(Player p, final ItemStack guide) { + final ChestMenu menu = new ChestMenu("Settings / Info"); + + menu.setEmptySlotsClickable(false); + menu.addMenuOpeningHandler(pl -> pl.playSound(pl.getLocation(), Sound.BLOCK_NOTE_BLOCK_HARP, 0.7F, 0.7F)); + + menu.addItem(1, new CustomItem(getItem(SlimefunGuideLayout.CHEST), "&e\u21E6 Back", "", "&7Go back to your Slimefun Guide")); + menu.addMenuClickHandler(1, (pl, slot, item, action) -> { + SlimefunGuide.openGuide(pl, guide); + return false; + }); + + for (int i: SLOTS) { + menu.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " ")); + menu.addMenuClickHandler(i, (pl, slot, item, action) -> false); + } + + if (SlimefunManager.isItemSimiliar(guide, getItem(SlimefunGuideLayout.CHEST), true)) { + if (p.hasPermission("slimefun.cheat.items")) { + menu.addItem(19, new CustomItem(new ItemStack(Material.CHEST), "&7Guide Layout: &eChest GUI", "", "&aChest GUI", "&7Book GUI", "&7Cheat Sheet", "", "&e Click &8\u21E8 &7Change Layout")); + menu.addMenuClickHandler(19, (pl, slot, item, action) -> { + pl.getInventory().setItemInMainHand(getItem(SlimefunGuideLayout.BOOK)); + openSettings(pl, pl.getInventory().getItemInMainHand()); + return false; + }); + } + else { + menu.addItem(19, new CustomItem(new ItemStack(Material.CHEST), "&7Guide Layout: &eChest GUI", "", "&aChest GUI", "&7Book GUI", "", "&e Click &8\u21E8 &7Change Layout")); + menu.addMenuClickHandler(19, (pl, slot, item, action) -> { + pl.getInventory().setItemInMainHand(getItem(SlimefunGuideLayout.BOOK)); + openSettings(pl, pl.getInventory().getItemInMainHand()); + return false; + }); + } + } + else if (SlimefunManager.isItemSimiliar(guide, getItem(SlimefunGuideLayout.BOOK), true)) { + if (p.hasPermission("slimefun.cheat.items")) { + menu.addItem(19, new CustomItem(new ItemStack(Material.BOOK), "&7Guide Layout: &eBook GUI", "", "&7Chest GUI", "&aBook GUI", "&7Cheat Sheet", "", "&e Click &8\u21E8 &7Change Layout")); + menu.addMenuClickHandler(19, (pl, slot, item, action) -> { + pl.getInventory().setItemInMainHand(getItem(SlimefunGuideLayout.CHEAT_SHEET)); + openSettings(pl, pl.getInventory().getItemInMainHand()); + return false; + }); + } + else { + menu.addItem(19, new CustomItem(new ItemStack(Material.BOOK), "&7Guide Layout: &eBook GUI", "", "&7Chest GUI", "&aBook GUI", "", "&e Click &8\u21E8 &7Change Layout")); + menu.addMenuClickHandler(19, (pl, slot, item, action) -> { + pl.getInventory().setItemInMainHand(getItem(SlimefunGuideLayout.CHEST)); + openSettings(pl, pl.getInventory().getItemInMainHand()); + return false; + }); + } + } + else if (SlimefunManager.isItemSimiliar(guide, getItem(SlimefunGuideLayout.CHEAT_SHEET), true)) { + menu.addItem(19, new CustomItem(new ItemStack(Material.COMMAND_BLOCK), "&7Guide Layout: &eCheat Sheet", "", "&7Chest GUI", "&7Book GUI", "&aCheat Sheet", "", "&e Click &8\u21E8 &7Change Layout")); + menu.addMenuClickHandler(19, (pl, slot, item, action) -> { + pl.getInventory().setItemInMainHand(getItem(SlimefunGuideLayout.CHEST)); + openSettings(pl, pl.getInventory().getItemInMainHand()); + return false; + }); + } + + menu.addItem(3, new CustomItem(new ItemStack(Material.WRITABLE_BOOK), + "&aCredits", + "", + "&7Slimefun Version: &a" + Slimefun.getVersion(), + "&7CSCore-Lib Version: &a" + CSCoreLib.getLib().getDescription().getVersion(), + "&7Installed Addons: &b" + Slimefun.getInstalledAddons().size(), + "&7Contributors: &e" + SlimefunPlugin.getUtilities().contributors.size(), + "", + "&7\u21E8 Click to see the people behind this Plugin" + )); + menu.addMenuClickHandler(3, (pl, slot, item, action) -> { + openCredits(pl, 0); + return false; + }); + + try { + menu.addItem(5, new CustomItem(new ItemStack(Material.COMPARATOR), "&eSource Code", "", "&7Bytes of Code: &6" + IntegerFormat.formatBigNumber(SlimefunPlugin.getUtilities().codeBytes), "&7Last Update: &a" + IntegerFormat.timeDelta(SlimefunPlugin.getUtilities().lastUpdate) + " ago", "&7Forks: &e" + SlimefunPlugin.getUtilities().forks, "&7Stars: &e" + SlimefunPlugin.getUtilities().stars, "", "&7&oSlimefun 4 is a community project,", "&7&othe source code is available on GitHub", "&7&oand if you want to keep this Plugin alive,", "&7&othen please consider contributing to it", "", "&7\u21E8 Click to go to GitHub")); + menu.addMenuClickHandler(5, (pl, slot, item, action) -> { + pl.closeInventory(); + ChatUtils.sendURL(pl, "https://github.com/TheBusyBiscuit/Slimefun4"); + return false; + }); + } catch (Exception x) { + Slimefun.getLogger().log(Level.SEVERE, "An Error occured while creating the Info-Panel for Slimefun " + Slimefun.getVersion(), x); + } + + menu.addItem(7, new CustomItem(new ItemStack(Material.KNOWLEDGE_BOOK), "&3Slimefun Wiki", "", "&7Do you need help with an Item or machine?", "&7You cannot figure out what to do?", "&7Check out our community-maintained Wiki", "&7and become one of our Editors!", "", "&7\u21E8 Click to go to the official Slimefun Wiki")); + menu.addMenuClickHandler(7, (pl, slot, item, action) -> { + pl.closeInventory(); + ChatUtils.sendURL(pl, "https://github.com/TheBusyBiscuit/Slimefun4/wiki"); + return false; + }); + + menu.addItem(20, new CustomItem(new ItemStack(Material.REDSTONE), "&4Report a bug", "", "&7Open Issues: &a" + SlimefunPlugin.getUtilities().issues, "&7Pending Pull Requests: &a" + SlimefunPlugin.getUtilities().prs, "", "&7\u21E8 Click to go to the Slimefun Bug Tracker")); + menu.addMenuClickHandler(20, (pl, slot, item, action) -> { + pl.closeInventory(); + ChatUtils.sendURL(pl, "https://github.com/TheBusyBiscuit/Slimefun4/issues"); + return false; + }); + + // TODO: Resourcepack Install Button + + menu.open(p); + } + + private static void openCredits(Player p, int page) { + final ChestMenu menu = new ChestMenu("Credits"); + + menu.setEmptySlotsClickable(false); + menu.addMenuOpeningHandler(pl -> pl.playSound(pl.getLocation(), Sound.BLOCK_NOTE_BLOCK_HARP, 0.7F, 0.7F)); + + for (int i = 0; i < 9; i++) { + if (i != 1) { + menu.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " ")); + menu.addMenuClickHandler(i, (pl, slot, item, action) -> false); + } + else { + menu.addItem(1, new CustomItem(getItem(SlimefunGuideLayout.CHEST), "&e\u21E6 Back", "", "&7Go back to the Settings Panel")); + menu.addMenuClickHandler(1, (pl, slot, item, action) -> { + openSettings(pl, p.getInventory().getItemInMainHand()); + return false; + }); + } + } + + for (int i = 45; i < 54; i++) { + if (i != 46 && i != 52) { + menu.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " ")); + menu.addMenuClickHandler(i, (pl, slot, item, action) -> false); + } + } + + List contributors = new ArrayList<>(SlimefunPlugin.getUtilities().contributors.values()); + contributors.sort(Comparator.comparingInt(Contributor::index)); + + boolean hasPrevious = page > 0; + boolean hasNext = false; + + for (int i = page * 36; i < contributors.size(); i++) { + if (i >= (page + 1) * 36) { + hasNext = true; + break; + } + + Contributor contributor = contributors.get(i); + ItemStack skull = new ItemStack(Material.PLAYER_HEAD); + + try { + skull = CustomSkull.getItem(contributor.getTexture()); + } catch (Exception e) { + Slimefun.getLogger().log(Level.SEVERE, "An Error occured while inserting a Contributors head.", e); + } + + SkullMeta meta = (SkullMeta) skull.getItemMeta(); + meta.setDisplayName(ChatColor.GRAY + contributor.getName()); + + List lore = new LinkedList<>(); + lore.add(""); + + for (Map.Entry entry: contributor.getContributions().entrySet()) { + lore.add(ChatColors.color(entry.getKey() + " &7(" + entry.getValue() + " Commit" + (entry.getValue() > 1 ? "s": "") + ")")); + } + + lore.add(""); + lore.add("&7\u21E8 Click to visit " + contributor.getName() + "'s profile"); + meta.setLore(lore); + skull.setItemMeta(meta); + + menu.addItem(i + 9, skull); + menu.addMenuClickHandler(i + 9, (pl, slot, item, action) -> { + pl.closeInventory(); + ChatUtils.sendURL(pl, contributor.getProfile()); + return false; + }); + } + + if (hasPrevious) { + menu.addItem(46, new CustomItem(Material.LIME_STAINED_GLASS_PANE, "&e<- Previous")); + menu.addMenuClickHandler(46, (pl, slot, item, action) -> { + openCredits(pl, page - 1); + return false; + }); + } + else { + menu.addItem(46, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " ")); + menu.addMenuClickHandler(46, (pl, slot, item, action) -> false); + } + + if (hasNext) { + menu.addItem(52, new CustomItem(Material.LIME_STAINED_GLASS_PANE, "&e<- Previous")); + menu.addMenuClickHandler(52, (pl, slot, item, action) -> { + openCredits(pl, page + 1); + return false; + }); + } + else { + menu.addItem(52, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " ")); + menu.addMenuClickHandler(52, (pl, slot, item, action) -> false); + } + + menu.open(p); + } + + private static ItemStack getItem(SlimefunGuideLayout layout) { + return SlimefunGuide.getItem(layout); + } + +} From 23202d1cd68bb46027d8ed985bf913e498f83ed4 Mon Sep 17 00:00:00 2001 From: J3fftw1 <44972470+J3fftw1@users.noreply.github.com> Date: Tue, 26 Nov 2019 19:29:13 +0100 Subject: [PATCH 3/4] few more fixes --- .../java/me/mrCookieSlime/Slimefun/guides/GuideSettings.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/mrCookieSlime/Slimefun/guides/GuideSettings.java b/src/main/java/me/mrCookieSlime/Slimefun/guides/GuideSettings.java index 92a464e43..f290877c3 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/guides/GuideSettings.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/guides/GuideSettings.java @@ -7,6 +7,7 @@ import java.util.List; import java.util.Map; import java.util.logging.Level; +import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.Sound; @@ -99,7 +100,7 @@ public final class GuideSettings { "&aCredits", "", "&7Slimefun Version: &a" + Slimefun.getVersion(), - "&7CSCore-Lib Version: &a" + CSCoreLib.getLib().getDescription().getVersion(), + "&7CS-CoreLib Version: &a" + CSCoreLib.getLib().getDescription().getVersion(), "&7Installed Addons: &b" + Slimefun.getInstalledAddons().size(), "&7Contributors: &e" + SlimefunPlugin.getUtilities().contributors.size(), "", From eea32be7dd4c682695b983bc5051bcfce57c5a5b Mon Sep 17 00:00:00 2001 From: J3fftw1 <44972470+J3fftw1@users.noreply.github.com> Date: Tue, 26 Nov 2019 19:30:52 +0100 Subject: [PATCH 4/4] removed empty lines --- .../me/mrCookieSlime/Slimefun/guides/ChestSlimefunGuide.java | 4 ---- .../java/me/mrCookieSlime/Slimefun/guides/GuideSettings.java | 2 -- 2 files changed, 6 deletions(-) diff --git a/src/main/java/me/mrCookieSlime/Slimefun/guides/ChestSlimefunGuide.java b/src/main/java/me/mrCookieSlime/Slimefun/guides/ChestSlimefunGuide.java index 360d76d37..568edfebe 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/guides/ChestSlimefunGuide.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/guides/ChestSlimefunGuide.java @@ -424,9 +424,7 @@ public class ChestSlimefunGuide implements ISlimefunGuide { return false; }); } catch (Exception x) { - Slimefun.getLogger().log(Level.SEVERE, "An Error occurred while adding a Wiki Page for Slimefun " + Slimefun.getVersion(), x); - } } @@ -441,9 +439,7 @@ public class ChestSlimefunGuide implements ISlimefunGuide { return false; }); } catch (Exception x) { - Slimefun.getLogger().log(Level.SEVERE, "An Error occurred while adding a Youtube Video for Slimefun " + Slimefun.getVersion(), x); - } } diff --git a/src/main/java/me/mrCookieSlime/Slimefun/guides/GuideSettings.java b/src/main/java/me/mrCookieSlime/Slimefun/guides/GuideSettings.java index f290877c3..a1002ad95 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/guides/GuideSettings.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/guides/GuideSettings.java @@ -95,7 +95,6 @@ public final class GuideSettings { }); } - menu.addItem(3, new CustomItem(new ItemStack(Material.WRITABLE_BOOK), "&aCredits", "", @@ -106,7 +105,6 @@ public final class GuideSettings { "", "&7\u21E8 Click to see the people behind this Plugin" )); - menu.addMenuClickHandler(3, (pl, slot, item, action) -> { openCredits(pl, 0); return false;