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