68 lines
1.6 KiB
Java
68 lines
1.6 KiB
Java
package tokarotik.giftapi.NBT.pages;
|
|
|
|
import net.minecraft.server.v1_6_R3.NBTTagList;
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
public class PagesManager
|
|
{
|
|
private NBTTagList tag;
|
|
private int current_page = 0;
|
|
private int count_pages = 0;
|
|
private final int items_slots;
|
|
public PagesManager(NBTTagList tag, int items_slots)
|
|
{
|
|
this.items_slots = items_slots;
|
|
this.tag = tag;
|
|
setCountPages();
|
|
}
|
|
|
|
public PagesManager(int items_slots)
|
|
{
|
|
this.items_slots = items_slots;
|
|
this.tag = new NBTTagList("giftapi");
|
|
}
|
|
|
|
public synchronized void add(ItemStack item)
|
|
{
|
|
PagesUtil.add(item, this.tag);
|
|
setCountPages();
|
|
}
|
|
|
|
public synchronized void remove(ItemStack item)
|
|
{
|
|
this.tag = PagesUtil.remove(item, this.tag);
|
|
setCountPages();
|
|
}
|
|
|
|
public synchronized NBTTagList getTag() { return this.tag; }
|
|
|
|
public synchronized ItemStack[] getList() { return PagesUtil.getRawList(this.tag); }
|
|
|
|
public synchronized int getCurrentPage() { return this.current_page; }
|
|
|
|
public synchronized int getCountPages() { return this.count_pages; }
|
|
public synchronized void nextPage()
|
|
{
|
|
if (getCountPages() > getCurrentPage())
|
|
{
|
|
this.current_page++;
|
|
}
|
|
}
|
|
|
|
public synchronized void backPage()
|
|
{
|
|
if (0 < getCurrentPage())
|
|
{
|
|
this.current_page -= 1;
|
|
}
|
|
}
|
|
|
|
private synchronized void setCountPages() {
|
|
int tag_size = this.tag.size();
|
|
if (tag_size == 0) { this.count_pages = 0; }
|
|
|
|
this.count_pages = Math.floorDiv(tag_size, this.items_slots);
|
|
}
|
|
|
|
}
|