+rep NBT. начал работу по загрузки НБТ в игру

This commit is contained in:
ScriptCat 2025-07-24 23:27:43 +03:00
parent 2164ba76ab
commit 8070765b14
7 changed files with 134 additions and 21 deletions

View File

@ -1,9 +1,11 @@
package tokarotik.giftapi;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import tokarotik.giftapi.dev.GiftCommand;

View File

@ -4,6 +4,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import tokarotik.giftapi.APIManager;
import tokarotik.giftapi.savemanager.NBTManager;
@ -24,7 +25,7 @@ public class GiftCommand implements CommandExecutor {
return true;
}
new NBTManager().write((Player) sender);
new NBTManager("world").write((Player) sender);
this.apiManager.openInventory((Player) sender);

View File

@ -14,13 +14,18 @@ public class BasicNBT {
private String path;
public BasicNBT(String world)
{
this.path = getPath() + "\\" + world;
}
public boolean writePlayerNBT(NBTTagCompound compound, EntityPlayer entityPlayer)
{
try
{
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);
out.close();
}

View File

@ -3,23 +3,48 @@ package tokarotik.giftapi.savemanager;
import net.minecraft.server.v1_6_R3.EntityPlayer;
import net.minecraft.server.v1_6_R3.NBTTagCompound;
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
{
private BasicNBT basicNBT;
public NBTManager()
public NBTManager(String world)
{
this.basicNBT = new BasicNBT();
this.basicNBT = new BasicNBT(world);
}
public boolean write(Player player)
{
EntityPlayer entityPlayer = this.basicNBT.getPlayer(player);
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);
}

View File

@ -1,9 +1,83 @@
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 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
}
}

View File

@ -2,18 +2,20 @@ package tokarotik.giftapi.savemanager.item;
import net.minecraft.server.v1_6_R3.NBTTagCompound;
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;
private NBTTagCompound tag;
public ItemStack item;
public NBTTagCompound tag;
public Item(ItemStack item)
public ItemManager(ItemStack item)
{
this.item = item;
}
public Item(NBTTagCompound tag)
public ItemManager(NBTTagCompound tag)
{
this.tag = tag;
}

View File

@ -1,6 +1,8 @@
package tokarotik.giftapi.savemanager.item;
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.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -38,7 +40,7 @@ public class ItemNBTTag
private void setMetaTag(NBTTagCompound baseTag)
{
NBTTagCompound tag = new NBTTagCompound("meta");
NBTTagCompound tag = new NBTTagCompound();
if (this.item.hasItemMeta())
{
@ -54,7 +56,7 @@ public class ItemNBTTag
if (meta.hasLore())
{
tag.setCompound(
tag.set(
"lore",
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) {
NBTlist.setString(
null, //Integer.toString(i), - for fun
s
for (int i = 0; i < list.size(); i++) {
NBTlist.add(
new NBTTagString(
null,
list.get(i)
)
);
}
return NBTlist;
@ -99,9 +103,9 @@ public class ItemNBTTag
{
levelNBT = level;
}
enchantmentNBT.setInt("id", enchantment.getId());
enchantmentNBT.setInt("level", levelNBT);
NBTlist.setCompound(String.valueOf(enchantment.getId()), enchantmentNBT);
});
return NBTlist;
}