2012-03-03 18:54:16 +01:00
package com.gmail.nossr50.util ;
import java.util.ArrayList ;
import org.bukkit.ChatColor ;
import org.bukkit.entity.Player ;
2012-03-03 19:24:47 +01:00
import com.gmail.nossr50.datatypes.SkillType ;
2012-04-27 11:47:11 +02:00
import com.gmail.nossr50.locale.LocaleLoader ;
2012-03-03 18:54:16 +01:00
public class Page {
2012-06-05 15:57:10 +02:00
2012-03-03 19:24:47 +01:00
public static int getTotalPageNumber ( String address )
{
2012-04-27 11:47:11 +02:00
String [ ] addressSplit = LocaleLoader . getString ( address ) . split ( " \ n " ) ;
2012-03-03 21:43:50 +01:00
if ( addressSplit . length < = 8 )
2012-03-03 19:24:47 +01:00
return 1 ;
else
return ( addressSplit . length / 8 ) + 1 ;
}
2012-06-05 15:57:10 +02:00
2012-03-03 18:54:16 +01:00
public static ArrayList < String > grabPageContents ( String header , String address , int pagenum )
{
int pageIndexStart = 0 ;
2012-06-05 15:57:10 +02:00
2012-03-03 18:54:16 +01:00
//Determine what string to start at
if ( pagenum > 1 )
{
pageIndexStart = 8 * ( pagenum - 1 ) ;
}
2012-06-05 15:57:10 +02:00
2012-03-03 18:54:16 +01:00
ArrayList < String > allStrings = new ArrayList < String > ( ) ;
2012-04-27 11:47:11 +02:00
String split [ ] = LocaleLoader . getString ( address ) . split ( " \ n " ) ;
2012-06-05 15:57:10 +02:00
2012-03-03 18:54:16 +01:00
allStrings . add ( ChatColor . GOLD + " -= " + ChatColor . GREEN + header + ChatColor . GOLD + " =- " ) ; //So stylish
2012-06-05 15:57:10 +02:00
2012-03-03 18:54:16 +01:00
//Add targeted strings
2012-06-05 15:57:10 +02:00
2012-03-03 19:24:47 +01:00
while ( allStrings . size ( ) < 9 )
2012-03-03 18:54:16 +01:00
{
2012-03-03 21:43:50 +01:00
if ( pageIndexStart + allStrings . size ( ) > split . length )
2012-03-03 19:24:47 +01:00
allStrings . add ( " " ) ;
else
2012-03-03 21:43:50 +01:00
allStrings . add ( split [ pageIndexStart + allStrings . size ( ) - 1 ] ) ;
2012-03-03 18:54:16 +01:00
}
2012-06-05 15:57:10 +02:00
2012-03-03 19:24:47 +01:00
allStrings . add ( " Page " + pagenum + " of " + getTotalPageNumber ( address ) ) ;
2012-03-03 18:54:16 +01:00
return allStrings ;
}
2012-06-05 15:57:10 +02:00
2012-03-03 18:54:16 +01:00
public static void clearChat ( Player player )
{
2012-03-03 19:39:18 +01:00
for ( int x = 0 ; x < 20 ; x + + )
2012-03-03 18:54:16 +01:00
{
player . sendMessage ( " " ) ;
}
}
2012-06-05 15:57:10 +02:00
2012-03-03 19:24:47 +01:00
public static void grabGuidePageForSkill ( SkillType skilltype , Player player , String [ ] args )
{
2012-04-27 11:47:11 +02:00
String capitalized = Misc . getCapitalized ( skilltype . toString ( ) ) ;
2012-03-26 22:17:35 +02:00
player . sendMessage ( ChatColor . DARK_AQUA + " Guide for " + capitalized + " available type / " + skilltype . toString ( ) . toLowerCase ( ) + " ? [Page#] " ) ; //TODO: Needs more locale.
2012-03-03 19:24:47 +01:00
if ( args . length > = 1 )
{
if ( args [ 0 ] . equals ( " ? " ) )
{
2012-06-05 15:57:10 +02:00
2012-03-03 19:24:47 +01:00
String address = " Guides. " + capitalized ;
2012-06-05 15:57:10 +02:00
2012-04-27 11:47:11 +02:00
if ( args . length > 1 & & Misc . isInt ( args [ 1 ] ) & & Misc . getInt ( args [ 1 ] ) < = Page . getTotalPageNumber ( address ) )
2012-03-03 19:24:47 +01:00
{
2012-03-03 19:39:18 +01:00
Page . clearChat ( player ) ;
2012-04-27 11:47:11 +02:00
for ( String target : Page . grabPageContents ( capitalized + " Guide " , address , Misc . getInt ( args [ 1 ] ) ) )
2012-03-03 19:24:47 +01:00
{
player . sendMessage ( target ) ;
}
2012-03-03 22:04:12 +01:00
} else if ( args . length = = 1 )
{
Page . clearChat ( player ) ;
for ( String target : Page . grabPageContents ( capitalized + " Guide " , address , 1 ) )
{
player . sendMessage ( target ) ;
}
}
2012-06-05 15:57:10 +02:00
else if ( args . length > 1 & & Misc . getInt ( args [ 1 ] ) > Page . getTotalPageNumber ( address ) )
2012-03-03 19:24:47 +01:00
{
2012-03-26 22:17:35 +02:00
player . sendMessage ( " That page doesn't exist, there are only " + Page . getTotalPageNumber ( address ) + " total pages " ) ; //TODO: Needs more locale.
2012-03-03 19:24:47 +01:00
}
2012-04-27 11:47:11 +02:00
else if ( args . length > 1 & & ! Misc . isInt ( args [ 1 ] ) )
2012-03-03 19:24:47 +01:00
{
2012-03-26 22:17:35 +02:00
player . sendMessage ( " Not a valid page number! " ) ; //TODO: Needs more locale.
2012-03-03 19:24:47 +01:00
}
}
else
{
2012-03-26 22:17:35 +02:00
player . sendMessage ( ChatColor . RED + " Usage is / " + skilltype . toString ( ) . toLowerCase ( ) + " ? [page] " ) ; //TODO: Needs more locale.
2012-03-03 19:24:47 +01:00
}
}
}
}