final variables and static classes
- make some variables final - turn to static ItemLoad and ItemNBT
This commit is contained in:
parent
0db2b81316
commit
cfb573e376
@ -9,20 +9,18 @@ import tokarotik.giftapi.inventory.InventoryManager;
|
||||
|
||||
public class APIManager {
|
||||
|
||||
public Main plugin;
|
||||
private FileConfiguration config;
|
||||
private InventoryManager inventoryManager;
|
||||
public final Main plugin;
|
||||
private final InventoryManager inventoryManager;
|
||||
|
||||
public APIManager(Main plugin, FileConfiguration config)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.config = config;
|
||||
|
||||
this.inventoryManager = new InventoryManager(
|
||||
this.config.getString(ConfigPaths.GUINAME, "GiftAPI Menu"),
|
||||
this.config.getString(ConfigPaths.GUIRIGHT, "<<right"),
|
||||
this.config.getString(ConfigPaths.GUILEFT, "left>>"),
|
||||
this.config.getString(ConfigPaths.GUIEXIT, "quit")
|
||||
config.getString(ConfigPaths.GUINAME, "GiftAPI Menu"),
|
||||
config.getString(ConfigPaths.GUIRIGHT, "<<right"),
|
||||
config.getString(ConfigPaths.GUILEFT, "left>>"),
|
||||
config.getString(ConfigPaths.GUIEXIT, "quit")
|
||||
);
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(this.inventoryManager, this.plugin);
|
||||
|
@ -10,7 +10,7 @@ import tokarotik.giftapi.savemanager.NBTManager;
|
||||
|
||||
public class GiftCommand implements CommandExecutor {
|
||||
|
||||
private APIManager apiManager;
|
||||
private final APIManager apiManager;
|
||||
|
||||
public GiftCommand(APIManager APIManager)
|
||||
{
|
||||
|
@ -15,10 +15,10 @@ public class InventoryManager implements Listener {
|
||||
|
||||
public final int countSlots = 54;
|
||||
|
||||
private String nameGUI;
|
||||
private String nameArrowRight;
|
||||
private String nameArrowLeft;
|
||||
private String nameExit;
|
||||
private final String nameGUI;
|
||||
private final String nameArrowRight;
|
||||
private final String nameArrowLeft;
|
||||
private final String nameExit;
|
||||
|
||||
public InventoryManager(String nameGUI, String nameArrowRight, String nameArrowLeft, String nameExit)
|
||||
{
|
||||
@ -42,8 +42,8 @@ public class InventoryManager implements Listener {
|
||||
if (inventory.getTitle().equals(this.nameGUI)) {
|
||||
event.setCancelled(true);
|
||||
|
||||
ItemStack currectItem = event.getCurrentItem();
|
||||
String nameCurrentItem = currectItem.getItemMeta().getDisplayName();
|
||||
ItemStack currentItem = event.getCurrentItem();
|
||||
String nameCurrentItem = currentItem.getItemMeta().getDisplayName();
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
||||
if (nameCurrentItem.equals(this.nameArrowRight))
|
||||
@ -76,7 +76,6 @@ public class InventoryManager implements Listener {
|
||||
setArrow(inventory, this.nameArrowLeft, 0, 6);
|
||||
// exit
|
||||
setItem(inventory, Material.REDSTONE, this.nameExit, 4, 6);
|
||||
//setSkull(inventory, "exit", ChatColor.ITALIC + "" + ChatColor.DARK_RED + "Выйти", 4, 6);
|
||||
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class NBTManager
|
||||
{
|
||||
private BasicNBT basicNBT;
|
||||
private final BasicNBT basicNBT;
|
||||
|
||||
public NBTManager(String world)
|
||||
{
|
||||
|
@ -12,64 +12,59 @@ import java.util.List;
|
||||
public class ItemLoad
|
||||
{
|
||||
|
||||
NBTTagCompound tag;
|
||||
|
||||
public ItemLoad(NBTTagCompound tag)
|
||||
{
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public ItemStack getItem()
|
||||
public static ItemStack getItem(NBTTagCompound tag)
|
||||
{
|
||||
|
||||
ItemStack item = new ItemStack(
|
||||
getId(), getCount(), getDurability()
|
||||
getId(tag), getCount(tag), getDurability(tag)
|
||||
);
|
||||
|
||||
// тут чехорда. с начало сет айтем, после сет мета, а в самом конце гет мета
|
||||
item.setItemMeta(
|
||||
setMeta(
|
||||
tag,
|
||||
item.getItemMeta()
|
||||
));
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
private int getId()
|
||||
private static int getId(NBTTagCompound tag)
|
||||
{
|
||||
int id = 0;
|
||||
if (this.tag.hasKey("id"))
|
||||
if (tag.hasKey("id"))
|
||||
{
|
||||
id = this.tag.getInt("id");
|
||||
id = tag.getInt("id");
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
private short getCount()
|
||||
private static short getCount(NBTTagCompound tag)
|
||||
{
|
||||
short count = 0;
|
||||
if (this.tag.hasKey("count"))
|
||||
if (tag.hasKey("count"))
|
||||
{
|
||||
count = this.tag.getShort("count");
|
||||
count = tag.getShort("count");
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private short getDurability()
|
||||
private static short getDurability(NBTTagCompound tag)
|
||||
{
|
||||
short durability = 0;
|
||||
if (this.tag.hasKey("durability"))
|
||||
if (tag.hasKey("durability"))
|
||||
{
|
||||
durability = this.tag.getShort("durability");
|
||||
durability = tag.getShort("durability");
|
||||
}
|
||||
return durability;
|
||||
}
|
||||
|
||||
private ItemMeta setMeta(ItemMeta meta)
|
||||
private static ItemMeta setMeta(NBTTagCompound tag, ItemMeta meta)
|
||||
{
|
||||
if (this.tag.hasKey("meta"))
|
||||
if (tag.hasKey("meta"))
|
||||
{
|
||||
NBTTagCompound metaNBT = this.tag.getCompound("meta");
|
||||
NBTTagCompound metaNBT = tag.getCompound("meta");
|
||||
|
||||
if (metaNBT.hasKey("name"))
|
||||
{
|
||||
@ -88,7 +83,7 @@ public class ItemLoad
|
||||
return meta;
|
||||
}
|
||||
|
||||
private List<String> NBTListToStringList(NBTTagList nbt)
|
||||
private static List<String> NBTListToStringList(NBTTagList nbt)
|
||||
{
|
||||
String[] list = new String[nbt.size()];
|
||||
|
||||
|
@ -12,39 +12,32 @@ import java.util.Map;
|
||||
|
||||
public class ItemNBT
|
||||
{
|
||||
ItemStack item;
|
||||
|
||||
public ItemNBT(ItemStack item)
|
||||
public static NBTTagCompound getTag(ItemStack item)
|
||||
{
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public NBTTagCompound getTag()
|
||||
{
|
||||
if (this.item == null) {return null;}
|
||||
if (item == null) {return null;}
|
||||
|
||||
NBTTagCompound tag = new NBTTagCompound("item");
|
||||
|
||||
setBasic(tag);
|
||||
setMetaTag(tag);
|
||||
setBasic(item, tag);
|
||||
setMetaTag(item, tag);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
private void setBasic(NBTTagCompound tag)
|
||||
private static void setBasic(ItemStack item, NBTTagCompound tag)
|
||||
{
|
||||
tag.setShort("count", (short)this.item.getAmount());
|
||||
tag.setInt("id", this.item.getTypeId());
|
||||
tag.setShort("durability", this.item.getDurability());
|
||||
tag.setShort("count", (short)item.getAmount());
|
||||
tag.setInt("id", item.getTypeId());
|
||||
tag.setShort("durability", item.getDurability());
|
||||
}
|
||||
|
||||
private void setMetaTag(NBTTagCompound baseTag)
|
||||
private static void setMetaTag(ItemStack item, NBTTagCompound baseTag)
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
|
||||
if (this.item.hasItemMeta())
|
||||
if (item.hasItemMeta())
|
||||
{
|
||||
ItemMeta meta = this.item.getItemMeta();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
if (meta.hasDisplayName())
|
||||
{
|
||||
@ -75,22 +68,22 @@ public class ItemNBT
|
||||
}
|
||||
}
|
||||
|
||||
private NBTTagList stringListToNBTCompound(List<String> list)
|
||||
private static NBTTagList stringListToNBTCompound(List<String> list)
|
||||
{
|
||||
NBTTagList NBTlist = new NBTTagList();
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
for (String s : list) {
|
||||
NBTlist.add(
|
||||
new NBTTagString(
|
||||
null,
|
||||
list.get(i)
|
||||
s
|
||||
)
|
||||
);
|
||||
}
|
||||
return NBTlist;
|
||||
}
|
||||
|
||||
private NBTTagCompound enchantsToNBTCompound(Map<Enchantment, Integer> enchantments)
|
||||
private static NBTTagCompound enchantsToNBTCompound(Map<Enchantment, Integer> enchantments)
|
||||
{
|
||||
NBTTagCompound NBTlist = new NBTTagCompound();
|
||||
|
||||
|
@ -11,7 +11,7 @@ import java.util.List;
|
||||
|
||||
public class Page
|
||||
{
|
||||
public int max_stack;
|
||||
public final int max_stack;
|
||||
public NBTTagList tag;
|
||||
|
||||
public Page(int max_stack)
|
||||
@ -22,7 +22,7 @@ public class Page
|
||||
public boolean add(ItemStack item) {
|
||||
if (!isOverStacked()) {
|
||||
|
||||
NBTTagCompound nbt = new ItemNBT(item).getTag();
|
||||
NBTTagCompound nbt = ItemNBT.getTag(item);
|
||||
|
||||
this.tag.add(nbt);
|
||||
|
||||
|
@ -20,7 +20,7 @@ public class PageUtil
|
||||
{
|
||||
NBTTagCompound compound = (NBTTagCompound) tag.get(i);
|
||||
|
||||
list[i] = new ItemLoad(compound).getItem();
|
||||
list[i] = ItemLoad.getItem(compound);
|
||||
}
|
||||
|
||||
return list;
|
||||
@ -54,11 +54,9 @@ public class PageUtil
|
||||
{
|
||||
NBTTagList list = new NBTTagList();
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
if (items[i] != null)
|
||||
{
|
||||
ItemNBT tag = new ItemNBT(items[i]);
|
||||
NBTTagCompound compound = tag.getTag();
|
||||
for (ItemStack item : items) {
|
||||
if (item != null) {
|
||||
NBTTagCompound compound = ItemNBT.getTag(item);
|
||||
|
||||
list.add(compound);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user