+rep NBT. начал работу по загрузки НБТ в игру
This commit is contained in:
parent
2164ba76ab
commit
8070765b14
@ -1,9 +1,11 @@
|
|||||||
package tokarotik.giftapi;
|
package tokarotik.giftapi;
|
||||||
|
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import tokarotik.giftapi.dev.GiftCommand;
|
import tokarotik.giftapi.dev.GiftCommand;
|
||||||
|
@ -4,6 +4,7 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import tokarotik.giftapi.APIManager;
|
import tokarotik.giftapi.APIManager;
|
||||||
import tokarotik.giftapi.savemanager.NBTManager;
|
import tokarotik.giftapi.savemanager.NBTManager;
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ public class GiftCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
new NBTManager().write((Player) sender);
|
new NBTManager("world").write((Player) sender);
|
||||||
|
|
||||||
this.apiManager.openInventory((Player) sender);
|
this.apiManager.openInventory((Player) sender);
|
||||||
|
|
||||||
|
@ -14,13 +14,18 @@ public class BasicNBT {
|
|||||||
|
|
||||||
private String path;
|
private String path;
|
||||||
|
|
||||||
|
public BasicNBT(String world)
|
||||||
|
{
|
||||||
|
this.path = getPath() + "\\" + world;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean writePlayerNBT(NBTTagCompound compound, EntityPlayer entityPlayer)
|
public boolean writePlayerNBT(NBTTagCompound compound, EntityPlayer entityPlayer)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
entityPlayer.f(compound);
|
entityPlayer.f(compound);
|
||||||
|
|
||||||
FileOutputStream out = new FileOutputStream(this.path + '/' + entityPlayer.getName());
|
FileOutputStream out = new FileOutputStream(this.path + "\\players\\" + entityPlayer.getName() + ".dat");
|
||||||
NBTCompressedStreamTools.a(compound, out);
|
NBTCompressedStreamTools.a(compound, out);
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
@ -3,23 +3,48 @@ 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.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import tokarotik.giftapi.savemanager.item.ItemManager;
|
||||||
|
|
||||||
public class NBTManager
|
public class NBTManager
|
||||||
{
|
{
|
||||||
private BasicNBT basicNBT;
|
private BasicNBT basicNBT;
|
||||||
|
|
||||||
public NBTManager()
|
public NBTManager(String world)
|
||||||
{
|
{
|
||||||
this.basicNBT = new BasicNBT();
|
this.basicNBT = new BasicNBT(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean write(Player player)
|
public boolean write(Player player)
|
||||||
{
|
{
|
||||||
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(39, 1);
|
||||||
|
|
||||||
|
ItemMeta metaItem = item.getItemMeta();
|
||||||
|
|
||||||
|
metaItem.setDisplayName("Muhaha");
|
||||||
|
|
||||||
|
List<String> list = Arrays.asList("Apple", "Banana", "Cherry");
|
||||||
|
|
||||||
|
metaItem.setLore(list);
|
||||||
|
|
||||||
|
item.setItemMeta(metaItem);
|
||||||
|
|
||||||
|
ItemManager itemManager = new ItemManager(item);
|
||||||
|
itemManager.getTag();
|
||||||
|
|
||||||
|
tag.setCompound("giftapi", itemManager.tag);
|
||||||
|
|
||||||
|
System.out.println("OUTPUT" + tag);
|
||||||
|
|
||||||
return this.basicNBT.writePlayerNBT(tag, entityPlayer);
|
return this.basicNBT.writePlayerNBT(tag, entityPlayer);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,83 @@
|
|||||||
package tokarotik.giftapi.savemanager.item;
|
package tokarotik.giftapi.savemanager.item;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import net.minecraft.server.v1_6_R3.NBTTagCompound;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
public class ItemGame
|
public class ItemGame
|
||||||
{
|
{
|
||||||
public ItemGame()
|
|
||||||
|
NBTTagCompound tag;
|
||||||
|
|
||||||
|
public ItemGame(NBTTagCompound tag)
|
||||||
|
{
|
||||||
|
this.tag = tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getItem()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ItemStack item = new ItemStack(
|
||||||
|
getId(), getCount(), getDurability()
|
||||||
|
);
|
||||||
|
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getId()
|
||||||
|
{
|
||||||
|
int id = 0;
|
||||||
|
if (this.tag.hasKey("id"))
|
||||||
|
{
|
||||||
|
id = this.tag.getInt("id");
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
private short getCount()
|
||||||
|
{
|
||||||
|
short count = 0;
|
||||||
|
if (this.tag.hasKey("count"))
|
||||||
|
{
|
||||||
|
count = this.tag.getShort("count");
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
private short getDurability()
|
||||||
|
{
|
||||||
|
short durability = 0;
|
||||||
|
if (this.tag.hasKey("durability"))
|
||||||
|
{
|
||||||
|
durability = this.tag.getShort("durability");
|
||||||
|
}
|
||||||
|
return durability;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemMeta setMeta(ItemMeta meta)
|
||||||
|
{
|
||||||
|
if (this.tag.hasKey("meta"))
|
||||||
|
{
|
||||||
|
NBTTagCompound metaNBT = this.tag.getCompound("meta");
|
||||||
|
|
||||||
|
if (metaNBT.hasKey("name"))
|
||||||
|
{
|
||||||
|
meta.setDisplayName(metaNBT.getString("name"));
|
||||||
|
}
|
||||||
|
if (metaNBT.hasKey("lore"))
|
||||||
|
{
|
||||||
|
//meta.setLore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void NBTCompountToStringList(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
|
return; // it will fill
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,18 +2,20 @@ package tokarotik.giftapi.savemanager.item;
|
|||||||
|
|
||||||
import net.minecraft.server.v1_6_R3.NBTTagCompound;
|
import net.minecraft.server.v1_6_R3.NBTTagCompound;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
//import org.bukkit.inventory.ItemStack;
|
||||||
|
//import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
public class Item
|
public class ItemManager
|
||||||
{
|
{
|
||||||
private ItemStack item;
|
public ItemStack item;
|
||||||
private NBTTagCompound tag;
|
public NBTTagCompound tag;
|
||||||
|
|
||||||
public Item(ItemStack item)
|
public ItemManager(ItemStack item)
|
||||||
{
|
{
|
||||||
this.item = item;
|
this.item = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Item(NBTTagCompound tag)
|
public ItemManager(NBTTagCompound tag)
|
||||||
{
|
{
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
}
|
}
|
@ -1,6 +1,8 @@
|
|||||||
package tokarotik.giftapi.savemanager.item;
|
package tokarotik.giftapi.savemanager.item;
|
||||||
|
|
||||||
import net.minecraft.server.v1_6_R3.NBTTagCompound;
|
import net.minecraft.server.v1_6_R3.NBTTagCompound;
|
||||||
|
import net.minecraft.server.v1_6_R3.NBTTagList;
|
||||||
|
import net.minecraft.server.v1_6_R3.NBTTagString;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
@ -38,7 +40,7 @@ public class ItemNBTTag
|
|||||||
|
|
||||||
private void setMetaTag(NBTTagCompound baseTag)
|
private void setMetaTag(NBTTagCompound baseTag)
|
||||||
{
|
{
|
||||||
NBTTagCompound tag = new NBTTagCompound("meta");
|
NBTTagCompound tag = new NBTTagCompound();
|
||||||
|
|
||||||
if (this.item.hasItemMeta())
|
if (this.item.hasItemMeta())
|
||||||
{
|
{
|
||||||
@ -54,7 +56,7 @@ public class ItemNBTTag
|
|||||||
|
|
||||||
if (meta.hasLore())
|
if (meta.hasLore())
|
||||||
{
|
{
|
||||||
tag.setCompound(
|
tag.set(
|
||||||
"lore",
|
"lore",
|
||||||
stringListToNBTCompound(meta.getLore())
|
stringListToNBTCompound(meta.getLore())
|
||||||
);
|
);
|
||||||
@ -73,14 +75,16 @@ public class ItemNBTTag
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private NBTTagCompound stringListToNBTCompound(List<String> list)
|
private NBTTagList stringListToNBTCompound(List<String> list)
|
||||||
{
|
{
|
||||||
NBTTagCompound NBTlist = new NBTTagCompound();
|
NBTTagList NBTlist = new NBTTagList();
|
||||||
|
|
||||||
for (String s : list) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
NBTlist.setString(
|
NBTlist.add(
|
||||||
null, //Integer.toString(i), - for fun
|
new NBTTagString(
|
||||||
s
|
null,
|
||||||
|
list.get(i)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return NBTlist;
|
return NBTlist;
|
||||||
@ -99,9 +103,9 @@ public class ItemNBTTag
|
|||||||
{
|
{
|
||||||
levelNBT = level;
|
levelNBT = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
enchantmentNBT.setInt("id", enchantment.getId());
|
|
||||||
enchantmentNBT.setInt("level", levelNBT);
|
enchantmentNBT.setInt("level", levelNBT);
|
||||||
|
|
||||||
|
NBTlist.setCompound(String.valueOf(enchantment.getId()), enchantmentNBT);
|
||||||
});
|
});
|
||||||
return NBTlist;
|
return NBTlist;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user