2016-04-14 16:24:03 +00:00
package me.mrCookieSlime.Slimefun ;
import java.util.ArrayList ;
2017-01-15 18:17:02 +00:00
import java.util.Arrays ;
2016-04-14 16:24:03 +00:00
import java.util.Iterator ;
2019-09-05 11:29:19 +00:00
import java.util.LinkedList ;
2016-04-14 16:24:03 +00:00
import java.util.List ;
2019-10-16 23:08:14 +00:00
import java.util.Optional ;
2019-08-31 12:17:25 +00:00
import java.util.logging.Level ;
2019-08-25 20:21:06 +00:00
import java.util.stream.Collectors ;
2016-04-14 16:24:03 +00:00
2017-01-15 18:17:02 +00:00
import org.bukkit.Bukkit ;
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.FurnaceRecipe ;
import org.bukkit.inventory.ItemStack ;
import org.bukkit.inventory.Recipe ;
import org.bukkit.inventory.ShapedRecipe ;
import org.bukkit.inventory.ShapelessRecipe ;
2019-05-30 11:42:06 +00:00
import org.bukkit.inventory.meta.SkullMeta ;
2017-01-15 18:17:02 +00:00
2019-10-01 11:14:50 +00:00
import io.github.thebusybiscuit.cscorelib2.chat.ChatInput ;
2019-10-05 21:49:25 +00:00
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils ;
2019-10-01 15:04:09 +00:00
import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler ;
2016-04-14 16:24:03 +00:00
import me.mrCookieSlime.CSCoreLibPlugin.PlayerRunnable ;
import me.mrCookieSlime.CSCoreLibPlugin.general.Chat.TellRawMessage ;
import me.mrCookieSlime.CSCoreLibPlugin.general.Chat.TellRawMessage.HoverAction ;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu ;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.CustomBookOverlay ;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem ;
import me.mrCookieSlime.CSCoreLibPlugin.general.String.StringUtils ;
import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull ;
import me.mrCookieSlime.Slimefun.Lists.RecipeType ;
import me.mrCookieSlime.Slimefun.Objects.Category ;
import me.mrCookieSlime.Slimefun.Objects.LockedCategory ;
import me.mrCookieSlime.Slimefun.Objects.Research ;
2019-08-30 09:28:27 +00:00
import me.mrCookieSlime.Slimefun.Objects.SeasonalCategory ;
2016-04-14 16:24:03 +00:00
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem ;
2019-09-03 11:06:24 +00:00
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.RecipeDisplayItem ;
2019-10-03 16:06:14 +00:00
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.multiblocks.MultiBlockMachine ;
2016-04-14 16:24:03 +00:00
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager ;
import me.mrCookieSlime.Slimefun.api.GuideHandler ;
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-08-31 13:52:15 +00:00
import me.mrCookieSlime.Slimefun.api.SlimefunGuideLayout ;
2019-08-26 07:07:02 +00:00
import me.mrCookieSlime.Slimefun.hooks.github.Contributor ;
import me.mrCookieSlime.Slimefun.hooks.github.IntegerFormat ;
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-11 21:48:46 +00:00
2019-09-27 19:40:51 +00:00
private static final int CATEGORY_SIZE = 36 ;
2019-10-05 21:49:25 +00:00
private static final int [ ] SLOTS = new int [ ] { 0 , 2 , 3 , 5 , 6 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 } ;
2019-10-11 21:48:46 +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-08-31 09:36:45 +00:00
public static ItemStack getItem ( SlimefunGuideLayout design ) {
2017-01-31 10:08:17 +00:00
switch ( design ) {
2019-08-25 21:20:31 +00:00
case BOOK :
2018-09-04 09:33:57 +00:00
return new CustomItem ( new ItemStack ( Material . ENCHANTED_BOOK ) , " &aSlimefun Guide &7(Book GUI) " , " " , " &eRight Click &8 \ u21E8 &7Browse Items " , " &eShift + Right Click &8 \ u21E8 &7Open Settings / Credits " ) ;
2019-08-25 21:20:31 +00:00
case CHEAT_SHEET :
2018-09-04 09:33:57 +00:00
return new CustomItem ( new ItemStack ( Material . ENCHANTED_BOOK ) , " &cSlimefun Guide &4(Cheat Sheet) " , " " , " &4&lOnly openable by Admins " , " " , " &eRight Click &8 \ u21E8 &7Browse Items " , " &eShift + Right Click &8 \ u21E8 &7Open Settings / Credits " ) ;
2019-08-25 21:20:31 +00:00
case CHEST :
2018-09-04 09:33:57 +00:00
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 " ) ;
2017-01-31 10:08:17 +00:00
default :
return null ;
}
}
@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
2017-01-14 21:40:06 +00:00
public static void openSettings ( Player p , final ItemStack guide ) {
final ChestMenu menu = new ChestMenu ( " Settings / Info " ) ;
2019-10-11 21:48:46 +00:00
2018-04-25 04:30:41 +00:00
menu . setEmptySlotsClickable ( false ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuOpeningHandler (
pl - > pl . playSound ( pl . getLocation ( ) , Sound . BLOCK_NOTE_BLOCK_HARP , 0 . 7F , 0 . 7F )
) ;
2019-09-28 15:13:23 +00:00
2019-10-05 21:49:25 +00:00
for ( int i : SLOTS ) {
2018-09-04 09:33:57 +00:00
menu . addItem ( i , new CustomItem ( new ItemStack ( Material . GRAY_STAINED_GLASS_PANE ) , " " ) ) ;
2019-10-05 21:49:25 +00:00
menu . addMenuClickHandler ( i , ( pl , slot , item , action ) - > false ) ;
2017-01-14 21:40:06 +00:00
}
2019-10-11 21:48:46 +00:00
2019-08-31 09:36:45 +00:00
if ( SlimefunManager . isItemSimiliar ( guide , getItem ( SlimefunGuideLayout . CHEST ) , true ) ) {
2017-01-31 10:08:17 +00:00
if ( p . hasPermission ( " slimefun.cheat.items " ) ) {
2018-09-04 09:33:57 +00:00
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 " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 19 , ( pl , slot , item , action ) - > {
2019-08-31 09:36:45 +00:00
pl . getInventory ( ) . setItemInMainHand ( getItem ( SlimefunGuideLayout . BOOK ) ) ;
2019-03-31 18:32:40 +00:00
openSettings ( pl , pl . getInventory ( ) . getItemInMainHand ( ) ) ;
return false ;
2017-01-31 10:08:17 +00:00
} ) ;
}
else {
2018-09-04 09:33:57 +00:00
menu . addItem ( 19 , new CustomItem ( new ItemStack ( Material . CHEST ) , " &7Guide Layout: &eChest GUI " , " " , " &aChest GUI " , " &7Book GUI " , " " , " &e Click &8 \ u21E8 &7Change Layout " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 19 , ( pl , slot , item , action ) - > {
2019-08-31 09:36:45 +00:00
pl . getInventory ( ) . setItemInMainHand ( getItem ( SlimefunGuideLayout . BOOK ) ) ;
2019-03-31 18:32:40 +00:00
openSettings ( pl , pl . getInventory ( ) . getItemInMainHand ( ) ) ;
return false ;
2017-01-31 10:08:17 +00:00
} ) ;
}
}
2019-08-31 09:36:45 +00:00
else if ( SlimefunManager . isItemSimiliar ( guide , getItem ( SlimefunGuideLayout . BOOK ) , true ) ) {
2017-01-31 10:08:17 +00:00
if ( p . hasPermission ( " slimefun.cheat.items " ) ) {
2018-09-04 09:33:57 +00:00
menu . addItem ( 19 , new CustomItem ( new ItemStack ( Material . CHEST ) , " &7Guide Layout: &eBook GUI " , " " , " &7Chest GUI " , " &aBook GUI " , " &7Cheat Sheet " , " " , " &e Click &8 \ u21E8 &7Change Layout " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 19 , ( pl , slot , item , action ) - > {
2019-08-31 09:36:45 +00:00
pl . getInventory ( ) . setItemInMainHand ( getItem ( SlimefunGuideLayout . CHEAT_SHEET ) ) ;
2019-03-31 18:32:40 +00:00
openSettings ( pl , pl . getInventory ( ) . getItemInMainHand ( ) ) ;
return false ;
2017-01-31 10:08:17 +00:00
} ) ;
}
else {
2018-09-04 09:33:57 +00:00
menu . addItem ( 19 , new CustomItem ( new ItemStack ( Material . CHEST ) , " &7Guide Layout: &eBook GUI " , " " , " &7Chest GUI " , " &aBook GUI " , " " , " &e Click &8 \ u21E8 &7Change Layout " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 19 , ( pl , slot , item , action ) - > {
2019-08-31 09:36:45 +00:00
pl . getInventory ( ) . setItemInMainHand ( getItem ( SlimefunGuideLayout . CHEST ) ) ;
2019-03-31 18:32:40 +00:00
openSettings ( pl , pl . getInventory ( ) . getItemInMainHand ( ) ) ;
return false ;
2017-01-31 10:08:17 +00:00
} ) ;
}
}
2019-08-31 09:36:45 +00:00
else if ( SlimefunManager . isItemSimiliar ( guide , getItem ( SlimefunGuideLayout . CHEAT_SHEET ) , true ) ) {
2018-09-04 09:33:57 +00:00
menu . addItem ( 19 , new CustomItem ( new ItemStack ( Material . CHEST ) , " &7Guide Layout: &eCheat Sheet " , " " , " &7Chest GUI " , " &7Book GUI " , " &aCheat Sheet " , " " , " &e Click &8 \ u21E8 &7Change Layout " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 19 , ( pl , slot , item , action ) - > {
2019-08-31 09:36:45 +00:00
pl . getInventory ( ) . setItemInMainHand ( getItem ( SlimefunGuideLayout . CHEST ) ) ;
2019-03-31 18:32:40 +00:00
openSettings ( pl , pl . getInventory ( ) . getItemInMainHand ( ) ) ;
return false ;
2017-01-31 10:08:17 +00:00
} ) ;
}
2019-10-11 21:48:46 +00:00
2019-08-31 09:36:45 +00:00
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 " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 1 , ( pl , slot , item , action ) - > {
openCredits ( pl , guide ) ;
return false ;
2017-01-14 21:40:06 +00:00
} ) ;
2019-10-11 21:48:46 +00:00
2017-01-16 15:28:41 +00:00
try {
2019-08-31 13:52:15 +00:00
menu . addItem ( 4 , 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 " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 4 , ( pl , slot , item , action ) - > {
pl . closeInventory ( ) ;
pl . sendMessage ( " " ) ;
pl . sendMessage ( ChatColor . translateAlternateColorCodes ( '&' , " &7&ohttps://github.com/TheBusyBiscuit/Slimefun4 " ) ) ;
pl . sendMessage ( " " ) ;
return false ;
2017-01-16 15:28:41 +00:00
} ) ;
2019-08-31 12:17:25 +00:00
} catch ( Exception x ) {
Slimefun . getLogger ( ) . log ( Level . SEVERE , " An Error occured while creating the Info-Panel for Slimefun " + Slimefun . getVersion ( ) , x ) ;
2017-01-16 15:28:41 +00:00
}
2019-10-11 21:48:46 +00:00
2019-08-31 13:52:15 +00:00
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 " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 7 , ( pl , slot , item , action ) - > {
pl . closeInventory ( ) ;
pl . sendMessage ( " " ) ;
pl . sendMessage ( ChatColor . translateAlternateColorCodes ( '&' , " &7&ohttps://github.com/TheBusyBiscuit/Slimefun4/issues " ) ) ;
pl . sendMessage ( " " ) ;
return false ;
2017-01-16 15:28:41 +00:00
} ) ;
2019-10-11 21:48:46 +00:00
2017-01-14 21:40:06 +00:00
menu . open ( p ) ;
}
2019-10-11 21:48:46 +00:00
private static void openCredits ( Player p , final ItemStack guide ) {
2017-01-14 21:40:06 +00:00
final ChestMenu menu = new ChestMenu ( " Credits " ) ;
2019-10-11 21:48:46 +00:00
2018-04-25 04:30:41 +00:00
menu . setEmptySlotsClickable ( false ) ;
2019-09-05 11:29:19 +00:00
menu . addMenuOpeningHandler ( pl - > pl . playSound ( pl . getLocation ( ) , Sound . BLOCK_NOTE_BLOCK_HARP , 0 . 7F , 0 . 7F ) ) ;
2019-10-11 21:48:46 +00:00
2017-01-14 21:40:06 +00:00
for ( int i = 0 ; i < 9 ; i + + ) {
if ( i ! = 4 ) {
2018-09-04 09:33:57 +00:00
menu . addItem ( i , new CustomItem ( new ItemStack ( Material . GRAY_STAINED_GLASS_PANE ) , " " ) ) ;
2019-09-05 11:29:19 +00:00
menu . addMenuClickHandler ( i , ( pl , slot , item , action ) - > false ) ;
2017-01-14 21:40:06 +00:00
}
else {
2018-09-04 09:33:57 +00:00
menu . addItem ( 4 , new CustomItem ( new ItemStack ( Material . EMERALD ) , " &7 \ u21E6 Back to Settings " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 4 , ( pl , slot , item , action ) - > {
openSettings ( pl , guide ) ;
return false ;
2017-01-14 21:40:06 +00:00
} ) ;
}
}
2019-10-11 21:48:46 +00:00
2017-01-15 18:17:02 +00:00
int index = 9 ;
2019-09-05 11:29:19 +00:00
double total = 1 . 0 * SlimefunPlugin . getUtilities ( ) . contributors . stream ( ) . mapToInt ( Contributor : : getCommits ) . sum ( ) ;
2019-10-11 21:48:46 +00:00
2019-08-31 09:36:45 +00:00
for ( final Contributor contributor : SlimefunPlugin . getUtilities ( ) . contributors ) {
2019-05-30 11:42:06 +00:00
ItemStack skull = new ItemStack ( Material . PLAYER_HEAD ) ;
2019-10-11 21:48:46 +00:00
2019-05-30 11:42:06 +00:00
try {
String texture = contributor . getTexture ( ) ;
if ( texture ! = null ) skull = CustomSkull . getItem ( texture ) ;
2019-08-31 12:17:25 +00:00
} catch ( Exception x ) {
Slimefun . getLogger ( ) . log ( Level . SEVERE , " An Error occured while fetching a Contributor Head for Slimefun " + Slimefun . getVersion ( ) , x ) ;
2019-05-30 11:42:06 +00:00
}
2019-10-11 21:48:46 +00:00
2019-05-30 11:42:06 +00:00
SkullMeta meta = ( SkullMeta ) skull . getItemMeta ( ) ;
meta . setDisplayName ( ChatColor . GOLD + contributor . getName ( ) ) ;
2017-12-09 15:52:13 +00:00
2017-12-09 15:28:45 +00:00
if ( contributor . getCommits ( ) > 0 ) {
double percentage = DoubleHandler . fixDouble ( ( contributor . getCommits ( ) * 100 . 0 ) / total , 2 ) ;
2017-12-09 15:52:13 +00:00
meta . setLore ( Arrays . asList ( " " , ChatColor . translateAlternateColorCodes ( '&' , " &7Role: &r " + contributor . getJob ( ) ) , ChatColor . translateAlternateColorCodes ( '&' , " &7Contributions: &r " + contributor . getCommits ( ) + " commits &7(&r " + percentage + " %&7) " ) , " " , ChatColor . translateAlternateColorCodes ( '&' , " &7 \ u21E8 Click to view my GitHub profile " ) ) ) ;
2017-01-15 18:17:02 +00:00
}
else {
2017-12-09 15:28:45 +00:00
meta . setLore ( Arrays . asList ( " " , ChatColor . translateAlternateColorCodes ( '&' , " &7Role: &r " + contributor . getJob ( ) ) ) ) ;
2017-01-15 18:17:02 +00:00
}
2017-12-09 15:52:13 +00:00
2017-01-15 18:17:02 +00:00
skull . setItemMeta ( meta ) ;
2019-10-11 21:48:46 +00:00
2017-01-15 18:17:02 +00:00
menu . addItem ( index , skull ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( index , ( pl , slot , item , action ) - > {
if ( contributor . getCommits ( ) > 0 ) {
pl . closeInventory ( ) ;
pl . sendMessage ( " " ) ;
pl . sendMessage ( ChatColor . translateAlternateColorCodes ( '&' , " &7&o " + contributor . getProfile ( ) ) ) ;
pl . sendMessage ( " " ) ;
2017-01-15 18:17:02 +00:00
}
2019-03-31 18:32:40 +00:00
return false ;
2017-01-15 18:17:02 +00:00
} ) ;
2019-10-11 21:48:46 +00:00
2017-01-15 18:17:02 +00:00
index + + ;
}
2019-10-11 21:48:46 +00:00
2017-01-14 21:40:06 +00:00
menu . open ( p ) ;
2016-04-14 16:24:03 +00:00
}
public static void openCheatMenu ( Player p ) {
2019-10-11 21:48:46 +00:00
openMainMenuAsync ( p , false , false , 1 ) ;
2016-04-14 16:24:03 +00:00
}
2019-10-11 21:48:46 +00:00
2017-12-30 00:31:50 +00:00
public static void openGuide ( Player p , boolean book ) {
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-16 23:08:14 +00:00
Object last = null ;
Optional < PlayerProfile > profile = PlayerProfile . find ( p ) ;
if ( profile . isPresent ( ) ) {
last = getLastEntry ( profile . get ( ) , false ) ;
}
2019-10-11 21:48:46 +00:00
if ( last = = null )
openMainMenuAsync ( p , true , book , 1 ) ;
else
2019-09-28 15:13:23 +00:00
handleHistory ( p , last , book , false ) ;
2016-04-14 16:24:03 +00:00
}
2019-08-30 07:21:49 +00:00
2019-10-11 21:48:46 +00:00
private static void openMainMenuAsync ( final Player player , final boolean survival , final boolean book , final int selected_page ) {
2019-10-11 22:56:51 +00:00
if ( ! PlayerProfile . get ( player , profile - > Slimefun . runSync ( ( ) - > openMainMenu ( profile , survival , book , selected_page ) ) ) )
Slimefun . getLocal ( ) . sendMessage ( player , " messages.opening-guide " ) ;
2019-10-11 21:48:46 +00:00
}
private static void openMainMenu ( final PlayerProfile profile , final boolean survival , final boolean book , final int selected_page ) {
Player p = Bukkit . getPlayer ( profile . getUUID ( ) ) ;
if ( p = = null ) return ;
2019-09-05 11:29:19 +00:00
if ( survival ) {
2019-10-16 23:08:14 +00:00
profile . getGuideHistory ( ) . clear ( ) ;
2019-09-05 11:29:19 +00:00
}
2019-10-11 21:48:46 +00:00
2017-12-30 00:31:50 +00:00
if ( book ) {
2019-08-28 08:59:20 +00:00
List < TellRawMessage > pages = new ArrayList < > ( ) ;
List < String > texts = new ArrayList < > ( ) ;
List < String > tooltips = new ArrayList < > ( ) ;
List < PlayerRunnable > actions = new ArrayList < > ( ) ;
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
int tier = 0 ;
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
for ( final Category category : Category . list ( ) ) {
2016-04-17 18:39:40 +00:00
boolean locked = true ;
2019-10-11 21:48:46 +00:00
2016-04-17 18:39:40 +00:00
for ( SlimefunItem item : category . getItems ( ) ) {
if ( Slimefun . isEnabled ( p , item , false ) ) {
locked = false ;
break ;
}
}
2019-10-11 21:48:46 +00:00
2019-09-27 19:40:51 +00:00
if ( ! locked ) {
2016-04-17 18:39:40 +00:00
if ( tier < category . getTier ( ) ) {
if ( survival ) {
for ( final GuideHandler handler : Slimefun . getGuideHandlers ( tier ) ) {
handler . addEntry ( texts , tooltips ) ;
actions . add ( new PlayerRunnable ( 2 ) {
2019-10-11 21:48:46 +00:00
2016-04-17 18:39:40 +00:00
@Override
public void run ( Player p ) {
2017-12-30 00:31:50 +00:00
handler . run ( p , survival , book ) ;
2016-04-17 18:39:40 +00:00
}
} ) ;
}
}
tier = category . getTier ( ) ;
if ( tier > 1 ) {
for ( int i = 0 ; i < 10 ; i + + ) {
if ( texts . size ( ) % 10 = = 0 ) break ;
texts . add ( " " ) ;
tooltips . add ( null ) ;
actions . add ( null ) ;
}
}
2018-06-06 09:50:26 +00:00
texts . add ( ChatColor . translateAlternateColorCodes ( '&' , " &8 \ u21E8 &6Tier " + tier ) ) ;
2016-04-17 18:39:40 +00:00
tooltips . add ( null ) ;
actions . add ( null ) ;
}
2019-10-11 21:48:46 +00:00
if ( category instanceof LockedCategory & & ! ( ( LockedCategory ) category ) . hasUnlocked ( p , profile ) ) {
2018-06-06 09:50:26 +00:00
StringBuilder parents = new StringBuilder ( ChatColor . translateAlternateColorCodes ( '&' , " &4&lLOCKED \ n \ n&7In order to unlock this Category, \ n&7you need to unlock all Items from \ n&7the following Categories first: \ n " ) ) ;
2019-10-11 21:48:46 +00:00
2016-04-17 18:39:40 +00:00
for ( Category parent : ( ( LockedCategory ) category ) . getParents ( ) ) {
2018-06-06 09:50:26 +00:00
parents . append ( ChatColor . translateAlternateColorCodes ( '&' , " \ n&c " + StringUtils . formatItemName ( parent . getItem ( ) , false ) ) ) ;
2016-04-17 18:39:40 +00:00
}
2019-10-11 21:48:46 +00:00
2018-06-06 09:50:26 +00:00
texts . add ( ChatColor . translateAlternateColorCodes ( '&' , shorten ( " &c " , StringUtils . formatItemName ( category . getItem ( ) , false ) ) ) ) ;
2016-04-17 18:39:40 +00:00
tooltips . add ( parents . toString ( ) ) ;
actions . add ( null ) ;
}
2019-08-30 09:28:27 +00:00
else if ( category instanceof SeasonalCategory ) {
if ( ( ( SeasonalCategory ) category ) . isUnlocked ( ) ) {
2018-06-06 09:50:26 +00:00
texts . add ( ChatColor . translateAlternateColorCodes ( '&' , shorten ( " &a " , StringUtils . formatItemName ( category . getItem ( ) , false ) ) ) ) ;
tooltips . add ( ChatColor . translateAlternateColorCodes ( '&' , " &eClick to open the following Category: \ n " + StringUtils . formatItemName ( category . getItem ( ) , false ) ) ) ;
2016-04-17 18:39:40 +00:00
actions . add ( new PlayerRunnable ( 1 ) {
2016-04-14 16:24:03 +00:00
@Override
2016-04-17 18:39:40 +00:00
public void run ( final Player p ) {
2019-08-31 09:36:45 +00:00
Bukkit . getScheduler ( ) . scheduleSyncDelayedTask ( SlimefunPlugin . instance , ( ) - > openCategory ( p , category , survival , 1 , book ) , 1L ) ;
2016-04-14 16:24:03 +00:00
}
} ) ;
}
}
2016-04-17 18:39:40 +00:00
else {
2018-06-06 09:50:26 +00:00
texts . add ( ChatColor . translateAlternateColorCodes ( '&' , shorten ( " &a " , StringUtils . formatItemName ( category . getItem ( ) , false ) ) ) ) ;
tooltips . add ( ChatColor . translateAlternateColorCodes ( '&' , " &eClick to open the following Category: \ n " + StringUtils . formatItemName ( category . getItem ( ) , false ) ) ) ;
2016-04-14 16:24:03 +00:00
actions . add ( new PlayerRunnable ( 1 ) {
@Override
public void run ( final Player p ) {
2019-08-31 09:36:45 +00:00
Bukkit . getScheduler ( ) . scheduleSyncDelayedTask ( SlimefunPlugin . instance , ( ) - > openCategory ( p , category , survival , 1 , book ) , 1L ) ;
2016-04-14 16:24:03 +00:00
}
} ) ;
}
}
}
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
if ( survival ) {
for ( final GuideHandler handler : Slimefun . getGuideHandlers ( tier ) ) {
handler . addEntry ( texts , tooltips ) ;
actions . add ( new PlayerRunnable ( 2 ) {
@Override
public void run ( Player p ) {
2017-12-30 00:31:50 +00:00
handler . run ( p , survival , book ) ;
2016-04-14 16:24:03 +00:00
}
} ) ;
}
}
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
for ( int i = 0 ; i < texts . size ( ) ; i = i + 10 ) {
TellRawMessage page = new TellRawMessage ( ) ;
2018-06-06 09:50:26 +00:00
page . addText ( ChatColor . translateAlternateColorCodes ( '&' , " &b&l- Slimefun Guide - \ n \ n " ) ) ;
2016-04-14 16:24:03 +00:00
for ( int j = i ; j < texts . size ( ) & & j < i + 10 ; j + + ) {
2016-12-18 13:49:50 +00:00
page . addText ( texts . get ( j ) + " \ n " ) ;
if ( tooltips . get ( j ) ! = null ) page . addHoverEvent ( HoverAction . SHOW_TEXT , tooltips . get ( j ) ) ;
2016-04-14 16:24:03 +00:00
if ( actions . get ( j ) ! = null ) page . addClickEvent ( actions . get ( j ) ) ;
}
// page.addText("\n");
// if (i > 0) {
2018-06-06 09:50:26 +00:00
// page.addText(ChatColor.translateAlternateColorCodes('&', "&c<- Prev"));
// page.addHoverEvent(HoverAction.SHOW_TEXT, ChatColor.translateAlternateColorCodes('&', "&eGo to Page " + (i)));
2016-04-14 16:24:03 +00:00
// page.addClickEvent(me.mrCookieSlime.CSCoreLibPlugin.general.Chat.TellRawMessage.ClickAction.CHANGE_PAGE, String.valueOf(i));
// page.addText(" ");
// }
// if (texts.size() > i * 10) {
// page.addText(" ");
2018-06-06 09:50:26 +00:00
// page.addText(ChatColor.translateAlternateColorCodes('&', "&cNext ->"));
// page.addHoverEvent(HoverAction.SHOW_TEXT, ChatColor.translateAlternateColorCodes('&', "&eGo to Page " + (i + 2)));
2016-04-14 16:24:03 +00:00
// page.addClickEvent(me.mrCookieSlime.CSCoreLibPlugin.general.Chat.TellRawMessage.ClickAction.CHANGE_PAGE, String.valueOf(i + 2));
// }
pages . add ( page ) ;
}
2019-10-11 21:48:46 +00:00
2019-10-05 21:49:25 +00:00
new CustomBookOverlay ( " Slimefun Guide " , " TheBusyBiscuit " , pages . toArray ( new TellRawMessage [ pages . size ( ) ] ) ) . open ( p ) ;
2016-04-14 16:24:03 +00:00
}
else {
final ChestMenu menu = new ChestMenu ( " Slimefun Guide " ) ;
2019-10-11 21:48:46 +00:00
2018-04-25 04:30:41 +00:00
menu . setEmptySlotsClickable ( false ) ;
2019-09-06 10:11:37 +00:00
menu . addMenuOpeningHandler ( pl - > pl . playSound ( pl . getLocation ( ) , Sound . ITEM_BOOK_PAGE_TURN , 1 , 1 ) ) ;
2019-10-11 21:48:46 +00:00
2019-09-04 17:42:17 +00:00
List < Category > categories = SlimefunPlugin . getUtilities ( ) . enabledCategories ;
2019-08-31 10:54:54 +00:00
List < GuideHandler > handlers = SlimefunPlugin . getUtilities ( ) . guideHandlers . values ( ) . stream ( ) . flatMap ( List : : stream ) . collect ( Collectors . toList ( ) ) ;
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
int index = 9 ;
2016-05-17 19:38:18 +00:00
int pages = 1 ;
2019-09-27 19:40:51 +00:00
2019-09-30 17:06:50 +00:00
fillInv ( menu , ! survival ) ;
2019-09-27 19:40:51 +00:00
int target = ( CATEGORY_SIZE * ( selected_page - 1 ) ) - 1 ;
2019-10-11 21:48:46 +00:00
2016-05-17 19:38:18 +00:00
while ( target < ( categories . size ( ) + handlers . size ( ) - 1 ) ) {
2019-09-27 19:40:51 +00:00
if ( index > = CATEGORY_SIZE + 9 ) {
2016-05-17 19:38:18 +00:00
pages + + ;
break ;
2016-04-14 16:24:03 +00:00
}
2019-10-11 21:48:46 +00:00
2016-05-16 11:18:56 +00:00
target + + ;
2019-10-11 21:48:46 +00:00
2016-05-16 11:18:56 +00:00
if ( target > = categories . size ( ) ) {
2019-09-05 11:29:19 +00:00
if ( ! survival ) {
break ;
}
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
index = handlers . get ( target - categories . size ( ) ) . next ( p , index , menu ) ;
}
else {
2019-10-05 21:49:25 +00:00
Category category = categories . get ( target ) ;
2016-04-17 18:39:40 +00:00
boolean locked = true ;
2019-10-11 21:48:46 +00:00
2016-04-17 18:39:40 +00:00
for ( SlimefunItem item : category . getItems ( ) ) {
if ( Slimefun . isEnabled ( p , item , false ) ) {
locked = false ;
break ;
}
}
2019-10-11 21:48:46 +00:00
2016-04-17 18:39:40 +00:00
if ( locked ) {
// Dont display that Category...
}
else if ( ! ( category instanceof LockedCategory ) ) {
2019-08-30 09:28:27 +00:00
if ( ! ( category instanceof SeasonalCategory ) ) {
2016-04-14 16:24:03 +00:00
menu . addItem ( index , category . getItem ( ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( index , ( pl , slot , item , action ) - > {
openCategory ( pl , category , survival , 1 , book ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
index + + ;
}
else {
2019-08-30 09:28:27 +00:00
if ( ( ( SeasonalCategory ) category ) . isUnlocked ( ) ) {
2016-04-14 16:24:03 +00:00
menu . addItem ( index , category . getItem ( ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( index , ( pl , slot , item , action ) - > {
openCategory ( pl , category , survival , 1 , book ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
index + + ;
}
}
}
2019-10-11 21:48:46 +00:00
else if ( ( ( LockedCategory ) category ) . hasUnlocked ( p , profile ) ) {
2016-04-14 16:24:03 +00:00
menu . addItem ( index , category . getItem ( ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( index , ( pl , slot , item , action ) - > {
openCategory ( pl , category , survival , 1 , book ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
index + + ;
}
else {
2019-08-28 08:59:20 +00:00
List < String > parents = new ArrayList < > ( ) ;
2016-04-14 16:24:03 +00:00
parents . add ( " " ) ;
2018-06-06 09:50:26 +00:00
parents . add ( ChatColor . translateAlternateColorCodes ( '&' , " &rYou need to unlock all Items " ) ) ;
parents . add ( ChatColor . translateAlternateColorCodes ( '&' , " &rfrom the following Categories first: " ) ) ;
2016-04-14 16:24:03 +00:00
parents . add ( " " ) ;
2019-10-11 21:48:46 +00:00
2019-03-31 18:32:40 +00:00
for ( Category parent : ( ( LockedCategory ) category ) . getParents ( ) ) {
2016-04-14 16:24:03 +00:00
parents . add ( parent . getItem ( ) . getItemMeta ( ) . getDisplayName ( ) ) ;
}
2019-10-11 21:48:46 +00:00
2019-10-06 17:32:55 +00:00
menu . addItem ( index , new CustomItem ( Material . BARRIER , " &4LOCKED &7- &r " + category . getItem ( ) . getItemMeta ( ) . getDisplayName ( ) , parents . toArray ( new String [ 0 ] ) ) ) ;
2019-09-05 11:29:19 +00:00
menu . addMenuClickHandler ( index , ( pl , slot , item , action ) - > false ) ;
2016-04-14 16:24:03 +00:00
index + + ;
}
}
}
2016-05-17 19:38:18 +00:00
final int finalPages = pages ;
2019-10-11 21:48:46 +00:00
2018-09-04 09:33:57 +00:00
menu . addItem ( 46 , new CustomItem ( new ItemStack ( Material . LIME_STAINED_GLASS_PANE ) , " &r \ u21E6 Previous Page " , " " , " &7( " + selected_page + " / " + pages + " ) " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 46 , ( pl , slot , item , action ) - > {
int next = selected_page - 1 ;
if ( next < 1 ) next = finalPages ;
2019-10-11 21:48:46 +00:00
if ( next ! = selected_page ) openMainMenuAsync ( pl , survival , book , next ) ;
2019-03-31 18:32:40 +00:00
return false ;
2016-05-17 19:38:18 +00:00
} ) ;
2019-10-11 21:48:46 +00:00
2018-09-04 09:33:57 +00:00
menu . addItem ( 52 , new CustomItem ( new ItemStack ( Material . LIME_STAINED_GLASS_PANE ) , " &rNext Page \ u21E8 " , " " , " &7( " + selected_page + " / " + pages + " ) " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 52 , ( pl , slot , item , action ) - > {
int next = selected_page + 1 ;
if ( next > finalPages ) next = 1 ;
2019-10-11 21:48:46 +00:00
if ( next ! = selected_page ) openMainMenuAsync ( pl , survival , book , next ) ;
2019-03-31 18:32:40 +00:00
return false ;
2016-05-17 19:38:18 +00:00
} ) ;
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
menu . open ( p ) ;
}
}
2019-10-11 21:48:46 +00:00
private static String shorten ( String string , String string2 ) {
2016-04-14 16:24:03 +00:00
if ( ChatColor . stripColor ( string + string2 ) . length ( ) > 19 ) return ( string + ChatColor . stripColor ( string2 ) ) . substring ( 0 , 18 ) + " ... " ;
else return ( string + ChatColor . stripColor ( string2 ) ) ;
}
2019-10-11 21:48:46 +00:00
private static void openCategory ( final Player p , final Category category , final boolean survival , final int selected_page , final boolean book ) {
2016-04-14 16:24:03 +00:00
if ( category = = null ) return ;
2017-12-30 00:31:50 +00:00
if ( book & & category . getItems ( ) . size ( ) < 250 ) {
2019-08-28 08:59:20 +00:00
List < TellRawMessage > pages = new ArrayList < > ( ) ;
List < String > texts = new ArrayList < > ( ) ;
List < String > tooltips = new ArrayList < > ( ) ;
List < PlayerRunnable > actions = new ArrayList < > ( ) ;
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
for ( final SlimefunItem item : category . getItems ( ) ) {
if ( Slimefun . hasPermission ( p , item , false ) ) {
2016-04-17 18:39:40 +00:00
if ( Slimefun . isEnabled ( p , item , false ) ) {
if ( survival & & ! Slimefun . hasUnlocked ( p , item , false ) & & item . getResearch ( ) ! = null ) {
2017-07-21 09:50:59 +00:00
final Research research = item . getResearch ( ) ;
2019-10-11 21:48:46 +00:00
2018-06-06 09:50:26 +00:00
texts . add ( ChatColor . translateAlternateColorCodes ( '&' , shorten ( " &7 " , StringUtils . formatItemName ( item . getItem ( ) , false ) ) ) ) ;
tooltips . add ( ChatColor . translateAlternateColorCodes ( '&' , StringUtils . formatItemName ( item . getItem ( ) , false ) + " \ n&c&lLOCKED \ n \ n&7Cost: " + ( p . getLevel ( ) > = research . getCost ( ) ? " &b " : " &4 " ) + research . getCost ( ) + " Levels \ n \ n&a> Click to unlock " ) ) ;
2016-04-17 18:39:40 +00:00
actions . add ( new PlayerRunnable ( 2 ) {
2019-10-11 21:48:46 +00:00
2016-04-17 18:39:40 +00:00
@Override
public void run ( final Player p ) {
2017-10-07 06:54:56 +00:00
if ( ! Research . isResearching ( p ) ) {
if ( research . canUnlock ( p ) ) {
2019-10-01 00:57:58 +00:00
PlayerProfile profile = PlayerProfile . get ( p ) ;
2019-10-11 21:48:46 +00:00
2019-08-25 14:07:06 +00:00
if ( profile . hasUnlocked ( research ) ) {
2017-12-30 00:31:50 +00:00
openCategory ( p , category , true , selected_page , book ) ;
2019-08-25 14:07:06 +00:00
}
2017-10-07 06:54:56 +00:00
else {
2019-08-31 09:36:45 +00:00
if ( ! ( p . getGameMode ( ) = = GameMode . CREATIVE & & SlimefunPlugin . getSettings ( ) . researchesFreeInCreative ) ) {
2017-10-07 06:54:56 +00:00
p . setLevel ( p . getLevel ( ) - research . getCost ( ) ) ;
}
if ( p . getGameMode ( ) = = GameMode . CREATIVE ) {
research . unlock ( p , true ) ;
2019-10-11 21:48:46 +00:00
2019-08-31 09:36:45 +00:00
Bukkit . getScheduler ( ) . scheduleSyncDelayedTask ( SlimefunPlugin . instance , ( ) - > openCategory ( p , category , survival , selected_page , book ) , 1L ) ;
2019-10-11 21:48:46 +00:00
}
2019-08-25 14:07:06 +00:00
else {
2017-10-07 06:54:56 +00:00
research . unlock ( p , false ) ;
2019-10-11 21:48:46 +00:00
2019-08-31 09:36:45 +00:00
Bukkit . getScheduler ( ) . scheduleSyncDelayedTask ( SlimefunPlugin . instance , ( ) - > openCategory ( p , category , survival , selected_page , book ) , 103L ) ;
2017-10-07 06:54:56 +00:00
}
}
2019-09-21 11:59:15 +00:00
} else SlimefunPlugin . getLocal ( ) . sendMessage ( p , " messages.not-enough-xp " , true ) ;
2017-10-07 06:54:56 +00:00
}
2016-04-14 16:24:03 +00:00
}
2016-04-17 18:39:40 +00:00
} ) ;
2016-04-14 16:24:03 +00:00
}
2016-04-17 18:39:40 +00:00
else {
2018-06-06 09:50:26 +00:00
texts . add ( ChatColor . translateAlternateColorCodes ( '&' , shorten ( " &a " , StringUtils . formatItemName ( item . getItem ( ) , false ) ) ) ) ;
2019-10-11 21:48:46 +00:00
2016-04-17 18:39:40 +00:00
StringBuilder tooltip = new StringBuilder ( ) ;
2019-10-11 21:48:46 +00:00
2016-04-17 18:39:40 +00:00
tooltip . append ( StringUtils . formatItemName ( item . getItem ( ) , false ) ) ;
2019-10-11 21:48:46 +00:00
2016-04-17 18:39:40 +00:00
if ( item . getItem ( ) . hasItemMeta ( ) & & item . getItem ( ) . getItemMeta ( ) . hasLore ( ) ) {
2019-03-31 18:32:40 +00:00
for ( String line : item . getItem ( ) . getItemMeta ( ) . getLore ( ) ) {
2016-04-17 18:39:40 +00:00
tooltip . append ( " \ n " + line ) ;
}
2016-04-14 16:24:03 +00:00
}
2019-10-11 21:48:46 +00:00
2018-06-06 09:50:26 +00:00
tooltip . append ( ChatColor . translateAlternateColorCodes ( '&' , " \ n \ n&e&oClick for more Info " ) ) ;
2019-10-11 21:48:46 +00:00
2016-04-17 18:39:40 +00:00
tooltips . add ( tooltip . toString ( ) ) ;
actions . add ( new PlayerRunnable ( 2 ) {
2019-10-11 21:48:46 +00:00
2016-04-17 18:39:40 +00:00
@Override
public void run ( Player p ) {
2017-12-30 00:31:50 +00:00
displayItem ( p , item . getItem ( ) , true , book , 0 ) ;
2016-04-17 18:39:40 +00:00
}
} ) ;
}
2016-04-14 16:24:03 +00:00
}
}
else {
2018-06-06 09:50:26 +00:00
texts . add ( ChatColor . translateAlternateColorCodes ( '&' , shorten ( " &4 " , StringUtils . formatItemName ( item . getItem ( ) , false ) ) ) ) ;
tooltips . add ( ChatColor . translateAlternateColorCodes ( '&' , " &cNo Permission! " ) ) ;
2016-04-14 16:24:03 +00:00
actions . add ( null ) ;
}
}
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
for ( int i = 0 ; i < texts . size ( ) ; i = i + 10 ) {
TellRawMessage page = new TellRawMessage ( ) ;
2018-06-06 09:50:26 +00:00
page . addText ( ChatColor . translateAlternateColorCodes ( '&' , " &b&l- Slimefun Guide - \ n \ n " ) ) ;
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
for ( int j = i ; j < texts . size ( ) & & j < i + 10 ; j + + ) {
page . addText ( texts . get ( j ) + " \ n " ) ;
if ( tooltips . get ( j ) ! = null ) page . addHoverEvent ( HoverAction . SHOW_TEXT , tooltips . get ( j ) ) ;
if ( actions . get ( j ) ! = null ) page . addClickEvent ( actions . get ( j ) ) ;
}
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
page . addText ( " \ n " ) ;
2018-06-06 09:50:26 +00:00
page . addText ( ChatColor . translateAlternateColorCodes ( '&' , " &6 \ u21E6 &lBack " ) ) ;
page . addHoverEvent ( HoverAction . SHOW_TEXT , ChatColor . translateAlternateColorCodes ( '&' , " &eClick to go back to the Category Overview " ) ) ;
2016-04-14 16:24:03 +00:00
page . addClickEvent ( new PlayerRunnable ( 2 ) {
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
@Override
public void run ( final Player p ) {
2019-10-11 21:48:46 +00:00
openMainMenuAsync ( p , survival , true , 1 ) ;
2016-04-14 16:24:03 +00:00
}
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
} ) ;
pages . add ( page ) ;
}
2019-10-11 21:48:46 +00:00
2019-10-05 21:49:25 +00:00
new CustomBookOverlay ( " Slimefun Guide " , " TheBusyBiscuit " , pages . toArray ( new TellRawMessage [ pages . size ( ) ] ) ) . open ( p ) ;
2016-04-14 16:24:03 +00:00
}
else {
final ChestMenu menu = new ChestMenu ( " Slimefun Guide " ) ;
2019-10-11 21:48:46 +00:00
2018-04-25 04:30:41 +00:00
menu . setEmptySlotsClickable ( false ) ;
2019-09-06 10:11:37 +00:00
menu . addMenuOpeningHandler ( pl - > pl . playSound ( pl . getLocation ( ) , Sound . ITEM_BOOK_PAGE_TURN , 1 , 1 ) ) ;
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
int index = 9 ;
2019-09-27 19:40:51 +00:00
final int pages = ( category . getItems ( ) . size ( ) - 1 ) / CATEGORY_SIZE + 1 ;
2016-04-14 16:24:03 +00:00
for ( int i = 0 ; i < 4 ; i + + ) {
2018-09-04 09:33:57 +00:00
menu . addItem ( i , new CustomItem ( new ItemStack ( Material . GRAY_STAINED_GLASS_PANE ) , " " ) ) ;
2019-08-30 07:21:49 +00:00
menu . addMenuClickHandler ( i , ( pl , slot , item , action ) - > false ) ;
2016-04-14 16:24:03 +00:00
}
2019-10-11 21:48:46 +00:00
2018-09-04 09:33:57 +00:00
menu . addItem ( 4 , new CustomItem ( new ItemStack ( Material . ENCHANTED_BOOK ) , " &7 \ u21E6 Back " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 4 , ( pl , slot , item , action ) - > {
2019-10-11 21:48:46 +00:00
openMainMenuAsync ( pl , survival , book , 1 ) ;
2019-03-31 18:32:40 +00:00
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
for ( int i = 5 ; i < 9 ; i + + ) {
2018-09-04 09:33:57 +00:00
menu . addItem ( i , new CustomItem ( new ItemStack ( Material . GRAY_STAINED_GLASS_PANE ) , " " ) ) ;
2019-08-30 07:21:49 +00:00
menu . addMenuClickHandler ( i , ( pl , slot , item , action ) - > false ) ;
2016-04-14 16:24:03 +00:00
}
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
for ( int i = 45 ; i < 54 ; i + + ) {
2018-09-04 09:33:57 +00:00
menu . addItem ( i , new CustomItem ( new ItemStack ( Material . GRAY_STAINED_GLASS_PANE ) , " " ) ) ;
2019-08-30 07:21:49 +00:00
menu . addMenuClickHandler ( i , ( pl , slot , item , action ) - > false ) ;
2016-04-14 16:24:03 +00:00
}
2019-10-11 21:48:46 +00:00
2018-09-04 09:33:57 +00:00
menu . addItem ( 46 , new CustomItem ( new ItemStack ( Material . LIME_STAINED_GLASS_PANE ) , " &r \ u21E6 Previous Page " , " " , " &7( " + selected_page + " / " + pages + " ) " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 46 , ( pl , slot , item , action ) - > {
int next = selected_page - 1 ;
if ( next < 1 ) next = pages ;
if ( next ! = selected_page ) openCategory ( pl , category , survival , next , book ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
2019-10-11 21:48:46 +00:00
2018-09-04 09:33:57 +00:00
menu . addItem ( 52 , new CustomItem ( new ItemStack ( Material . LIME_STAINED_GLASS_PANE ) , " &rNext Page \ u21E8 " , " " , " &7( " + selected_page + " / " + pages + " ) " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 52 , ( pl , slot , item , action ) - > {
int next = selected_page + 1 ;
if ( next > pages ) next = 1 ;
if ( next ! = selected_page ) openCategory ( pl , category , survival , next , book ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
2019-10-11 21:48:46 +00:00
2019-10-05 21:49:25 +00:00
PlayerProfile profile = PlayerProfile . get ( p ) ;
2019-10-11 21:48:46 +00:00
2019-09-27 19:40:51 +00:00
int categoryIndex = CATEGORY_SIZE * ( selected_page - 1 ) ;
for ( int i = 0 ; i < CATEGORY_SIZE ; i + + ) {
2019-08-30 20:49:18 +00:00
int target = categoryIndex + i ;
2016-04-14 16:24:03 +00:00
if ( target > = category . getItems ( ) . size ( ) ) break ;
final SlimefunItem sfitem = category . getItems ( ) . get ( target ) ;
2019-10-11 21:48:46 +00:00
2016-05-16 11:12:28 +00:00
if ( Slimefun . isEnabled ( p , sfitem , false ) ) {
2019-10-05 21:49:25 +00:00
final Research research = sfitem . getResearch ( ) ;
if ( survival & & research ! = null & & ! profile . hasUnlocked ( research ) ) {
2016-05-16 11:12:28 +00:00
if ( Slimefun . hasPermission ( p , sfitem , false ) ) {
2019-10-05 21:49:25 +00:00
menu . addItem ( index , new CustomItem ( Material . BARRIER , " &r " + ItemUtils . getItemName ( sfitem . getItem ( ) ) , " &4&lLOCKED " , " " , " &a> Click to unlock " , " " , " &7Cost: &b " + research . getCost ( ) + " Level " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( index , ( pl , slot , item , action ) - > {
if ( ! Research . isResearching ( pl ) ) {
if ( research . canUnlock ( pl ) ) {
2019-10-11 21:48:46 +00:00
2019-08-25 14:07:06 +00:00
if ( profile . hasUnlocked ( research ) ) {
openCategory ( p , category , true , selected_page , book ) ;
}
2019-03-31 18:32:40 +00:00
else {
2019-08-31 09:36:45 +00:00
if ( ! ( pl . getGameMode ( ) = = GameMode . CREATIVE & & SlimefunPlugin . getSettings ( ) . researchesFreeInCreative ) ) {
2019-03-31 18:32:40 +00:00
pl . setLevel ( pl . getLevel ( ) - research . getCost ( ) ) ;
}
2017-10-07 06:54:56 +00:00
2019-03-31 18:32:40 +00:00
if ( pl . getGameMode ( ) = = GameMode . CREATIVE ) {
2019-08-31 09:36:45 +00:00
research . unlock ( pl , SlimefunPlugin . getSettings ( ) . researchesFreeInCreative ) ;
2019-03-31 18:32:40 +00:00
openCategory ( pl , category , survival , selected_page , book ) ;
2019-09-28 15:13:23 +00:00
}
2019-08-25 14:07:06 +00:00
else {
2019-03-31 18:32:40 +00:00
research . unlock ( pl , false ) ;
2019-08-31 09:36:45 +00:00
Bukkit . getScheduler ( ) . scheduleSyncDelayedTask ( SlimefunPlugin . instance , ( ) - > openCategory ( pl , category , survival , selected_page , book ) , 103L ) ;
2017-10-07 06:54:56 +00:00
}
2019-03-31 18:32:40 +00:00
}
2019-09-28 15:13:23 +00:00
}
2019-09-21 11:59:15 +00:00
else SlimefunPlugin . getLocal ( ) . sendMessage ( pl , " messages.not-enough-xp " , true ) ;
2016-04-14 16:24:03 +00:00
}
2019-03-31 18:32:40 +00:00
return false ;
2016-04-17 18:39:40 +00:00
} ) ;
2019-09-28 15:13:23 +00:00
2016-04-17 18:48:28 +00:00
index + + ;
2016-04-17 18:39:40 +00:00
}
2016-05-16 11:12:28 +00:00
else {
2019-09-09 02:10:53 +00:00
List < String > message = sfitem . getNoPermissionTooltip ( ) ;
2019-09-08 10:47:09 +00:00
menu . addItem ( index , new CustomItem ( Material . BARRIER , StringUtils . formatItemName ( sfitem . getItem ( ) , false ) , message . toArray ( new String [ message . size ( ) ] ) ) ) ;
2019-08-25 14:07:06 +00:00
menu . addMenuClickHandler ( index , ( pl , slot , item , action ) - > false ) ;
2016-05-16 11:12:28 +00:00
index + + ;
}
2016-04-14 16:24:03 +00:00
}
else {
2016-05-16 11:12:28 +00:00
menu . addItem ( index , sfitem . getItem ( ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( index , ( pl , slot , item , action ) - > {
if ( survival ) displayItem ( pl , item , true , book , 0 ) ;
2019-10-03 16:06:14 +00:00
else {
if ( sfitem instanceof MultiBlockMachine ) {
SlimefunPlugin . getLocal ( ) . sendMessage ( pl , " guide.cheat.no-multiblocks " ) ;
}
else {
pl . getInventory ( ) . addItem ( item ) ;
}
}
2019-03-31 18:32:40 +00:00
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
2016-04-17 18:48:28 +00:00
index + + ;
2016-04-14 16:24:03 +00:00
}
}
}
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
menu . open ( p ) ;
2019-09-28 15:13:23 +00:00
}
2016-04-14 16:24:03 +00:00
if ( survival ) {
2019-10-16 23:08:14 +00:00
PlayerProfile . get ( p , profile - > profile . getGuideHistory ( ) . add ( category ) ) ;
2016-04-14 16:24:03 +00:00
}
}
2019-10-16 23:08:14 +00:00
public static void openSearch ( Player player , String input , boolean cheat , boolean addToHistory ) {
PlayerProfile . get ( player , profile - > {
2019-10-16 23:21:04 +00:00
final ChestMenu menu = new ChestMenu ( " Searching for: " + shorten ( " " , input ) ) ;
2019-10-16 23:08:14 +00:00
menu . setEmptySlotsClickable ( false ) ;
fillInv ( menu , cheat ) ;
addBackButton ( menu , 1 , profile , false , cheat ) ;
2019-09-28 15:13:23 +00:00
2019-10-16 23:08:14 +00:00
String searchTerm = input . toLowerCase ( ) ;
2019-09-28 15:13:23 +00:00
2019-10-16 23:08:14 +00:00
int index = 9 ;
// Find items and add them
for ( SlimefunItem item : SlimefunItem . list ( ) ) {
final String itemName = ChatColor . stripColor ( item . getItem ( ) . getItemMeta ( ) . getDisplayName ( ) ) . toLowerCase ( ) ;
if ( itemName . isEmpty ( ) ) continue ;
if ( index = = 44 ) break ;
if ( itemName . equals ( searchTerm ) | | itemName . contains ( searchTerm ) ) {
menu . addItem ( index , item . getItem ( ) ) ;
menu . addMenuClickHandler ( index , ( pl , slot , itm , action ) - > {
if ( cheat ) {
pl . getInventory ( ) . addItem ( itm ) ;
}
else {
displayItem ( pl , itm , true , false , 0 ) ;
}
2019-10-11 21:48:46 +00:00
2019-10-16 23:08:14 +00:00
return false ;
} ) ;
2019-09-28 15:13:23 +00:00
2019-10-16 23:08:14 +00:00
index + + ;
}
2019-09-28 15:13:23 +00:00
}
2019-10-16 23:08:14 +00:00
if ( addToHistory ) {
profile . getGuideHistory ( ) . add ( searchTerm ) ;
}
2019-09-28 15:13:23 +00:00
2019-10-16 23:08:14 +00:00
menu . open ( player ) ;
} ) ;
2019-09-28 15:13:23 +00:00
}
2019-09-30 17:06:50 +00:00
private static void fillInv ( ChestMenu menu , boolean cheat ) {
2019-09-27 19:40:51 +00:00
for ( int i = 0 ; i < 9 ; i + + ) {
menu . addItem ( i , new CustomItem ( new ItemStack ( Material . GRAY_STAINED_GLASS_PANE ) , " " ) ) ;
menu . addMenuClickHandler ( i , ( arg0 , arg1 , arg2 , arg3 ) - > false ) ;
2019-09-05 11:29:19 +00:00
}
2019-09-27 19:40:51 +00:00
2019-09-28 15:13:23 +00:00
// Search feature!
2019-10-01 11:14:50 +00:00
menu . addItem ( 7 , new CustomItem ( Material . NAME_TAG , SlimefunPlugin . getLocal ( ) . getMessage ( " guide.search.name " ) , SlimefunPlugin . getLocal ( ) . getMessagesArray ( " guide.search.lore " ) ) ) ;
2019-10-11 21:48:46 +00:00
2019-09-28 15:13:23 +00:00
menu . addMenuClickHandler ( 7 , ( player , i , itemStack , clickAction ) - > {
player . closeInventory ( ) ;
2019-09-30 18:36:08 +00:00
SlimefunPlugin . getLocal ( ) . sendMessage ( player , " search.message " ) ;
2019-10-11 21:48:46 +00:00
ChatInput . waitForPlayer ( SlimefunPlugin . instance , player , msg - >
2019-10-01 11:14:50 +00:00
openSearch ( player , msg , cheat , true )
) ;
2019-09-28 15:13:23 +00:00
return false ;
} ) ;
2019-09-27 19:40:51 +00:00
for ( int i = 45 ; i < 54 ; i + + ) {
menu . addItem ( i , new CustomItem ( new ItemStack ( Material . GRAY_STAINED_GLASS_PANE ) , " " ) ) ;
menu . addMenuClickHandler ( i , ( arg0 , arg1 , arg2 , arg3 ) - > false ) ;
}
}
2019-10-16 23:08:14 +00:00
private static void addBackButton ( ChestMenu menu , int slot , PlayerProfile profile , boolean book , boolean cheat ) {
List < Object > playerHistory = profile . getGuideHistory ( ) ;
2019-10-16 23:27:00 +00:00
if ( playerHistory . size ( ) > 1 ) {
2019-10-11 21:48:46 +00:00
2019-10-14 18:50:57 +00:00
menu . addItem ( slot , new CustomItem ( new ItemStack ( Material . ENCHANTED_BOOK ) ,
2019-09-27 19:40:51 +00:00
" &7 \ u21E6 Back " , " " ,
" &rLeft Click: &7Go back to previous Page " ,
" &rShift + left Click: &7Go back to Main Menu " )
) ;
2019-10-11 21:48:46 +00:00
2019-10-16 23:33:49 +00:00
menu . addMenuClickHandler ( slot , ( pl , s , is , action ) - > {
2019-10-11 21:48:46 +00:00
if ( action . isShiftClicked ( ) ) openMainMenuAsync ( pl , true , false , 1 ) ;
2019-09-27 19:40:51 +00:00
else {
2019-10-16 23:08:14 +00:00
Object last = getLastEntry ( profile , true ) ;
2019-09-28 15:13:23 +00:00
handleHistory ( pl , last , book , cheat ) ;
2019-09-27 19:40:51 +00:00
}
return false ;
} ) ;
2019-10-11 21:48:46 +00:00
}
2019-10-01 11:14:50 +00:00
else {
2019-10-16 23:33:49 +00:00
menu . addItem ( slot , new CustomItem ( new ItemStack ( Material . ENCHANTED_BOOK ) , " &7 \ u21E6 Back " , " " , " &rLeft Click: &7Go back to Main Menu " ) ) ;
2019-10-14 18:50:57 +00:00
menu . addMenuClickHandler ( 0 , ( pl , s , is , action ) - > {
2019-10-11 21:48:46 +00:00
openMainMenuAsync ( pl , true , book , 1 ) ;
2019-09-27 19:40:51 +00:00
return false ;
} ) ;
}
}
2019-10-16 23:08:14 +00:00
private static Object getLastEntry ( PlayerProfile profile , boolean remove ) {
LinkedList < Object > history = profile . getGuideHistory ( ) ;
2019-10-11 21:48:46 +00:00
2019-10-16 23:08:14 +00:00
if ( remove & & ! history . isEmpty ( ) ) {
2019-09-05 11:29:19 +00:00
history . removeLast ( ) ;
2016-04-14 16:24:03 +00:00
}
2019-10-11 21:48:46 +00:00
2019-10-16 23:08:14 +00:00
return history . isEmpty ( ) ? null : history . getLast ( ) ;
2016-04-14 16:24:03 +00:00
}
2019-03-27 20:41:29 +00:00
2019-10-11 21:48:46 +00:00
private static void displayItem ( Player p , final ItemStack item , boolean addToHistory , final boolean book , final int page ) {
2016-11-27 18:34:45 +00:00
if ( item = = null | | item . getType ( ) = = Material . AIR ) return ;
2016-04-14 16:24:03 +00:00
final SlimefunItem sfItem = SlimefunItem . getByItem ( item ) ;
2019-10-11 21:48:46 +00:00
2019-08-31 09:36:45 +00:00
if ( sfItem = = null & & ! SlimefunPlugin . getSettings ( ) . guideShowVanillaRecipes ) return ;
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
ItemStack [ ] recipe = new ItemStack [ 9 ] ;
ItemStack recipeType = null ;
ItemStack recipeOutput = item ;
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
ChestMenu menu = new ChestMenu ( " Slimefun Guide " ) ;
2019-10-11 21:48:46 +00:00
2018-04-25 04:30:41 +00:00
menu . setEmptySlotsClickable ( false ) ;
2019-09-06 10:11:37 +00:00
menu . addMenuOpeningHandler ( pl - > pl . playSound ( pl . getLocation ( ) , Sound . ITEM_BOOK_PAGE_TURN , 1 , 1 ) ) ;
2016-11-27 18:34:45 +00:00
2016-04-14 16:24:03 +00:00
if ( sfItem ! = null ) {
recipe = sfItem . getRecipe ( ) ;
recipeType = sfItem . getRecipeType ( ) . toItem ( ) ;
2018-06-06 09:41:56 +00:00
recipeOutput = sfItem . getRecipeOutput ( ) ! = null ? sfItem . getRecipeOutput ( ) : sfItem . getItem ( ) ;
2016-04-14 16:24:03 +00:00
}
else {
2019-08-25 14:07:06 +00:00
List < Recipe > recipes = new ArrayList < > ( ) ;
2016-04-14 16:24:03 +00:00
Iterator < Recipe > iterator = Bukkit . recipeIterator ( ) ;
while ( iterator . hasNext ( ) ) {
Recipe r = iterator . next ( ) ;
2019-03-27 20:41:29 +00:00
if ( SlimefunManager . isItemSimiliar ( new CustomItem ( r . getResult ( ) , 1 ) , item , true ) ) recipes . add ( r ) ;
2016-04-14 16:24:03 +00:00
}
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
if ( recipes . isEmpty ( ) ) return ;
2019-08-25 14:07:06 +00:00
Recipe r = recipes . get ( page ) ;
2019-10-11 21:48:46 +00:00
2019-08-25 14:07:06 +00:00
if ( recipes . size ( ) > page + 1 ) {
menu . addItem ( 1 , new CustomItem ( new ItemStack ( Material . ENCHANTED_BOOK ) , " &7Next \ u21E8 " , " " , " &e&l! &rThere are multiple recipes for this Item " ) ) ;
menu . addMenuClickHandler ( 1 , ( pl , slot , itemstack , action ) - > {
displayItem ( pl , itemstack , false , book , page + 1 ) ;
return false ;
} ) ;
}
2019-10-11 21:48:46 +00:00
2019-08-25 14:07:06 +00:00
if ( r instanceof ShapedRecipe ) {
String [ ] shape = ( ( ShapedRecipe ) r ) . getShape ( ) ;
for ( int i = 0 ; i < shape . length ; i + + ) {
for ( int j = 0 ; j < shape [ i ] . length ( ) ; j + + ) {
recipe [ i * 3 + j ] = ( ( ShapedRecipe ) r ) . getIngredientMap ( ) . get ( shape [ i ] . charAt ( j ) ) ;
}
}
recipeType = RecipeType . SHAPED_RECIPE . toItem ( ) ;
recipeOutput = r . getResult ( ) ;
}
else if ( r instanceof ShapelessRecipe ) {
List < ItemStack > ingredients = ( ( ShapelessRecipe ) r ) . getIngredientList ( ) ;
for ( int i = 0 ; i < ingredients . size ( ) ; i + + ) {
recipe [ i ] = ingredients . get ( i ) ;
}
recipeType = RecipeType . SHAPELESS_RECIPE . toItem ( ) ;
recipeOutput = r . getResult ( ) ;
}
else if ( r instanceof FurnaceRecipe ) {
recipe [ 4 ] = ( ( FurnaceRecipe ) r ) . getInput ( ) ;
2019-10-11 21:48:46 +00:00
2019-08-25 14:07:06 +00:00
recipeType = RecipeType . FURNACE . toItem ( ) ;
recipeOutput = r . getResult ( ) ;
}
2016-04-14 16:24:03 +00:00
}
2019-10-16 23:08:14 +00:00
PlayerProfile profile = PlayerProfile . get ( p ) ;
2019-10-11 21:48:46 +00:00
2019-10-16 23:08:14 +00:00
addBackButton ( menu , 0 , profile , book , false ) ;
2019-09-27 19:40:51 +00:00
2019-10-16 23:08:14 +00:00
LinkedList < Object > history = profile . getGuideHistory ( ) ;
2019-10-11 21:48:46 +00:00
2019-10-16 23:08:14 +00:00
if ( addToHistory ) {
history . add ( sfItem ! = null ? sfItem : item ) ;
}
2019-10-11 21:48:46 +00:00
2019-10-16 23:27:00 +00:00
if ( history . size ( ) > 1 ) {
2018-09-04 09:33:57 +00:00
menu . addItem ( 0 , 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 " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 0 , ( pl , slot , itemstack , action ) - > {
2019-10-11 21:48:46 +00:00
if ( action . isShiftClicked ( ) ) openMainMenuAsync ( p , true , book , 1 ) ;
2019-03-31 18:32:40 +00:00
else {
2019-10-16 23:08:14 +00:00
Object last = getLastEntry ( profile , true ) ;
2019-09-28 15:13:23 +00:00
handleHistory ( pl , last , book , false ) ;
2016-04-14 16:24:03 +00:00
}
2019-03-31 18:32:40 +00:00
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
}
else {
2018-09-04 09:33:57 +00:00
menu . addItem ( 0 , new CustomItem ( new ItemStack ( Material . ENCHANTED_BOOK ) , " &7 \ u21E6 Back " , " " , " &rLeft Click: &7Go back to Main Menu " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 0 , ( pl , slot , itemstack , action ) - > {
2019-10-11 21:48:46 +00:00
openMainMenuAsync ( pl , true , book , 1 ) ;
2019-03-31 18:32:40 +00:00
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
}
2019-10-11 21:48:46 +00:00
2019-10-05 21:49:25 +00:00
menu . addItem ( 3 , getDisplayItem ( p , sfItem ! = null , recipe [ 0 ] ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 3 , ( pl , slot , itemstack , action ) - > {
displayItem ( pl , itemstack , true , book , 0 ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
2019-10-11 21:48:46 +00:00
2019-10-05 21:49:25 +00:00
menu . addItem ( 4 , getDisplayItem ( p , sfItem ! = null , recipe [ 1 ] ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 4 , ( pl , slot , itemstack , action ) - > {
displayItem ( pl , itemstack , true , book , 0 ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
2019-10-11 21:48:46 +00:00
2019-10-05 21:49:25 +00:00
menu . addItem ( 5 , getDisplayItem ( p , sfItem ! = null , recipe [ 2 ] ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 5 , ( pl , slot , itemstack , action ) - > {
displayItem ( pl , itemstack , true , book , 0 ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
if ( sfItem ! = null ) {
2019-08-31 12:17:25 +00:00
if ( sfItem . hasWiki ( ) ) {
2016-04-14 16:24:03 +00:00
try {
2019-10-16 22:49:55 +00:00
menu . addItem ( 8 , new CustomItem ( Material . KNOWLEDGE_BOOK , " &rView this Item on our Wiki &7(Slimefun Wiki) " , " " , " &7 \ u21E8 Click to open " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 8 , ( pl , slot , itemstack , action ) - > {
pl . closeInventory ( ) ;
pl . sendMessage ( " " ) ;
2019-08-31 12:17:25 +00:00
pl . sendMessage ( ChatColor . translateAlternateColorCodes ( '&' , " &7&o " + sfItem . getWiki ( ) ) ) ;
2019-03-31 18:32:40 +00:00
pl . sendMessage ( " " ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
2019-08-31 12:17:25 +00:00
} catch ( Exception x ) {
Slimefun . getLogger ( ) . log ( Level . SEVERE , " An Error occured while adding a Wiki Page for Slimefun " + Slimefun . getVersion ( ) , x ) ;
2016-04-14 16:24:03 +00:00
}
}
2019-10-11 21:48:46 +00:00
2018-06-06 09:41:56 +00:00
if ( Slimefun . getItemConfig ( ) . contains ( sfItem . getID ( ) + " .youtube " ) ) {
2016-04-14 16:24:03 +00:00
try {
2016-11-23 15:51:57 +00:00
menu . addItem ( 7 , new CustomItem ( CustomSkull . getItem ( " eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjQzNTNmZDBmODYzMTQzNTM4NzY1ODYwNzViOWJkZjBjNDg0YWFiMDMzMWI4NzJkZjExYmQ1NjRmY2IwMjllZCJ9fX0= " ) , " &rDemonstration Video &7(Youtube) " , " " , " &7 \ u21E8 Click to watch " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 7 , ( pl , slot , itemstack , action ) - > {
pl . closeInventory ( ) ;
pl . sendMessage ( " " ) ;
pl . sendMessage ( ChatColor . translateAlternateColorCodes ( '&' , " &7&o " + Slimefun . getItemConfig ( ) . getString ( sfItem . getID ( ) + " .youtube " ) ) ) ;
pl . sendMessage ( " " ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
2019-08-31 12:17:25 +00:00
} catch ( Exception x ) {
Slimefun . getLogger ( ) . log ( Level . SEVERE , " An Error occured while adding a Youtube Video for Slimefun " + Slimefun . getVersion ( ) , x ) ;
2016-04-14 16:24:03 +00:00
}
}
}
menu . addItem ( 10 , recipeType ) ;
2019-08-25 14:07:06 +00:00
menu . addMenuClickHandler ( 10 , ( pl , slot , itemstack , action ) - > false ) ;
2019-10-11 21:48:46 +00:00
2019-10-05 21:49:25 +00:00
menu . addItem ( 12 , getDisplayItem ( p , sfItem ! = null , recipe [ 3 ] ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 12 , ( pl , slot , itemstack , action ) - > {
displayItem ( pl , itemstack , true , book , 0 ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
2019-10-11 21:48:46 +00:00
2019-10-05 21:49:25 +00:00
menu . addItem ( 13 , getDisplayItem ( p , sfItem ! = null , recipe [ 4 ] ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 13 , ( pl , slot , itemstack , action ) - > {
displayItem ( pl , itemstack , true , book , 0 ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
2019-10-11 21:48:46 +00:00
2019-10-05 21:49:25 +00:00
menu . addItem ( 14 , getDisplayItem ( p , sfItem ! = null , recipe [ 5 ] ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 14 , ( pl , slot , itemstack , action ) - > {
displayItem ( pl , itemstack , true , book , 0 ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
2019-10-11 21:48:46 +00:00
2016-04-14 16:24:03 +00:00
menu . addItem ( 16 , recipeOutput ) ;
2019-08-25 14:07:06 +00:00
menu . addMenuClickHandler ( 16 , ( pl , slot , itemstack , action ) - > false ) ;
2019-10-11 21:48:46 +00:00
2019-10-05 21:49:25 +00:00
menu . addItem ( 21 , getDisplayItem ( p , sfItem ! = null , recipe [ 6 ] ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 21 , ( pl , slot , itemstack , action ) - > {
displayItem ( pl , itemstack , true , book , 0 ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
2019-10-11 21:48:46 +00:00
2019-10-05 21:49:25 +00:00
menu . addItem ( 22 , getDisplayItem ( p , sfItem ! = null , recipe [ 7 ] ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 22 , ( pl , slot , itemstack , action ) - > {
displayItem ( pl , itemstack , true , book , 0 ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
2019-10-11 21:48:46 +00:00
2019-10-05 21:49:25 +00:00
menu . addItem ( 23 , getDisplayItem ( p , sfItem ! = null , recipe [ 8 ] ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 23 , ( pl , slot , itemstack , action ) - > {
displayItem ( pl , itemstack , true , book , 0 ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
2019-10-11 21:48:46 +00:00
2019-09-21 19:40:54 +00:00
if ( sfItem instanceof RecipeDisplayItem ) {
displayRecipes ( menu , ( RecipeDisplayItem ) sfItem , 0 ) ;
}
2019-10-11 21:48:46 +00:00
2019-09-21 19:40:54 +00:00
menu . open ( p ) ;
}
2019-09-27 19:40:51 +00:00
2019-10-05 21:49:25 +00:00
private static ItemStack getDisplayItem ( Player p , boolean isSlimefunRecipe , ItemStack item ) {
if ( isSlimefunRecipe ) {
SlimefunItem slimefunItem = SlimefunItem . getByItem ( item ) ;
if ( slimefunItem = = null ) return item ;
2019-10-11 21:48:46 +00:00
2019-10-05 21:49:25 +00:00
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 ;
}
}
2019-09-28 15:13:23 +00:00
private static void handleHistory ( Player pl , Object last , boolean book , boolean cheat ) {
2019-10-16 23:21:04 +00:00
if ( last instanceof Category ) openCategory ( pl , ( Category ) last , ! cheat , 1 , book ) ;
2019-09-27 19:40:51 +00:00
else if ( last instanceof SlimefunItem ) displayItem ( pl , ( ( SlimefunItem ) last ) . getItem ( ) , false , book , 0 ) ;
else if ( last instanceof GuideHandler ) ( ( GuideHandler ) last ) . run ( pl , true , book ) ;
2019-10-16 23:21:04 +00:00
else if ( last instanceof String ) openSearch ( pl , ( String ) last , cheat , false ) ;
2019-09-27 19:40:51 +00:00
else displayItem ( pl , ( ItemStack ) last , false , book , 0 ) ;
}
2019-09-21 19:40:54 +00:00
private static void displayRecipes ( ChestMenu menu , RecipeDisplayItem sfItem , int page ) {
List < ItemStack > recipes = sfItem . getDisplayRecipes ( ) ;
2019-10-11 21:48:46 +00:00
2019-09-21 19:40:54 +00:00
if ( ! recipes . isEmpty ( ) ) {
menu . addItem ( 53 , null ) ;
2019-10-11 21:48:46 +00:00
2019-09-21 19:40:54 +00:00
if ( page = = 0 ) {
2016-04-14 16:24:03 +00:00
for ( int i = 27 ; i < 36 ; i + + ) {
2019-09-21 19:40:54 +00:00
menu . replaceExistingItem ( i , new CustomItem ( Material . GRAY_STAINED_GLASS_PANE , sfItem . getRecipeSectionLabel ( ) ) ) ;
menu . addMenuClickHandler ( i , ( pl , slot , itemstack , action ) - > false ) ;
2016-04-14 16:24:03 +00:00
}
2019-09-21 19:40:54 +00:00
}
else {
menu . replaceExistingItem ( 28 , new CustomItem ( Material . LIME_STAINED_GLASS_PANE , " &a \ u21E6 Previous Page " ) ) ;
menu . addMenuClickHandler ( 28 , ( pl , slot , itemstack , action ) - > {
displayRecipes ( menu , sfItem , page - 1 ) ;
pl . playSound ( pl . getLocation ( ) , Sound . ITEM_BOOK_PAGE_TURN , 1 , 1 ) ;
return false ;
} ) ;
}
2019-10-11 21:48:46 +00:00
2019-09-21 19:40:54 +00:00
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 ( 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 ) ;
}
2019-10-11 21:48:46 +00:00
2019-09-21 19:40:54 +00:00
int inputs = 36 ;
int outputs = 45 ;
2019-10-11 21:48:46 +00:00
2019-09-21 19:40:54 +00:00
for ( int i = 0 ; i < 18 ; i + + ) {
int slot = i % 2 = = 0 ? inputs + + : outputs + + ;
2019-10-11 21:48:46 +00:00
2019-09-21 19:40:54 +00:00
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 ( pl , itemstack , true , false , 0 ) ;
return false ;
} ) ;
}
else {
menu . replaceExistingItem ( slot , recipes . get ( i + ( page * 18 ) ) ) ;
2016-04-14 16:24:03 +00:00
}
}
2019-09-21 19:40:54 +00:00
else {
menu . replaceExistingItem ( slot , null ) ;
menu . addMenuClickHandler ( slot , ( pl , s , itemstack , action ) - > false ) ;
2016-04-14 16:24:03 +00:00
}
}
}
}
}