i started to make pages
This commit is contained in:
parent
d3891cc364
commit
c92229230e
@ -8,7 +8,7 @@ import org.bukkit.entity.Player;
|
|||||||
import tokarotik.giftapi.APIManager;
|
import tokarotik.giftapi.APIManager;
|
||||||
import tokarotik.giftapi.savemanager.BasicNBT;
|
import tokarotik.giftapi.savemanager.BasicNBT;
|
||||||
import tokarotik.giftapi.savemanager.NBTManager;
|
import tokarotik.giftapi.savemanager.NBTManager;
|
||||||
import tokarotik.giftapi.savemanager.item.ItemGame;
|
import tokarotik.giftapi.savemanager.item.ItemLoad;
|
||||||
|
|
||||||
public class GiftCommand implements CommandExecutor {
|
public class GiftCommand implements CommandExecutor {
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ public class GiftCommand implements CommandExecutor {
|
|||||||
|
|
||||||
System.out.println(nbt.readPlayerNBT(nbt.getPlayer((Player) sender)).getCompound("giftapi"));
|
System.out.println(nbt.readPlayerNBT(nbt.getPlayer((Player) sender)).getCompound("giftapi"));
|
||||||
|
|
||||||
((Player) sender).getInventory().addItem(new ItemGame(nbt.readPlayerNBT(nbt.getPlayer((Player) sender)).getCompound("giftapi")).getItem());
|
((Player) sender).getInventory().addItem(new ItemLoad(nbt.readPlayerNBT(nbt.getPlayer((Player) sender)).getCompound("giftapi")).getItem());
|
||||||
|
|
||||||
this.apiManager.openInventory((Player) sender);
|
this.apiManager.openInventory((Player) sender);
|
||||||
|
|
||||||
|
@ -13,6 +13,8 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
|
|
||||||
public class InventoryManager implements Listener {
|
public class InventoryManager implements Listener {
|
||||||
|
|
||||||
|
public final int countSlots = 54;
|
||||||
|
|
||||||
private String nameGUI;
|
private String nameGUI;
|
||||||
private String nameArrowRight;
|
private String nameArrowRight;
|
||||||
private String nameArrowLeft;
|
private String nameArrowLeft;
|
||||||
@ -25,7 +27,7 @@ public class InventoryManager implements Listener {
|
|||||||
}
|
}
|
||||||
public void openCustomInventory(Player player)
|
public void openCustomInventory(Player player)
|
||||||
{
|
{
|
||||||
Inventory inventory = Bukkit.createInventory(null, 54, this.nameGUI);
|
Inventory inventory = Bukkit.createInventory(null, countSlots, this.nameGUI);
|
||||||
|
|
||||||
updateInventory(inventory);
|
updateInventory(inventory);
|
||||||
|
|
||||||
@ -36,12 +38,19 @@ public class InventoryManager implements Listener {
|
|||||||
if (event.getInventory().getTitle().equals(this.nameGUI)) {
|
if (event.getInventory().getTitle().equals(this.nameGUI)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
if (event.getCurrentItem() == null) return;
|
ItemStack currectItem = event.getCurrentItem();
|
||||||
/*if (event.getCurrentItem().getItemMeta().getDisplayName() == Material.DIAMOND) {
|
String nameCurrentItem = currectItem.getItemMeta().getDisplayName();
|
||||||
Player player = (Player) event.getWhoClicked();
|
Player player = (Player) event.getWhoClicked();
|
||||||
player.sendMessage(ChatColor.GREEN + "Ты кликнул по алмазу!");
|
|
||||||
player.closeInventory();
|
if (nameCurrentItem == this.nameArrowRight)
|
||||||
}*/
|
{
|
||||||
|
player.sendMessage("Right!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nameCurrentItem == this.nameArrowLeft)
|
||||||
|
{
|
||||||
|
player.sendMessage("Left!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,16 +62,16 @@ public class InventoryManager implements Listener {
|
|||||||
private void setUI(Inventory inventory)
|
private void setUI(Inventory inventory)
|
||||||
{
|
{
|
||||||
// arrow right
|
// arrow right
|
||||||
setSkull(inventory, "right", this.nameArrowRight, 0, 6);
|
setArrow(inventory, this.nameArrowRight, 0, 6);
|
||||||
// arrow left
|
// arrow left
|
||||||
setSkull(inventory, "left", this.nameArrowLeft, 8, 6);
|
setArrow(inventory, this.nameArrowLeft, 8, 6);
|
||||||
// exit
|
// exit
|
||||||
//setSkull(inventory, "exit", ChatColor.ITALIC + "" + ChatColor.DARK_RED + "Выйти", 4, 6);
|
//setSkull(inventory, "exit", ChatColor.ITALIC + "" + ChatColor.DARK_RED + "Выйти", 4, 6);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSkull(Inventory inventory, String direction, String name, int x, int y)
|
private void setArrow(Inventory inventory, String name, int x, int y)
|
||||||
{
|
{
|
||||||
ItemStack arrow = new ItemStack(Material.ARROW, 1);
|
ItemStack arrow = new ItemStack(Material.ARROW, 1);
|
||||||
ItemMeta meta_arrow = arrow.getItemMeta();
|
ItemMeta meta_arrow = arrow.getItemMeta();
|
||||||
|
@ -26,7 +26,7 @@ public class BasicNBT {
|
|||||||
{
|
{
|
||||||
entityPlayer.f(compound);
|
entityPlayer.f(compound);
|
||||||
|
|
||||||
FileOutputStream out = new FileOutputStream(this.path + "\\players\\" + entityPlayer.getName() + ".dat");
|
FileOutputStream out = new FileOutputStream(getSavePath(entityPlayer));
|
||||||
NBTCompressedStreamTools.a(compound, out);
|
NBTCompressedStreamTools.a(compound, out);
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ public class BasicNBT {
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FileInputStream in = new FileInputStream(this.path + "\\players\\" + entityPlayer.getName() + ".dat");
|
FileInputStream in = new FileInputStream(getSavePath(entityPlayer));
|
||||||
NBTTagCompound compound = NBTCompressedStreamTools.a(in);
|
NBTTagCompound compound = NBTCompressedStreamTools.a(in);
|
||||||
|
|
||||||
entityPlayer.e(compound);
|
entityPlayer.e(compound);
|
||||||
@ -66,7 +66,7 @@ public class BasicNBT {
|
|||||||
public String getPath() {
|
public String getPath() {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return new File(".").getCanonicalFile().getAbsolutePath().toString();
|
return new File(".").getCanonicalFile().getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -74,4 +74,9 @@ public class BasicNBT {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getSavePath(EntityPlayer entityPlayer)
|
||||||
|
{
|
||||||
|
return this.path + "\\players\\" + entityPlayer.getName() + ".dat";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,7 @@ package tokarotik.giftapi.savemanager;
|
|||||||
|
|
||||||
import net.minecraft.server.v1_6_R3.EntityPlayer;
|
import net.minecraft.server.v1_6_R3.EntityPlayer;
|
||||||
import net.minecraft.server.v1_6_R3.NBTTagCompound;
|
import net.minecraft.server.v1_6_R3.NBTTagCompound;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import tokarotik.giftapi.savemanager.item.ItemNBTTag;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class NBTManager
|
public class NBTManager
|
||||||
{
|
{
|
||||||
@ -26,25 +19,18 @@ public class NBTManager
|
|||||||
EntityPlayer entityPlayer = this.basicNBT.getPlayer(player);
|
EntityPlayer entityPlayer = this.basicNBT.getPlayer(player);
|
||||||
NBTTagCompound tag = this.basicNBT.readPlayerNBT(entityPlayer);
|
NBTTagCompound tag = this.basicNBT.readPlayerNBT(entityPlayer);
|
||||||
|
|
||||||
ItemStack item = new ItemStack(Material.COAL_BLOCK, 1);
|
// some action
|
||||||
|
|
||||||
ItemMeta metaItem = item.getItemMeta();
|
|
||||||
|
|
||||||
metaItem.setDisplayName("Muhaha");
|
|
||||||
|
|
||||||
List<String> list = Arrays.asList("Apple", "Banana", "Cherry");
|
|
||||||
|
|
||||||
metaItem.setLore(list);
|
|
||||||
|
|
||||||
item.setItemMeta(metaItem);
|
|
||||||
|
|
||||||
ItemNBTTag itemManager = new ItemNBTTag(item);
|
|
||||||
|
|
||||||
tag.setCompound("giftapi", itemManager.getTag());
|
|
||||||
|
|
||||||
System.out.println("OUTPUT" + tag);
|
|
||||||
|
|
||||||
return this.basicNBT.writePlayerNBT(tag, entityPlayer);
|
return this.basicNBT.writePlayerNBT(tag, entityPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean read(Player player)
|
||||||
|
{
|
||||||
|
EntityPlayer entityPlayer = this.basicNBT.getPlayer(player);
|
||||||
|
NBTTagCompound tag = this.basicNBT.readPlayerNBT(entityPlayer);
|
||||||
|
|
||||||
|
//some action
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,12 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ItemGame
|
public class ItemLoad
|
||||||
{
|
{
|
||||||
|
|
||||||
NBTTagCompound tag;
|
NBTTagCompound tag;
|
||||||
|
|
||||||
public ItemGame(NBTTagCompound tag)
|
public ItemLoad(NBTTagCompound tag)
|
||||||
{
|
{
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
}
|
}
|
||||||
@ -26,8 +26,11 @@ public class ItemGame
|
|||||||
getId(), getCount(), getDurability()
|
getId(), getCount(), getDurability()
|
||||||
);
|
);
|
||||||
|
|
||||||
item.setItemMeta(setMeta(item.getItemMeta())); // тут чехорда. с начало сет айтем, после сет мета, а в самом конце гет мета
|
// тут чехорда. с начало сет айтем, после сет мета, а в самом конце гет мета
|
||||||
|
item.setItemMeta(
|
||||||
|
setMeta(
|
||||||
|
item.getItemMeta()
|
||||||
|
));
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
@ -10,11 +10,11 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ItemNBTTag
|
public class ItemNBT
|
||||||
{
|
{
|
||||||
ItemStack item;
|
ItemStack item;
|
||||||
|
|
||||||
public ItemNBTTag(ItemStack item)
|
public ItemNBT(ItemStack item)
|
||||||
{
|
{
|
||||||
this.item = item;
|
this.item = item;
|
||||||
}
|
}
|
||||||
@ -23,7 +23,7 @@ public class ItemNBTTag
|
|||||||
{
|
{
|
||||||
if (this.item == null) {return null;}
|
if (this.item == null) {return null;}
|
||||||
|
|
||||||
NBTTagCompound tag = new NBTTagCompound("giftapi");
|
NBTTagCompound tag = new NBTTagCompound("item");
|
||||||
|
|
||||||
setBasic(tag);
|
setBasic(tag);
|
||||||
setMetaTag(tag);
|
setMetaTag(tag);
|
92
src/main/java/tokarotik/giftapi/savemanager/page/Page.java
Normal file
92
src/main/java/tokarotik/giftapi/savemanager/page/Page.java
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
package tokarotik.giftapi.savemanager.page;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_6_R3.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_6_R3.NBTTagList;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import tokarotik.giftapi.savemanager.item.ItemLoad;
|
||||||
|
import tokarotik.giftapi.savemanager.item.ItemNBT;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Page
|
||||||
|
{
|
||||||
|
public NBTTagList tag;
|
||||||
|
|
||||||
|
public void add(ItemStack item)
|
||||||
|
{
|
||||||
|
NBTTagCompound nbt = new ItemNBT(item).getTag();
|
||||||
|
|
||||||
|
this.tag.add(nbt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(ItemStack item)
|
||||||
|
{
|
||||||
|
ItemStack[] new_list = addAllExtraOne(item);
|
||||||
|
|
||||||
|
this.tag = itemStackListToNBTList(new_list);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack[] getList()
|
||||||
|
{
|
||||||
|
return reverse(getList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack[] getRawList()
|
||||||
|
{
|
||||||
|
ItemStack[] list = new ItemStack[this.tag.size()];
|
||||||
|
|
||||||
|
for (int i = 0; i < this.tag.size(); i++)
|
||||||
|
{
|
||||||
|
NBTTagCompound compound = (NBTTagCompound) this.tag.get(i);
|
||||||
|
|
||||||
|
list[i] = new ItemLoad(compound).getItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack[] reverse(ItemStack[] list)
|
||||||
|
{
|
||||||
|
List<ItemStack> array = Arrays.asList(list);
|
||||||
|
Collections.reverse(array);
|
||||||
|
|
||||||
|
return (ItemStack[]) array.toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack[] addAllExtraOne(ItemStack item)
|
||||||
|
{
|
||||||
|
ItemStack[] new_list = new ItemStack[tag.size()];
|
||||||
|
ItemStack[] old_list = getRawList();
|
||||||
|
|
||||||
|
for (int i = 0;i < tag.size();i++)
|
||||||
|
{
|
||||||
|
if (!old_list[i].equals(item))
|
||||||
|
{
|
||||||
|
new_list[i] = old_list[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private NBTTagList itemStackListToNBTList(ItemStack[] items)
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
|
||||||
|
list.add(compound);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package tokarotik.giftapi.savemanager.page;
|
||||||
|
|
||||||
|
public class PageManager
|
||||||
|
{
|
||||||
|
public PageManager()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user