2016-04-14 16:24:03 +00:00
package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines ;
2018-09-05 16:36:32 +00:00
import me.mrCookieSlime.CSCoreLibPlugin.compatibility.MaterialHelper ;
2016-10-30 10:13:20 +00:00
import org.bukkit.Material ;
import org.bukkit.block.Block ;
import org.bukkit.entity.Player ;
import org.bukkit.inventory.ItemStack ;
import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib ;
2016-04-14 16:24:03 +00:00
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem ;
import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull ;
import me.mrCookieSlime.Slimefun.Lists.RecipeType ;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems ;
import me.mrCookieSlime.Slimefun.Objects.Category ;
import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler ;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem ;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason ;
import me.mrCookieSlime.Slimefun.Setup.Messages ;
import me.mrCookieSlime.Slimefun.api.BlockStorage ;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu ;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset ;
import me.mrCookieSlime.Slimefun.api.item_transport.CargoNet ;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow ;
public class CargoInputNode extends SlimefunItem {
private static final int [ ] border = { 0 , 1 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 17 , 18 , 22 , 23 , 26 , 27 , 31 , 32 , 33 , 34 , 35 , 36 , 40 , 44 , 45 , 46 , 47 , 48 , 49 , 50 , 51 , 52 , 53 } ;
public CargoInputNode ( Category category , ItemStack item , String name , RecipeType recipeType , ItemStack [ ] recipe , ItemStack recipeOutput ) {
super ( category , item , name , recipeType , recipe , recipeOutput ) ;
2016-11-23 15:51:57 +00:00
new BlockMenuPreset ( name , " &3Input Node " ) {
2016-04-14 16:24:03 +00:00
@Override
public void init ( ) {
constructMenu ( this ) ;
}
@Override
public void newInstance ( final BlockMenu menu , final Block b ) {
try {
2018-06-06 09:41:56 +00:00
if ( ! BlockStorage . hasBlockInfo ( b ) | | BlockStorage . getLocationInfo ( b . getLocation ( ) , " filter-type " ) = = null | | BlockStorage . getLocationInfo ( b . getLocation ( ) , " filter-type " ) . equals ( " whitelist " ) ) {
2018-09-05 16:36:32 +00:00
menu . replaceExistingItem ( 15 , new CustomItem ( new ItemStack ( Material . WHITE_WOOL ) , " &7Type: &rWhitelist " , " " , " &e> Click to change it to Blacklist " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 15 , ( p , slot , item , action ) - > {
BlockStorage . addBlockInfo ( b , " filter-type " , " blacklist " ) ;
newInstance ( menu , b ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
}
else {
2018-09-05 16:36:32 +00:00
menu . replaceExistingItem ( 15 , new CustomItem ( new ItemStack ( Material . BLACK_WOOL ) , " &7Type: &8Blacklist " , " " , " &e> Click to change it to Whitelist " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 15 , ( p , slot , item , action ) - > {
BlockStorage . addBlockInfo ( b , " filter-type " , " whitelist " ) ;
newInstance ( menu , b ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
}
2018-06-06 09:41:56 +00:00
if ( ! BlockStorage . hasBlockInfo ( b ) | | BlockStorage . getLocationInfo ( b . getLocation ( ) , " filter-durability " ) = = null | | BlockStorage . getLocationInfo ( b . getLocation ( ) , " filter-durability " ) . equals ( " false " ) ) {
2018-09-05 16:36:32 +00:00
menu . replaceExistingItem ( 16 , new CustomItem ( new ItemStack ( Material . STONE_SWORD , ( byte ) 20 ) , " &7Include Sub-IDs/Durability: &4 \ u2718 " , " " , " &e> Click to toggle whether the Durability has to match " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 16 , ( p , slot , item , action ) - > {
BlockStorage . addBlockInfo ( b , " filter-durability " , " true " ) ;
newInstance ( menu , b ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
}
else {
2018-09-05 16:36:32 +00:00
menu . replaceExistingItem ( 16 , new CustomItem ( new ItemStack ( Material . GOLDEN_SWORD , ( byte ) 20 ) , " &7Include Sub-IDs/Durability: &2 \ u2714 " , " " , " &e> Click to toggle whether the Durability has to match " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 16 , ( p , slot , item , action ) - > {
BlockStorage . addBlockInfo ( b , " filter-durability " , " false " ) ;
newInstance ( menu , b ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
}
2018-06-06 09:41:56 +00:00
if ( ! BlockStorage . hasBlockInfo ( b ) | | BlockStorage . getLocationInfo ( b . getLocation ( ) , " round-robin " ) = = null | | BlockStorage . getLocationInfo ( b . getLocation ( ) , " round-robin " ) . equals ( " false " ) ) {
2016-11-23 15:51:57 +00:00
menu . replaceExistingItem ( 24 , new CustomItem ( CustomSkull . getItem ( " eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDc4ZjJiN2U1ZTc1NjM5ZWE3ZmI3OTZjMzVkMzY0YzRkZjI4YjQyNDNlNjZiNzYyNzdhYWRjZDYyNjEzMzcifX19 " ) , " &7Round-Robin Mode: &4 \ u2718 " , " " , " &e> Click to enable Round Robin Mode " , " &e(Items will be equally distributed on the Channel) " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 24 , ( p , slot , item , action ) - > {
BlockStorage . addBlockInfo ( b , " round-robin " , " true " ) ;
newInstance ( menu , b ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
}
else {
2016-11-23 15:51:57 +00:00
menu . replaceExistingItem ( 24 , new CustomItem ( CustomSkull . getItem ( " eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDc4ZjJiN2U1ZTc1NjM5ZWE3ZmI3OTZjMzVkMzY0YzRkZjI4YjQyNDNlNjZiNzYyNzdhYWRjZDYyNjEzMzcifX19 " ) , " &7Round-Robin Mode: &2 \ u2714 " , " " , " &e> Click to disable Round Robin Mode " , " &e(Items will be equally distributed on the Channel) " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 24 , ( p , slot , item , action ) - > {
BlockStorage . addBlockInfo ( b , " round-robin " , " false " ) ;
newInstance ( menu , b ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
}
2018-06-06 09:41:56 +00:00
if ( ! BlockStorage . hasBlockInfo ( b ) | | BlockStorage . getLocationInfo ( b . getLocation ( ) , " filter-lore " ) = = null | | BlockStorage . getLocationInfo ( b . getLocation ( ) , " filter-lore " ) . equals ( " true " ) ) {
2018-09-05 16:36:32 +00:00
menu . replaceExistingItem ( 25 , new CustomItem ( new ItemStack ( Material . MAP ) , " &7Include Lore: &2 \ u2714 " , " " , " &e> Click to toggle whether the Lore has to match " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 25 , ( p , slot , item , action ) - > {
BlockStorage . addBlockInfo ( b , " filter-lore " , " false " ) ;
newInstance ( menu , b ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
}
else {
2018-09-05 16:36:32 +00:00
menu . replaceExistingItem ( 25 , new CustomItem ( new ItemStack ( Material . MAP ) , " &7Include Lore: &4 \ u2718 " , " " , " &e> Click to toggle whether the Lore has to match " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 25 , ( p , slot , item , action ) - > {
BlockStorage . addBlockInfo ( b , " filter-lore " , " true " ) ;
newInstance ( menu , b ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
}
2016-11-23 15:51:57 +00:00
menu . replaceExistingItem ( 41 , new CustomItem ( CustomSkull . getItem ( " eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjI1OTliZDk4NjY1OWI4Y2UyYzQ5ODg1MjVjOTRlMTlkZGQzOWZhZDA4YTM4Mjg0YTE5N2YxYjcwNjc1YWNjIn19fQ== " ) , " &bChannel " , " " , " &e> Click to decrease the Channel ID by 1 " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 41 , ( p , slot , item , action ) - > {
int channel = Integer . parseInt ( BlockStorage . getLocationInfo ( b . getLocation ( ) , " frequency " ) ) - 1 ;
if ( channel < 0 ) {
if ( CargoNet . EXTRA_CHANNELS ) channel = 16 ;
else channel = 15 ;
2016-04-14 16:24:03 +00:00
}
2019-03-31 18:32:40 +00:00
BlockStorage . addBlockInfo ( b , " frequency " , String . valueOf ( channel ) ) ;
newInstance ( menu , b ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
2018-06-06 09:41:56 +00:00
int channel = ( ( ! BlockStorage . hasBlockInfo ( b ) | | BlockStorage . getLocationInfo ( b . getLocation ( ) , " frequency " ) = = null ) ? 0 : ( Integer . parseInt ( BlockStorage . getLocationInfo ( b . getLocation ( ) , " frequency " ) ) ) ) ;
2016-04-14 16:24:03 +00:00
if ( channel = = 16 ) {
2016-11-23 15:51:57 +00:00
menu . replaceExistingItem ( 42 , new CustomItem ( SlimefunItems . CHEST_TERMINAL , " &bChannel ID: &3 " + ( channel + 1 ) ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 42 ,
( p , slot , item , action ) - > false
) ;
2016-04-14 16:24:03 +00:00
}
else {
2018-09-05 16:36:32 +00:00
menu . replaceExistingItem ( 42 , new CustomItem ( new ItemStack ( MaterialHelper . WoolColours [ channel ] ) , " &bChannel ID: &3 " + ( channel + 1 ) ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 42 ,
( p , slot , item , action ) - > false
) ;
2016-04-14 16:24:03 +00:00
}
2016-11-23 15:51:57 +00:00
menu . replaceExistingItem ( 43 , new CustomItem ( CustomSkull . getItem ( " eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzJmOTEwYzQ3ZGEwNDJlNGFhMjhhZjZjYzgxY2Y0OGFjNmNhZjM3ZGFiMzVmODhkYjk5M2FjY2I5ZGZlNTE2In19fQ== " ) , " &bChannel " , " " , " &e> Click to increase the Channel ID by 1 " ) ) ;
2019-03-31 18:32:40 +00:00
menu . addMenuClickHandler ( 43 , ( p , slot , item , action ) - > {
int channeln = Integer . parseInt ( BlockStorage . getLocationInfo ( b . getLocation ( ) , " frequency " ) ) + 1 ;
2016-04-14 16:24:03 +00:00
2019-03-31 18:32:40 +00:00
if ( CargoNet . EXTRA_CHANNELS ) {
if ( channeln > 16 ) channeln = 0 ;
}
else {
if ( channeln > 15 ) channeln = 0 ;
2016-04-14 16:24:03 +00:00
}
2019-03-31 18:32:40 +00:00
2019-04-13 10:47:22 +00:00
BlockStorage . addBlockInfo ( b , " frequency " , String . valueOf ( channeln ) ) ;
2019-03-31 18:32:40 +00:00
newInstance ( menu , b ) ;
return false ;
2016-04-14 16:24:03 +00:00
} ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
}
@Override
public boolean canOpen ( Block b , Player p ) {
2016-10-30 10:01:47 +00:00
boolean open = CSCoreLib . getLib ( ) . getProtectionManager ( ) . canAccessChest ( p . getUniqueId ( ) , b ) | | p . hasPermission ( " slimefun.cargo.bypass " ) ;
2016-04-14 16:24:03 +00:00
if ( ! open ) {
Messages . local . sendTranslation ( p , " inventory.no-access " , true ) ;
}
return open ;
}
@Override
public int [ ] getSlotsAccessedByItemTransport ( ItemTransportFlow flow ) {
return new int [ 0 ] ;
}
} ;
registerBlockHandler ( name , new SlimefunBlockHandler ( ) {
@Override
public void onPlace ( Player p , Block b , SlimefunItem item ) {
BlockStorage . addBlockInfo ( b , " owner " , p . getUniqueId ( ) . toString ( ) ) ;
BlockStorage . addBlockInfo ( b , " index " , " 0 " ) ;
BlockStorage . addBlockInfo ( b , " frequency " , " 0 " ) ;
BlockStorage . addBlockInfo ( b , " filter-type " , " whitelist " ) ;
BlockStorage . addBlockInfo ( b , " filter-lore " , " true " ) ;
BlockStorage . addBlockInfo ( b , " filter-durability " , " false " ) ;
BlockStorage . addBlockInfo ( b , " round-robin " , " false " ) ;
}
@Override
public boolean onBreak ( Player p , Block b , SlimefunItem item , UnregisterReason reason ) {
2018-04-28 16:05:43 +00:00
BlockMenu inv = BlockStorage . getInventory ( b ) ;
if ( inv ! = null ) {
2019-03-31 18:32:40 +00:00
for ( int slot : getInputSlots ( ) ) {
2018-04-28 16:05:43 +00:00
if ( inv . getItemInSlot ( slot ) ! = null ) {
b . getWorld ( ) . dropItemNaturally ( b . getLocation ( ) , inv . getItemInSlot ( slot ) ) ;
inv . replaceExistingItem ( slot , null ) ;
}
2018-04-26 03:40:46 +00:00
}
2016-04-14 16:24:03 +00:00
}
return true ;
}
} ) ;
}
protected void constructMenu ( BlockMenuPreset preset ) {
2019-03-31 18:32:40 +00:00
for ( int i : border ) {
2018-09-05 16:36:32 +00:00
preset . addItem ( i , new CustomItem ( new ItemStack ( Material . CYAN_STAINED_GLASS_PANE ) , " " ) ,
2019-03-31 18:32:40 +00:00
( p , slot , item , action ) - > false
) ;
2016-04-14 16:24:03 +00:00
}
2018-09-05 16:36:32 +00:00
preset . addItem ( 2 , new CustomItem ( new ItemStack ( Material . PAPER ) , " &3Items " , " " , " &bPut in all Items you want to " , " &bblacklist/whitelist " ) ,
2019-03-31 18:32:40 +00:00
( p , slot , item , action ) - > false
) ;
2016-04-14 16:24:03 +00:00
}
public int [ ] getInputSlots ( ) {
return new int [ ] { 19 , 20 , 21 , 28 , 29 , 30 , 37 , 38 , 39 } ;
}
2019-03-31 18:32:40 +00:00
2016-04-14 16:24:03 +00:00
}