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 ;
import java.util.List ;
import java.util.Map ;
import java.util.UUID ;
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 ;
import org.bukkit.inventory.meta.ItemMeta ;
2019-05-30 11:42:06 +00:00
import org.bukkit.inventory.meta.SkullMeta ;
2017-01-15 18:17:02 +00:00
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.Math.DoubleHandler ;
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 ;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunMachine ;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AGenerator ;
2016-11-20 16:50:20 +00:00
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AReactor ;
2017-01-15 18:17:02 +00:00
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel ;
2016-04-14 16:24:03 +00:00
import me.mrCookieSlime.Slimefun.Setup.Messages ;
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 ;
2019-09-02 09:12:34 +00:00
import me.mrCookieSlime.Slimefun.utils.RecipeDisplayItem ;
2016-04-14 16:24:03 +00:00
2019-08-27 21:08:13 +00:00
public final class SlimefunGuide {
private SlimefunGuide ( ) { }
2016-04-14 16:24:03 +00:00
private static final int category_size = 36 ;
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-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
}
2017-01-31 10:08:17 +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 } ;
2017-01-16 19:31:57 +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 " ) ;
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 )
) ;
2017-01-14 21:40:06 +00:00
2017-01-16 19:31:57 +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-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( i ,
( pl , slot , item , action ) - > false
) ;
2017-01-14 21:40:06 +00:00
}
2017-01-31 10:08:17 +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
} ) ;
}
2017-01-14 21:40:06 +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
} ) ;
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-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
} ) ;
2017-01-14 21:40:06 +00:00
menu . open ( p ) ;
}
public static void openCredits ( Player p , final ItemStack guide ) {
final ChestMenu menu = new ChestMenu ( " Credits " ) ;
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 )
) ;
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-03-31 18:32:40 +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
} ) ;
}
}
2017-01-15 18:17:02 +00:00
int index = 9 ;
double total = 0 ;
2019-08-31 09:36:45 +00:00
for ( Contributor contributor : SlimefunPlugin . getUtilities ( ) . contributors ) {
2017-12-09 15:28:45 +00:00
total + = contributor . getCommits ( ) ;
2017-01-15 18:17:02 +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 ) ;
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
}
2017-01-15 18:17:02 +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-01-15 18:17:02 +00:00
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 ) ;
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
} ) ;
index + + ;
}
2017-01-14 21:45:06 +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 ) {
openMainMenu ( p , false , false , 1 ) ;
}
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-08-30 07:21:49 +00:00
if ( ! getHistory ( ) . containsKey ( p . getUniqueId ( ) ) ) openMainMenu ( p , true , book , 1 ) ;
2016-04-14 16:24:03 +00:00
else {
2019-06-20 07:50:59 +00:00
Object last = getLastEntry ( p , false ) ;
if ( last instanceof Category ) openCategory ( p , ( Category ) last , true , 1 , book ) ;
else if ( last instanceof SlimefunItem ) displayItem ( p , ( ( SlimefunItem ) last ) . getItem ( ) , false , book , 0 ) ;
else if ( last instanceof GuideHandler ) ( ( GuideHandler ) last ) . run ( p , true , book ) ;
else displayItem ( p , ( ItemStack ) last , false , book , 0 ) ;
2016-04-14 16:24:03 +00:00
}
}
2019-08-30 07:21:49 +00:00
2017-12-30 00:31:50 +00:00
public static void openMainMenu ( final Player p , final boolean survival , final boolean book , final int selected_page ) {
2019-03-27 20:38:53 +00:00
if ( survival )
clearHistory ( p . getUniqueId ( ) ) ;
2016-04-14 16:24:03 +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 < > ( ) ;
2016-04-14 16:24:03 +00:00
int tier = 0 ;
for ( final Category category : Category . list ( ) ) {
2016-04-17 18:39:40 +00:00
boolean locked = true ;
for ( SlimefunItem item : category . getItems ( ) ) {
if ( Slimefun . isEnabled ( p , item , false ) ) {
locked = false ;
break ;
}
}
if ( locked ) {
// Dont display that Category...
}
else {
if ( tier < category . getTier ( ) ) {
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-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 ) ;
}
if ( category instanceof LockedCategory & & ! ( ( LockedCategory ) category ) . hasUnlocked ( p ) ) {
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 " ) ) ;
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
}
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
}
} ) ;
}
}
}
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
}
} ) ;
}
}
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 ) ;
}
new CustomBookOverlay ( " Slimefun Guide " , " mrCookieSlime " , pages . toArray ( new TellRawMessage [ pages . size ( ) ] ) ) . open ( p ) ;
}
else {
final ChestMenu menu = new ChestMenu ( " Slimefun Guide " ) ;
2018-04-25 04:30:41 +00:00
menu . setEmptySlotsClickable ( false ) ;
2019-09-06 05:05:06 +00:00
menu . addMenuOpeningHandler ( pl - > pl . playSound ( pl . getLocation ( ) , Sound . ITEM_BOOK_PAGE_TURN , Float . MAX_VALUE , 0 ) ) ;
2016-04-14 16:24:03 +00:00
2019-08-31 13:52:15 +00:00
List < Category > categories = SlimefunPlugin . getUtilities ( ) . currentlyEnabledCategories ;
2019-08-31 10:54:54 +00:00
List < GuideHandler > handlers = SlimefunPlugin . getUtilities ( ) . guideHandlers . values ( ) . stream ( ) . flatMap ( List : : stream ) . collect ( Collectors . toList ( ) ) ;
2016-04-14 16:24:03 +00:00
int index = 9 ;
2016-05-17 19:38:18 +00:00
int pages = 1 ;
2016-04-14 16:24:03 +00:00
for ( int i = 0 ; i < 9 ; i + + ) {
2018-09-04 09:33:57 +00:00
menu . addItem ( i , new CustomItem ( new ItemStack ( Material . GRAY_STAINED_GLASS_PANE ) , " " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( i ,
( pl , slot , item , action ) - > false
) ;
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-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( i ,
( pl , slot , item , action ) - > false
) ;
2016-04-14 16:24:03 +00:00
}
2016-05-17 19:38:18 +00:00
int target = ( category_size * ( selected_page - 1 ) ) - 1 ;
2016-04-14 16:24:03 +00:00
2016-05-17 19:38:18 +00:00
while ( target < ( categories . size ( ) + handlers . size ( ) - 1 ) ) {
if ( index > = category_size + 9 ) {
pages + + ;
break ;
2016-04-14 16:24:03 +00:00
}
2016-05-17 19:38:18 +00:00
2016-05-16 11:18:56 +00:00
target + + ;
2016-05-17 19:38:18 +00:00
2016-05-16 11:18:56 +00:00
if ( target > = categories . size ( ) ) {
2016-04-14 16:24:03 +00:00
if ( ! survival ) break ;
index = handlers . get ( target - categories . size ( ) ) . next ( p , index , menu ) ;
}
else {
final Category category = categories . get ( target ) ;
2016-04-17 18:39:40 +00:00
boolean locked = true ;
for ( SlimefunItem item : category . getItems ( ) ) {
if ( Slimefun . isEnabled ( p , item , false ) ) {
locked = false ;
break ;
}
}
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 + + ;
}
}
}
else if ( ( ( LockedCategory ) category ) . hasUnlocked ( p ) ) {
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-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-05-30 11:42:06 +00:00
menu . addItem ( index , new CustomItem ( Material . BARRIER , " &4LOCKED &7- &r " + category . getItem ( ) . getItemMeta ( ) . getDisplayName ( ) , parents . toArray ( new String [ parents . size ( ) ] ) ) ) ;
2019-03-31 18:32:40 +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 ;
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 ;
if ( next ! = selected_page ) openMainMenu ( pl , survival , book , next ) ;
return false ;
2016-05-17 19:38:18 +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 ;
if ( next ! = selected_page ) openMainMenu ( pl , survival , book , next ) ;
return false ;
2016-05-17 19:38:18 +00:00
} ) ;
2016-04-14 16:24:03 +00:00
menu . open ( p ) ;
}
}
public static String shorten ( String string , String string2 ) {
if ( ChatColor . stripColor ( string + string2 ) . length ( ) > 19 ) return ( string + ChatColor . stripColor ( string2 ) ) . substring ( 0 , 18 ) + " ... " ;
else return ( string + ChatColor . stripColor ( string2 ) ) ;
}
2017-12-30 00:31:50 +00:00
public 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 < > ( ) ;
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 ( ) ;
2017-06-23 11:06:08 +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-08-25 14:07:06 +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-08-25 14:07:06 +00:00
PlayerProfile profile = PlayerProfile . fromUUID ( p . getUniqueId ( ) ) ;
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-08-25 14:07:06 +00:00
2019-08-31 09:36:45 +00:00
Bukkit . getScheduler ( ) . scheduleSyncDelayedTask ( SlimefunPlugin . instance , ( ) - > openCategory ( p , category , survival , selected_page , book ) , 1L ) ;
2019-08-25 14:07:06 +00:00
}
else {
2017-10-07 06:54:56 +00:00
research . unlock ( p , false ) ;
2019-08-25 14:07:06 +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
}
}
} else Messages . local . sendTranslation ( p , " messages.not-enough-xp " , true ) ;
}
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 ) ) ) ) ;
2016-04-14 16:24:03 +00:00
2016-04-17 18:39:40 +00:00
StringBuilder tooltip = new StringBuilder ( ) ;
tooltip . append ( StringUtils . formatItemName ( item . getItem ( ) , false ) ) ;
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
}
2016-04-17 18:39:40 +00:00
2018-06-06 09:50:26 +00:00
tooltip . append ( ChatColor . translateAlternateColorCodes ( '&' , " \ n \ n&e&oClick for more Info " ) ) ;
2016-04-17 18:39:40 +00:00
tooltips . add ( tooltip . toString ( ) ) ;
actions . add ( new PlayerRunnable ( 2 ) {
@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 ) ;
}
}
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 + + ) {
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 ) ) ;
}
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 ) {
@Override
public void run ( final Player p ) {
2019-08-31 09:36:45 +00:00
Bukkit . getScheduler ( ) . scheduleSyncDelayedTask ( SlimefunPlugin . instance , ( ) - > openMainMenu ( p , survival , true , 1 ) , 1L ) ;
2016-04-14 16:24:03 +00:00
}
} ) ;
pages . add ( page ) ;
}
new CustomBookOverlay ( " Slimefun Guide " , " mrCookieSlime " , pages . toArray ( new TellRawMessage [ pages . size ( ) ] ) ) . open ( p ) ;
}
else {
final ChestMenu menu = new ChestMenu ( " Slimefun Guide " ) ;
2018-04-25 04:30:41 +00:00
menu . setEmptySlotsClickable ( false ) ;
2019-09-06 04:59:34 +00:00
menu . addMenuOpeningHandler ( pl - > pl . playSound ( pl . getLocation ( ) , Sound . ITEM_BOOK_PAGE_TURN , Float . MAX_VALUE , 0 ) ) ;
2016-04-14 16:24:03 +00:00
int index = 9 ;
2018-09-06 10:50:49 +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
}
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 ) - > {
openMainMenu ( pl , survival , book , 1 ) ;
return false ;
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
}
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
}
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
} ) ;
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-08-30 20:49:18 +00:00
int categoryIndex = category_size * ( selected_page - 1 ) ;
2016-04-14 16:24:03 +00:00
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 ) ;
2016-05-16 11:12:28 +00:00
if ( Slimefun . isEnabled ( p , sfitem , false ) ) {
if ( survival & & ! Slimefun . hasUnlocked ( p , sfitem . getItem ( ) , false ) & & sfitem . getResearch ( ) ! = null ) {
if ( Slimefun . hasPermission ( p , sfitem , false ) ) {
2017-07-21 09:50:59 +00:00
final Research research = sfitem . getResearch ( ) ;
2019-05-30 11:42:06 +00:00
menu . addItem ( index , new CustomItem ( Material . BARRIER , " &r " + StringUtils . formatItemName ( sfitem . getItem ( ) , false ) , " &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-08-25 14:07:06 +00:00
PlayerProfile profile = PlayerProfile . fromUUID ( p . getUniqueId ( ) ) ;
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-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-08-30 07:21:49 +00:00
}
else Messages . local . sendTranslation ( 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-08-30 07:21:49 +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-02 11:43:11 +00:00
List < String > list = Messages . local . getTranslation ( " tooltips.item-permission " ) ;
2019-09-04 06:55:20 +00:00
String [ ] strings = list . toArray ( new String [ list . size ( ) ] ) ;
CustomItem display = new CustomItem ( Material . BARRIER , StringUtils . formatItemName ( sfitem . getItem ( ) , false ) , strings ) ;
menu . addItem ( index , display ) ;
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 ) ;
else pl . getInventory ( ) . addItem ( item ) ;
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
}
}
}
menu . open ( p ) ;
}
if ( survival ) {
2019-06-20 07:50:59 +00:00
addToHistory ( p , category ) ;
2016-04-14 16:24:03 +00:00
}
}
2019-06-20 07:50:59 +00:00
public static void addToHistory ( Player p , Object obj ) {
List < Object > list = new ArrayList < > ( ) ;
2019-08-30 07:21:49 +00:00
if ( getHistory ( ) . containsKey ( p . getUniqueId ( ) ) ) list = getHistory ( ) . get ( p . getUniqueId ( ) ) ;
2019-06-20 07:50:59 +00:00
list . add ( obj ) ;
2019-08-30 07:21:49 +00:00
getHistory ( ) . put ( p . getUniqueId ( ) , list ) ;
2016-04-14 16:24:03 +00:00
}
2019-03-27 20:41:29 +00:00
2019-06-20 07:50:59 +00:00
private static Object getLastEntry ( Player p , boolean remove ) {
List < Object > list = new ArrayList < > ( ) ;
2019-08-30 07:21:49 +00:00
if ( getHistory ( ) . containsKey ( p . getUniqueId ( ) ) ) list = getHistory ( ) . get ( p . getUniqueId ( ) ) ;
2019-08-25 14:07:06 +00:00
2019-08-29 21:18:04 +00:00
if ( remove & & ! list . isEmpty ( ) ) {
2019-06-20 07:50:59 +00:00
Object obj = list . get ( list . size ( ) - 1 ) ;
list . remove ( obj ) ;
2016-04-14 16:24:03 +00:00
}
2019-08-25 14:07:06 +00:00
2019-08-30 07:21:49 +00:00
if ( list . isEmpty ( ) ) getHistory ( ) . remove ( p . getUniqueId ( ) ) ;
else getHistory ( ) . put ( p . getUniqueId ( ) , list ) ;
2019-08-25 14:07:06 +00:00
2016-04-14 16:24:03 +00:00
return list . isEmpty ( ) ? null : list . get ( list . size ( ) - 1 ) ;
}
2019-03-27 20:41:29 +00:00
2017-12-30 00:31:50 +00:00
public 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-08-25 14:07:06 +00:00
2019-08-31 09:36:45 +00:00
if ( sfItem = = null & & ! SlimefunPlugin . getSettings ( ) . guideShowVanillaRecipes ) return ;
2016-04-14 16:24:03 +00:00
ItemStack [ ] recipe = new ItemStack [ 9 ] ;
ItemStack recipeType = null ;
ItemStack recipeOutput = item ;
ChestMenu menu = new ChestMenu ( " Slimefun Guide " ) ;
2018-04-25 04:30:41 +00:00
menu . setEmptySlotsClickable ( false ) ;
2019-09-06 04:59:34 +00:00
menu . addMenuOpeningHandler ( pl - > pl . playSound ( pl . getLocation ( ) , Sound . ITEM_BOOK_PAGE_TURN , Float . MAX_VALUE , 0 ) ) ;
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
}
if ( recipes . isEmpty ( ) ) return ;
2019-08-25 14:07:06 +00:00
Recipe r = recipes . get ( page ) ;
2016-04-14 16:24:03 +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 ;
} ) ;
}
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 ( ) ;
recipeType = RecipeType . FURNACE . toItem ( ) ;
recipeOutput = r . getResult ( ) ;
}
2016-04-14 16:24:03 +00:00
}
2019-06-20 07:50:59 +00:00
if ( addToHistory ) addToHistory ( p , sfItem ! = null ? sfItem : item ) ;
2016-04-14 16:24:03 +00:00
2019-08-30 07:21:49 +00:00
if ( getHistory ( ) . containsKey ( p . getUniqueId ( ) ) & & getHistory ( ) . get ( p . getUniqueId ( ) ) . 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 ) - > {
if ( action . isShiftClicked ( ) ) openMainMenu ( p , true , book , 1 ) ;
else {
2019-06-20 07:50:59 +00:00
Object last = getLastEntry ( pl , true ) ;
if ( last instanceof Category ) openCategory ( pl , ( Category ) last , true , 1 , book ) ;
else if ( last instanceof SlimefunItem ) displayItem ( pl , ( ( SlimefunItem ) last ) . getItem ( ) , false , book , 0 ) ;
else if ( last instanceof GuideHandler ) ( ( GuideHandler ) last ) . run ( pl , true , book ) ;
else displayItem ( pl , ( ItemStack ) last , false , book , 0 ) ;
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 ) - > {
openMainMenu ( pl , true , book , 1 ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
}
2019-05-30 11:42:06 +00:00
menu . addItem ( 3 , Slimefun . hasUnlocked ( p , recipe [ 0 ] , false ) ? recipe [ 0 ] : new CustomItem ( Material . BARRIER , StringUtils . formatItemName ( recipe [ 0 ] , false ) , " &4&lLOCKED " , " " , Slimefun . hasPermission ( p , SlimefunItem . getByItem ( recipe [ 0 ] ) , false ) ? " &rNeeds to be unlocked elsewhere " : " &rNo Permission " ) ) ;
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-05-30 11:42:06 +00:00
menu . addItem ( 4 , Slimefun . hasUnlocked ( p , recipe [ 1 ] , false ) ? recipe [ 1 ] : new CustomItem ( Material . BARRIER , StringUtils . formatItemName ( recipe [ 1 ] , false ) , " &4&lLOCKED " , " " , Slimefun . hasPermission ( p , SlimefunItem . getByItem ( recipe [ 1 ] ) , false ) ? " &rNeeds to be unlocked elsewhere " : " &rNo Permission " ) ) ;
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-05-30 11:42:06 +00:00
menu . addItem ( 5 , Slimefun . hasUnlocked ( p , recipe [ 2 ] , false ) ? recipe [ 2 ] : new CustomItem ( Material . BARRIER , StringUtils . formatItemName ( recipe [ 2 ] , false ) , " &4&lLOCKED " , " " , Slimefun . hasPermission ( p , SlimefunItem . getByItem ( recipe [ 2 ] ) , false ) ? " &rNeeds to be unlocked elsewhere " : " &rNo Permission " ) ) ;
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
} ) ;
if ( sfItem ! = null ) {
2019-08-31 12:17:25 +00:00
if ( sfItem . hasWiki ( ) ) {
2016-04-14 16:24:03 +00:00
try {
2016-11-23 15:51:57 +00:00
menu . addItem ( 8 , new CustomItem ( CustomSkull . getItem ( " eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzY2OTJmOTljYzZkNzgyNDIzMDQxMTA1NTM1ODk0ODQyOThiMmU0YTAyMzNiNzY3NTNmODg4ZTIwN2VmNSJ9fX0= " ) , " &rView this Item in 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-08-25 14:07:06 +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 ) ;
2016-04-14 16:24:03 +00:00
2019-05-30 11:42:06 +00:00
menu . addItem ( 12 , Slimefun . hasUnlocked ( p , recipe [ 3 ] , false ) ? recipe [ 3 ] : new CustomItem ( Material . BARRIER , StringUtils . formatItemName ( recipe [ 3 ] , false ) , " &4&lLOCKED " , " " , Slimefun . hasPermission ( p , SlimefunItem . getByItem ( recipe [ 3 ] ) , false ) ? " &rNeeds to be unlocked elsewhere " : " &rNo Permission " ) ) ;
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-05-30 11:42:06 +00:00
menu . addItem ( 13 , Slimefun . hasUnlocked ( p , recipe [ 4 ] , false ) ? recipe [ 4 ] : new CustomItem ( Material . BARRIER , StringUtils . formatItemName ( recipe [ 4 ] , false ) , " &4&lLOCKED " , " " , Slimefun . hasPermission ( p , SlimefunItem . getByItem ( recipe [ 4 ] ) , false ) ? " &rNeeds to be unlocked elsewhere " : " &rNo Permission " ) ) ;
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-05-30 11:42:06 +00:00
menu . addItem ( 14 , Slimefun . hasUnlocked ( p , recipe [ 5 ] , false ) ? recipe [ 5 ] : new CustomItem ( Material . BARRIER , StringUtils . formatItemName ( recipe [ 5 ] , false ) , " &4&lLOCKED " , " " , Slimefun . hasPermission ( p , SlimefunItem . getByItem ( recipe [ 5 ] ) , false ) ? " &rNeeds to be unlocked elsewhere " : " &rNo Permission " ) ) ;
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
} ) ;
menu . addItem ( 16 , recipeOutput ) ;
2019-08-25 14:07:06 +00:00
menu . addMenuClickHandler ( 16 , ( pl , slot , itemstack , action ) - > false ) ;
2016-04-14 16:24:03 +00:00
2019-05-30 11:42:06 +00:00
menu . addItem ( 21 , Slimefun . hasUnlocked ( p , recipe [ 6 ] , false ) ? recipe [ 6 ] : new CustomItem ( Material . BARRIER , StringUtils . formatItemName ( recipe [ 6 ] , false ) , " &4&lLOCKED " , " " , Slimefun . hasPermission ( p , SlimefunItem . getByItem ( recipe [ 6 ] ) , false ) ? " &rNeeds to be unlocked elsewhere " : " &rNo Permission " ) ) ;
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-05-30 11:42:06 +00:00
menu . addItem ( 22 , Slimefun . hasUnlocked ( p , recipe [ 7 ] , false ) ? recipe [ 7 ] : new CustomItem ( Material . BARRIER , StringUtils . formatItemName ( recipe [ 7 ] , false ) , " &4&lLOCKED " , " " , Slimefun . hasPermission ( p , SlimefunItem . getByItem ( recipe [ 7 ] ) , false ) ? " &rNeeds to be unlocked elsewhere " : " &rNo Permission " ) ) ;
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-05-30 11:42:06 +00:00
menu . addItem ( 23 , Slimefun . hasUnlocked ( p , recipe [ 8 ] , false ) ? recipe [ 8 ] : new CustomItem ( Material . BARRIER , StringUtils . formatItemName ( recipe [ 8 ] , false ) , " &4&lLOCKED " , " " , Slimefun . hasPermission ( p , SlimefunItem . getByItem ( recipe [ 8 ] ) , false ) ? " &rNeeds to be unlocked elsewhere " : " &rNo Permission " ) ) ;
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
} ) ;
if ( sfItem ! = null ) {
2019-09-02 09:12:34 +00:00
if ( sfItem instanceof RecipeDisplayItem & & ! ( ( RecipeDisplayItem ) sfItem ) . getDisplayRecipes ( ) . isEmpty ( ) ) {
2016-04-14 16:24:03 +00:00
for ( int i = 27 ; i < 36 ; i + + ) {
2019-05-30 11:42:06 +00:00
menu . addItem ( i , new CustomItem ( Material . LIME_STAINED_GLASS_PANE , SlimefunItem . getByItem ( item ) instanceof SlimefunMachine ? " &7 \ u21E9 Recipes made in this Machine \ u21E9 " : " " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( i ,
( pl , slot , itemstack , action ) - > false
) ;
2016-04-14 16:24:03 +00:00
}
2019-09-02 09:12:34 +00:00
List < ItemStack > recipes = ( ( RecipeDisplayItem ) SlimefunItem . getByItem ( item ) ) . getDisplayRecipes ( ) ;
2019-08-30 20:49:18 +00:00
int recipeSize = recipes . size ( ) ;
if ( recipeSize > 18 ) recipeSize = 18 ;
2019-08-29 20:46:03 +00:00
int inputs = - 1 ;
int outputs = - 1 ;
2016-04-14 16:24:03 +00:00
2019-08-30 20:49:18 +00:00
for ( int i = 0 ; i < recipeSize ; i + + ) {
2016-04-14 16:24:03 +00:00
int slot = 36 ;
if ( i % 2 = = 1 ) {
slot = slot + 9 ;
outputs + + ;
}
else inputs + + ;
int addition = ( i % 2 = = 0 ? inputs : outputs ) ;
2019-09-02 09:12:34 +00:00
menu . addItem ( slot + addition , recipes . get ( i ) . clone ( ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( slot + addition , ( pl , slotn , itemstack , action ) - > {
displayItem ( pl , itemstack , true , book , 0 ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
}
}
else if ( sfItem instanceof AGenerator ) {
int slot = 27 ;
for ( MachineFuel fuel : ( ( AGenerator ) sfItem ) . getFuelTypes ( ) ) {
2019-05-30 18:00:40 +00:00
if ( slot > = 54 ) break ;
2016-04-14 16:24:03 +00:00
ItemStack fItem = fuel . getInput ( ) . clone ( ) ;
ItemMeta im = fItem . getItemMeta ( ) ;
2019-08-25 14:07:06 +00:00
List < String > lore = new ArrayList < > ( ) ;
2016-11-27 18:57:36 +00:00
lore . add ( ChatColor . translateAlternateColorCodes ( '&' , " &8 \ u21E8 &7Lasts " + getTimeLeft ( fuel . getTicks ( ) / 2 ) ) ) ;
lore . add ( ChatColor . translateAlternateColorCodes ( '&' , " &8 \ u21E8 &e \ u26A1 &7 " + ( ( ( AGenerator ) sfItem ) . getEnergyProduction ( ) * 2 ) + " J/s " ) ) ;
2019-08-27 14:26:35 +00:00
lore . add ( ChatColor . translateAlternateColorCodes ( '&' , " &8 \ u21E8 &e \ u26A1 &7 " + DoubleHandler . getFancyDouble ( ( double ) fuel . getTicks ( ) * ( ( AGenerator ) sfItem ) . getEnergyProduction ( ) ) + " J in total " ) ) ;
2016-04-14 16:24:03 +00:00
im . setLore ( lore ) ;
fItem . setItemMeta ( im ) ;
menu . addItem ( slot , fItem ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( slot ,
( pl , slotn , itemstack , action ) - > false
) ;
2016-04-14 16:24:03 +00:00
slot + + ;
}
}
2016-11-20 16:50:20 +00:00
else if ( sfItem instanceof AReactor ) {
2016-04-14 16:24:03 +00:00
int slot = 27 ;
2016-11-20 16:50:20 +00:00
for ( MachineFuel fuel : ( ( AReactor ) sfItem ) . getFuelTypes ( ) ) {
2019-05-30 18:00:40 +00:00
if ( slot > = 54 ) break ;
2016-04-14 16:24:03 +00:00
ItemStack fItem = fuel . getInput ( ) . clone ( ) ;
ItemMeta im = fItem . getItemMeta ( ) ;
2019-08-25 14:07:06 +00:00
List < String > lore = new ArrayList < > ( ) ;
2016-11-27 18:57:36 +00:00
lore . add ( ChatColor . translateAlternateColorCodes ( '&' , " &8 \ u21E8 &7Lasts " + getTimeLeft ( fuel . getTicks ( ) / 2 ) ) ) ;
lore . add ( ChatColor . translateAlternateColorCodes ( '&' , " &8 \ u21E8 &e \ u26A1 &7 " + ( ( ( AReactor ) sfItem ) . getEnergyProduction ( ) * 2 ) + " J/s " ) ) ;
2019-08-27 14:26:35 +00:00
lore . add ( ChatColor . translateAlternateColorCodes ( '&' , " &8 \ u21E8 &e \ u26A1 &7 " + DoubleHandler . getFancyDouble ( ( double ) fuel . getTicks ( ) * ( ( AReactor ) sfItem ) . getEnergyProduction ( ) ) + " J in total " ) ) ;
2016-04-14 16:24:03 +00:00
im . setLore ( lore ) ;
fItem . setItemMeta ( im ) ;
menu . addItem ( slot , fItem ) ;
2019-08-30 07:21:49 +00:00
menu . addMenuClickHandler ( slot , ( pl , slotn , itemstack , action ) - > false ) ;
2016-04-14 16:24:03 +00:00
slot + + ;
}
}
}
2019-03-27 20:41:29 +00:00
menu . open ( p ) ;
2016-04-14 16:24:03 +00:00
}
2019-08-30 07:21:49 +00:00
private static Map < UUID , List < Object > > getHistory ( ) {
2019-08-31 09:36:45 +00:00
return SlimefunPlugin . getUtilities ( ) . guideHistory ;
2019-08-30 07:21:49 +00:00
}
2016-04-14 16:24:03 +00:00
public static void clearHistory ( UUID uuid ) {
2019-08-30 07:21:49 +00:00
getHistory ( ) . remove ( uuid ) ;
2016-04-14 16:24:03 +00:00
}
2019-09-02 08:24:53 +00:00
private static String getTimeLeft ( int seconds ) {
2016-04-14 16:24:03 +00:00
String timeleft = " " ;
2019-09-02 08:24:53 +00:00
final int minutes = ( int ) ( seconds / 60L ) ;
2016-04-14 16:24:03 +00:00
if ( minutes > 0 ) {
timeleft = String . valueOf ( timeleft ) + minutes + " m " ;
}
2019-09-02 08:24:53 +00:00
seconds - = minutes * 60 ;
2016-04-14 16:24:03 +00:00
timeleft = String . valueOf ( timeleft ) + seconds + " s " ;
2016-11-23 15:51:57 +00:00
return " &7 " + timeleft ;
2016-04-14 16:24:03 +00:00
}
}