2015-07-26 16:51:12 +02:00
package com.plotsquared.bukkit.object ;
2014-11-18 23:17:55 +01:00
2015-01-13 17:38:15 +01:00
import java.util.ArrayList ;
import java.util.List ;
import java.util.UUID ;
2014-12-22 16:44:13 +01:00
2015-07-26 16:51:12 +02:00
import com.intellectualcrafters.plot.object.Plot ;
import com.intellectualcrafters.plot.object.PlotPlayer ;
2015-07-26 18:14:34 +02:00
2014-11-18 23:17:55 +01:00
import org.bukkit.Bukkit ;
import org.bukkit.ChatColor ;
import org.bukkit.Material ;
import org.bukkit.entity.Player ;
import org.bukkit.inventory.Inventory ;
import org.bukkit.inventory.InventoryHolder ;
import org.bukkit.inventory.ItemStack ;
import org.bukkit.inventory.meta.ItemMeta ;
2015-07-26 18:14:34 +02:00
import com.plotsquared.bukkit.util.UUIDHandler ;
2015-07-26 16:51:12 +02:00
import com.plotsquared.bukkit.util.bukkit.BukkitUtil ;
2014-11-18 23:17:55 +01:00
/ * *
* Created 2014 - 11 - 18 for PlotSquared
*
* @author Citymonstret
* /
public class InfoInventory implements InventoryHolder {
2014-12-18 03:15:11 +01:00
private final Plot plot ;
2014-11-18 23:17:55 +01:00
private final Inventory inventory ;
2014-12-18 03:15:11 +01:00
private final Player player ;
2015-02-23 02:32:27 +01:00
2014-11-18 23:17:55 +01:00
/ * *
* Constructor
*
2014-12-18 03:15:11 +01:00
* @param plot from which we take information
2014-11-18 23:17:55 +01:00
* /
2015-02-22 08:13:27 +01:00
public InfoInventory ( final Plot plot , final PlotPlayer plr ) {
2014-11-18 23:17:55 +01:00
this . plot = plot ;
2015-02-22 08:13:27 +01:00
this . player = ( ( BukkitPlayer ) plr ) . player ;
2014-11-18 23:17:55 +01:00
this . inventory = Bukkit . createInventory ( this , 9 , " Plot: " + plot . id . toString ( ) ) ;
}
2015-02-23 02:32:27 +01:00
2014-11-18 23:17:55 +01:00
@Override
public Inventory getInventory ( ) {
2014-12-16 06:03:20 +01:00
return this . inventory ;
2014-11-18 23:17:55 +01:00
}
2015-02-23 02:32:27 +01:00
2015-02-20 07:34:19 +01:00
public String getName ( final UUID uuid ) {
2015-03-20 05:11:02 +01:00
final String name = UUIDHandler . getName ( this . plot . owner ) ;
2014-12-22 16:44:13 +01:00
if ( name = = null ) {
return " unknown " ;
}
return name ;
}
2015-02-23 02:32:27 +01:00
2014-11-18 23:17:55 +01:00
public InfoInventory build ( ) {
2015-02-23 02:32:27 +01:00
final UUID uuid = UUIDHandler . getUUID ( BukkitUtil . getPlayer ( this . player ) ) ;
2015-07-21 20:31:12 +02:00
final ItemStack generalInfo = getItem ( Material . EMERALD , " &cPlot Info " , " &cID: &6 " + this . plot . getId ( ) . toString ( ) , " &cOwner: &6 " + getName ( this . plot . owner ) , " &cAlias: &6 " + this . plot . getSettings ( ) . getAlias ( ) , " &cBiome: &6 " + this . plot . getSettings ( ) . getBiome ( ) . toString ( ) . replaceAll ( " _ " , " " ) . toLowerCase ( ) , " &cCan Build: &6 " + this . plot . isAdded ( uuid ) , " &cIs Denied: &6 " + this . plot . isDenied ( uuid ) ) ;
final ItemStack trusted = getItem ( Material . EMERALD , " &cTrusted " , " &cAmount: &6 " + this . plot . getTrusted ( ) . size ( ) , " &8Click to view a list of the trusted users " ) ;
final ItemStack members = getItem ( Material . EMERALD , " &cMembers " , " &cAmount: &6 " + this . plot . getMembers ( ) . size ( ) , " &8Click to view a list of plot members " ) ;
final ItemStack denied = getItem ( Material . EMERALD , " &cDenied " , " &cAmount: &6 " + this . plot . getDenied ( ) . size ( ) , " &8Click to view a list of denied players " ) ;
final ItemStack flags = getItem ( Material . EMERALD , " &cFlags " , " &cAmount: &6 " + this . plot . getSettings ( ) . flags . size ( ) , " &8Click to view a list of plot flags " ) ;
2014-12-16 06:03:20 +01:00
this . inventory . setItem ( 2 , generalInfo ) ;
2015-05-14 14:55:57 +02:00
this . inventory . setItem ( 3 , trusted ) ;
this . inventory . setItem ( 4 , members ) ;
2014-12-16 06:03:20 +01:00
this . inventory . setItem ( 5 , denied ) ;
this . inventory . setItem ( 6 , flags ) ;
2014-11-18 23:17:55 +01:00
return this ;
}
2015-02-23 02:32:27 +01:00
2014-11-18 23:17:55 +01:00
public InfoInventory display ( ) {
2014-12-16 06:03:20 +01:00
this . player . closeInventory ( ) ;
this . player . openInventory ( this . inventory ) ;
2014-11-18 23:17:55 +01:00
return this ;
}
2015-02-23 02:32:27 +01:00
2014-12-16 06:03:20 +01:00
private ItemStack getItem ( final Material material , final String name , final String . . . lore ) {
final ItemStack stack = new ItemStack ( material ) ;
final ItemMeta meta = stack . getItemMeta ( ) ;
2014-11-18 23:17:55 +01:00
meta . setDisplayName ( ChatColor . translateAlternateColorCodes ( '&' , name ) ) ;
2014-12-16 06:03:20 +01:00
final List < String > lList = new ArrayList < > ( ) ;
for ( final String l : lore ) {
2014-11-18 23:17:55 +01:00
lList . add ( ChatColor . translateAlternateColorCodes ( '&' , l ) ) ;
2014-12-16 06:03:20 +01:00
}
2014-11-18 23:17:55 +01:00
meta . setLore ( lList ) ;
stack . setItemMeta ( meta ) ;
return stack ;
}
}