2016-04-14 16:24:03 +00:00
package me.mrCookieSlime.Slimefun ;
2017-01-15 18:17:02 +00:00
import java.util.Arrays ;
2019-11-22 13:57:04 +00:00
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
2017-01-15 18:17:02 +00:00
import org.bukkit.Material ;
import org.bukkit.entity.Player ;
import org.bukkit.inventory.ItemStack ;
2019-11-22 13:57:04 +00:00
import org.bukkit.inventory.meta.ItemMeta ;
2017-01-15 18:17:02 +00:00
2019-11-24 12:23:16 +00:00
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors ;
2016-04-14 16:24:03 +00:00
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem ;
import me.mrCookieSlime.Slimefun.Objects.Category ;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem ;
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager ;
2019-08-25 14:07:06 +00:00
import me.mrCookieSlime.Slimefun.api.PlayerProfile ;
2016-04-14 16:24:03 +00:00
import me.mrCookieSlime.Slimefun.api.Slimefun ;
2019-10-20 14:41:28 +00:00
import me.mrCookieSlime.Slimefun.guides.BookSlimefunGuide ;
import me.mrCookieSlime.Slimefun.guides.ChestSlimefunGuide ;
import me.mrCookieSlime.Slimefun.guides.ISlimefunGuide ;
import me.mrCookieSlime.Slimefun.guides.SlimefunGuideLayout ;
2016-04-14 16:24:03 +00:00
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 ( ) { }
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 ( ) ) ;
}
2019-11-24 12:23:16 +00:00
2017-01-31 10:08:17 +00:00
@Deprecated
2016-04-14 16:24:03 +00:00
public static ItemStack getItem ( ) {
2019-08-31 09:36:45 +00:00
return getItem ( SlimefunGuideLayout . CHEST ) ;
2016-04-14 16:24:03 +00:00
}
2019-11-22 13:57:04 +00:00
2019-08-31 09:36:45 +00:00
public static ItemStack getItem ( SlimefunGuideLayout design ) {
2019-11-22 13:57:04 +00:00
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 " ) ) ) ;
2019-11-22 13:57:04 +00:00
2017-01-31 10:08:17 +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) " ) ) ;
2019-11-22 13:57:04 +00:00
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 " ) ) ;
2019-11-22 13:57:04 +00:00
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) " ) ) ;
2019-11-22 13:57:04 +00:00
break ;
2017-01-31 10:08:17 +00:00
default :
return null ;
}
2019-11-22 13:57:04 +00:00
meta . setLore ( lore ) ;
SlimefunPlugin . getItemTextureService ( ) . setTexture ( meta , " SLIMEFUN_GUIDE " ) ;
item . setItemMeta ( meta ) ;
return item ;
2017-01-31 10:08:17 +00:00
}
@Deprecated
2016-04-14 16:24:03 +00:00
public static ItemStack getItem ( boolean book ) {
2019-08-31 09:36:45 +00:00
return getItem ( book ? SlimefunGuideLayout . BOOK : SlimefunGuideLayout . CHEST ) ;
2017-01-31 10:08:17 +00:00
}
2019-10-11 21:48:46 +00:00
2019-08-27 14:26:35 +00:00
@Deprecated
2017-01-31 10:08:17 +00:00
public static ItemStack getDeprecatedItem ( boolean book ) {
2018-09-04 09:33:57 +00:00
return new CustomItem ( new ItemStack ( Material . ENCHANTED_BOOK ) , " &eSlimefun Guide &7(Right Click) " , ( book ? " " : " &2 " ) , " &rThis is your basic Guide for Slimefun " , " &rYou can see all Items added by this Plugin " , " &ror its Addons including their Recipes " , " &ra bit of information and more " ) ;
2016-04-14 16:24:03 +00:00
}
2019-10-11 21:48:46 +00:00
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
@Deprecated
public static void openGuide ( Player p , boolean book ) {
openGuide ( p , book ? SlimefunGuideLayout . BOOK : SlimefunGuideLayout . CHEST ) ;
}
2019-10-11 21:48:46 +00:00
2019-11-24 12:23:16 +00:00
public static void openGuide ( Player p , ItemStack guide ) {
2019-12-08 11:58:05 +00:00
if ( SlimefunManager . isItemSimilar ( guide , getItem ( SlimefunGuideLayout . CHEST ) , true ) ) {
2019-11-24 12:23:16 +00:00
openGuide ( p , SlimefunGuideLayout . CHEST ) ;
2017-01-31 10:08:17 +00:00
}
2019-12-08 11:58:05 +00:00
else if ( SlimefunManager . isItemSimilar ( guide , getItem ( SlimefunGuideLayout . BOOK ) , true ) ) {
2019-11-24 12:23:16 +00:00
openGuide ( p , SlimefunGuideLayout . BOOK ) ;
2017-01-31 10:08:17 +00:00
}
2019-12-08 11:58:05 +00:00
else if ( SlimefunManager . isItemSimilar ( guide , getItem ( SlimefunGuideLayout . CHEAT_SHEET ) , true ) ) {
2019-11-24 12:23:16 +00:00
openGuide ( p , SlimefunGuideLayout . CHEAT_SHEET ) ;
2017-01-15 18:17:02 +00:00
}
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 ;
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
}
}
2019-10-20 14:41:28 +00:00
private static void openMainMenuAsync ( final Player player , final boolean survival , final SlimefunGuideLayout layout , final int selected_page ) {
if ( ! PlayerProfile . get ( player , profile - > Slimefun . runSync ( ( ) - > openMainMenu ( profile , layout , survival , selected_page ) ) ) )
Slimefun . getLocal ( ) . sendMessage ( player , " messages.opening-guide " ) ;
2019-09-27 19:40:51 +00:00
}
2019-10-20 14:41:28 +00:00
public static void openMainMenu ( final PlayerProfile profile , SlimefunGuideLayout layout , final boolean survival , final int selected_page ) {
SlimefunPlugin . getUtilities ( ) . guideLayouts . get ( layout ) . openMainMenu ( profile , survival , selected_page ) ;
2016-04-14 16:24:03 +00:00
}
2019-03-27 20:41:29 +00:00
2019-10-20 14:41:28 +00:00
public static void openCategory ( final PlayerProfile profile , final Category category , SlimefunGuideLayout layout , final boolean survival , final int selected_page ) {
if ( category = = null ) return ;
SlimefunPlugin . getUtilities ( ) . guideLayouts . get ( layout ) . openCategory ( profile , category , survival , selected_page ) ;
2019-09-21 19:40:54 +00:00
}
2019-09-27 19:40:51 +00:00
2019-10-20 14:41:28 +00:00
public static void openSearch ( final PlayerProfile profile , String input , boolean survival , boolean addToHistory ) {
SlimefunPlugin . getUtilities ( ) . guideLayouts . get ( SlimefunGuideLayout . CHEST ) . openSearch ( profile , input , survival , addToHistory ) ;
2019-10-05 21:49:25 +00:00
}
2019-10-20 14:41:28 +00:00
public static void displayItem ( PlayerProfile profile , final ItemStack item , boolean addToHistory ) {
SlimefunPlugin . getUtilities ( ) . guideLayouts . get ( SlimefunGuideLayout . CHEST ) . displayItem ( profile , item , addToHistory ) ;
2019-09-27 19:40:51 +00:00
}
2019-10-20 14:41:28 +00:00
public static void displayItem ( PlayerProfile profile , final SlimefunItem item , boolean addToHistory ) {
SlimefunPlugin . getUtilities ( ) . guideLayouts . get ( SlimefunGuideLayout . CHEST ) . displayItem ( profile , item , addToHistory ) ;
2016-04-14 16:24:03 +00:00
}
}