1.14.4 Offline Players Inventory

Discussion in 'Spigot Plugin Development' started by JoeyPlayzTV, Feb 19, 2020.

  1. Hey, Iam making my own Essentials and i want to add a /oinv /oec command. I need help in getting and saving an offline players inventory. The inventory is stored inside the worldsfolder in a <uuid>.dat file. Has someone a good working idea how to do this. If yes and you have code, please dont paste only the code. I will learn how it works. I dont know, if the 1.14 API has some ways to do this....

    Thanks for help.
  2. this is half assed 1.9 code using my own api system but the idea is there
    Code (Java):
    this.ownerData = new File("world" + File.separator + "playerdata", owner.toString() + ".dat");
    tag.getList(list, "Inventory", 10);
    for(int i = 0; i < list.size(); i++) {
    int slot = tag.getByte("Slot") & 0xFF;
    if(slot >= 0 && slot <= 8) slot += 36;
    else if(slot >= 100 && slot <= 103) slot = 103 - slot;
    else if(slot == 150) slot = 4;
    inv.setItem(slot, itemStack.getBukkitItemStack());
    using compound tags, you can load the player's .dat data. theres a taglist of the inventory which you can get the items from.
    afaik there isnt a spigot api for this
  3. Thanks i have a question
    Is this normal Spigot code or is an API needet? And how i can save a inventory to the player?
  4. thats not normal spigot code, but the code there gives you enough idea to figure out what you need to do
    'tag' refers to my own wrapper system of nbttagcompounds, you can simply use the nms versions.
    the slot changing is because of how i designed my own offline inventories
    to save an offline player's inventory, last i checked you used NBTCompressedTools#save or something like that
    Code (Java):
    tag = NBTCompressedStreamTools.a(new FileInputStream((File)obj));
    like that. that gets you a nms nbttagcompound.
    Code (Java):
    NBTCompressedStreamTools.a(tag, new FileOutputStream(playerFile));
    this is how to save the nbttagcompound.
    use my above code to see how to mess with the nbttagcompound
    • Like Like x 1

  5. is "tag" an NBTTagCompound object?
    • Agree Agree x 1
    • Useful Useful x 1
  7. I cant use any of them. Because i need the loadPlayerData method and this is not part of NBTTagCompount
  8. i told you how to load the data.. my custom loadPlayerData method calls the method that i gave you
    /e basically youre trying to copy and paste but you cant because these arent public methods. figure out what my methods do and translate them to the actual NMS methods. i gave you the methods that arent super obvious. now figure out the obvious ones.

    /e2 here https://github.com/Warren1001/kabut...pound/impl/WrappedNBTTagCompoundv1_14_R1.java go thru my source and reverse engineer what i did
    #8 Warren1001, Feb 19, 2020
    Last edited: Feb 19, 2020
  9. I dont Copy Paste! Copy Paste are useless for me because iam coding for over 8 years but i have no knowlege in NBT! I use PowerNBT i only try to learn how it works!
  10. #getList returns NBTTagList. change the object type to that. the method should tell you this. if you were 8 years experienced (i am 5 years), youd know this
  11. I have never Worked with NBT because NBT is Crap and this Method
    Code (Text):
    tag = NBTCompressedStreamTools.a(new FileInputStream((File)obj));
    is not functioan it throws https://hasteb.in/ogerajog.md

    How am I supposed to load this stupid file if you give me a method that won't work! Have I programmed Minecraft? NO! So how should I know how to load this file! All methods are encrypted and are called a, b, c how should I find my way? How am I supposed to do something myself?
  12. show your code. the input stream ends unexpectedly, which shouldn't be happening. i havent tested that method but i know that thats what that does.
  13. what does sys.out bukkit.getworldcontainer print? are you sure you have the correct path to the file? maybe convert it to a file instead of inputting a string and checking if it exists.
  14. The output is wrong .world/playerdata/f54fe29c-c234-4191-bce5-a3291f9f9629.dat
  15. what output is wrong? new FileInputStream(new File("world" + File.separator + "playerdata" + File.separator + uuid.toString() + ".dat")); should get you what you want.
  16. I have try it so

    Code (Java):
    String path = Bukkit.getWorldContainer().getAbsolutePath() + "/world/playerdata/f54fe29c-c234-4191-bce5-a3291f9f9629.dat";
                File file = new File(path);
                DataInputStream stream = new DataInputStream(new FileInputStream(file));
                NBTTagCompound comb = NBTCompressedStreamTools.a(stream);
    But the same exception it is impossible
  17. print the entire String path. what is it? AND print file#exists. does it exist?

    /e dont go straight to datainputstream.
    this is what the source shows: final DataInputStream datainputstream = new DataInputStream(new BufferedInputStream(new GZIPInputStream(inputstream)));
    either do that, or just input FileInputStream and use the method:
    public static NBTTagCompound a(final InputStream inputstream)

    these are taken froma decompiled 1.14.4 server jar

    heres your issue: you're currently calling this:
    Code (Java):
        public static NBTTagCompound a(final DataInputStream datainputstream) throws IOException {
            return a(datainputstream, NBTReadLimiter.a);
    which this ends up to:
    Code (Java):
        private static NBTBase a(final DataInput datainput, final int i, final NBTReadLimiter nbtreadlimiter) throws IOException {
            final byte b0 = datainput.readByte();
            if (b0 == 0) {
                return new NBTTagEnd();
            final NBTBase nbtbase = NBTBase.createTag(b0);
            try {
                nbtbase.load(datainput, i, nbtreadlimiter);
                return nbtbase;
            catch (IOException ioexception) {
                final CrashReport crashreport = CrashReport.a(ioexception, "Loading NBT data");
                final CrashReportSystemDetails crashreportsystemdetails = crashreport.a("NBT Tag");
                crashreportsystemdetails.a("Tag type", b0);
                throw new ReportedException(crashreport);
    this is the wrong method. you want the one i put.