1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-21 20:25:54 +00:00
Slimefun4/src/main/java/me/mrCookieSlime/Slimefun/SlimefunGuide.java

124 lines
5.0 KiB
Java
Raw Normal View History

2016-04-14 16:24:03 +00:00
package me.mrCookieSlime.Slimefun;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
2019-10-20 14:41:28 +00:00
import java.util.Map;
2019-10-16 23:08:14 +00:00
import java.util.Optional;
2016-04-14 16:24:03 +00:00
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
2019-11-24 12:23:16 +00:00
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
2019-12-12 00:45:55 +00:00
import io.github.thebusybiscuit.slimefun4.core.guide.BookSlimefunGuide;
import io.github.thebusybiscuit.slimefun4.core.guide.ChestSlimefunGuide;
import io.github.thebusybiscuit.slimefun4.core.guide.ISlimefunGuide;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout;
2016-04-14 16:24:03 +00:00
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
import me.mrCookieSlime.Slimefun.api.PlayerProfile;
2016-04-14 16:24:03 +00:00
import me.mrCookieSlime.Slimefun.api.Slimefun;
2019-08-27 21:08:13 +00:00
public final class SlimefunGuide {
2019-10-11 21:48:46 +00:00
2019-08-27 21:08:13 +00:00
private SlimefunGuide() {}
2020-01-11 19:58:14 +00:00
2019-10-20 14:41:28 +00:00
static {
Map<SlimefunGuideLayout, ISlimefunGuide> layouts = SlimefunPlugin.getUtilities().guideLayouts;
ISlimefunGuide chestGuide = new ChestSlimefunGuide();
layouts.put(SlimefunGuideLayout.CHEST, chestGuide);
layouts.put(SlimefunGuideLayout.CHEAT_SHEET, chestGuide);
layouts.put(SlimefunGuideLayout.BOOK, new BookSlimefunGuide());
}
2020-01-11 19:58:14 +00:00
2019-08-31 09:36:45 +00:00
public static ItemStack getItem(SlimefunGuideLayout design) {
ItemStack item = new ItemStack(Material.ENCHANTED_BOOK);
ItemMeta meta = item.getItemMeta();
List<String> lore = new LinkedList<>();
2019-11-24 12:23:16 +00:00
lore.addAll(Arrays.asList("", ChatColors.color("&eRight Click &8\u21E8 &7Browse Items"), ChatColors.color("&eShift + Right Click &8\u21E8 &7Open Settings / Credits")));
2020-01-11 19:58:14 +00:00
switch (design) {
2019-08-25 21:20:31 +00:00
case BOOK:
2019-11-24 12:23:16 +00:00
meta.setDisplayName(ChatColors.color("&aSlimefun Guide &7(Book GUI)"));
break;
2019-08-25 21:20:31 +00:00
case CHEAT_SHEET:
2019-11-24 12:23:16 +00:00
meta.setDisplayName(ChatColors.color("&cSlimefun Guide &4(Cheat Sheet)"));
lore.add(0, ChatColors.color("&4&lOnly openable by Admins"));
lore.add(0, "");
break;
2019-08-25 21:20:31 +00:00
case CHEST:
2019-11-24 12:23:16 +00:00
meta.setDisplayName(ChatColors.color("&aSlimefun Guide &7(Chest GUI)"));
break;
default:
return null;
}
2020-01-11 19:58:14 +00:00
meta.setLore(lore);
SlimefunPlugin.getItemTextureService().setTexture(meta, "SLIMEFUN_GUIDE");
item.setItemMeta(meta);
return item;
}
2019-11-24 12:23:16 +00:00
public static void openCheatMenu(Player p) {
openMainMenuAsync(p, false, SlimefunGuideLayout.CHEAT_SHEET, 1);
}
2019-10-11 21:48:46 +00:00
2019-11-24 12:23:16 +00:00
public static void openGuide(Player p, ItemStack guide) {
if (SlimefunManager.isItemSimilar(guide, getItem(SlimefunGuideLayout.CHEST), true)) {
2019-11-24 12:23:16 +00:00
openGuide(p, SlimefunGuideLayout.CHEST);
}
else if (SlimefunManager.isItemSimilar(guide, getItem(SlimefunGuideLayout.BOOK), true)) {
2019-11-24 12:23:16 +00:00
openGuide(p, SlimefunGuideLayout.BOOK);
}
else if (SlimefunManager.isItemSimilar(guide, getItem(SlimefunGuideLayout.CHEAT_SHEET), true)) {
2019-11-24 12:23:16 +00:00
openGuide(p, SlimefunGuideLayout.CHEAT_SHEET);
}
2019-10-20 14:41:28 +00:00
}
public static void openGuide(Player p, SlimefunGuideLayout layout) {
2019-08-31 09:36:45 +00:00
if (!SlimefunPlugin.getWhitelist().getBoolean(p.getWorld().getName() + ".enabled")) return;
if (!SlimefunPlugin.getWhitelist().getBoolean(p.getWorld().getName() + ".enabled-items.SLIMEFUN_GUIDE")) return;
2019-10-11 21:48:46 +00:00
2019-10-20 14:41:28 +00:00
ISlimefunGuide guide = SlimefunPlugin.getUtilities().guideLayouts.get(layout);
2019-10-16 23:08:14 +00:00
Object last = null;
2020-01-11 19:58:14 +00:00
2019-10-16 23:08:14 +00:00
Optional<PlayerProfile> profile = PlayerProfile.find(p);
if (profile.isPresent()) {
2019-10-20 14:41:28 +00:00
last = guide.getLastEntry(profile.get(), false);
guide.handleHistory(profile.get(), last, true);
2016-04-14 16:24:03 +00:00
}
else {
2019-10-20 14:41:28 +00:00
openMainMenuAsync(p, true, layout, 1);
2019-09-27 19:40:51 +00:00
}
}
2020-01-06 19:04:39 +00:00
private static void openMainMenuAsync(Player player, boolean survival, SlimefunGuideLayout layout, int selectedPage) {
if (!PlayerProfile.get(player, profile -> Slimefun.runSync(() -> openMainMenu(profile, layout, survival, selectedPage))))
SlimefunPlugin.getLocal().sendMessage(player, "messages.opening-guide");
2019-09-27 19:40:51 +00:00
}
2020-01-06 19:04:39 +00:00
public static void openMainMenu(PlayerProfile profile, SlimefunGuideLayout layout, boolean survival, int selectedPage) {
SlimefunPlugin.getUtilities().guideLayouts.get(layout).openMainMenu(profile, survival, selectedPage);
2016-04-14 16:24:03 +00:00
}
2019-03-27 20:41:29 +00:00
2020-01-06 19:04:39 +00:00
public static void openCategory(PlayerProfile profile, Category category, SlimefunGuideLayout layout, boolean survival, int selectedPage) {
2019-10-20 14:41:28 +00:00
if (category == null) return;
2020-01-06 19:04:39 +00:00
SlimefunPlugin.getUtilities().guideLayouts.get(layout).openCategory(profile, category, survival, selectedPage);
}
2019-09-27 19:40:51 +00:00
2020-01-11 22:03:35 +00:00
public static void openSearch(PlayerProfile profile, String input, boolean survival, boolean addToHistory) {
2019-10-20 14:41:28 +00:00
SlimefunPlugin.getUtilities().guideLayouts.get(SlimefunGuideLayout.CHEST).openSearch(profile, input, survival, addToHistory);
}
2020-01-06 19:04:39 +00:00
public static void displayItem(PlayerProfile profile, ItemStack item, boolean addToHistory) {
2019-10-20 14:41:28 +00:00
SlimefunPlugin.getUtilities().guideLayouts.get(SlimefunGuideLayout.CHEST).displayItem(profile, item, addToHistory);
2019-09-27 19:40:51 +00:00
}
2020-01-06 19:04:39 +00:00
public static void displayItem(PlayerProfile profile, SlimefunItem item, boolean addToHistory) {
2019-10-20 14:41:28 +00:00
SlimefunPlugin.getUtilities().guideLayouts.get(SlimefunGuideLayout.CHEST).displayItem(profile, item, addToHistory);
2016-04-14 16:24:03 +00:00
}
}