Jump to content

vemacs

Members
  • Posts

    16
  • Joined

  • Last visited

Posts posted by vemacs

  1. Combine the first I posted with the second.

    The first loads / saves the Player NBT, the second reads the inventory from it and saves the modified inventory to it.

    Here's my class:

    	public void setOfflineInventory(String username, ItemStack[] contents, ItemStack[] armor) {
    	SaveHandler saveHandler = (SaveHandler)DimensionManager.getWorld(0).getSaveHandler();
    	NBTTagCompound playerNbt = saveHandler.getPlayerData(username);
    	InventoryPlayer inventory = new InventoryPlayer(null);
    	inventory.readFromNBT(playerNbt.getTagList("Inventory"));
    	inventory.armorInventory = armor;
    	inventory.mainInventory = contents;
    	playerNbt.setTag("Inventory", inventory.writeToNBT(new NBTTagList()));
    	try {
    		File playersDirectory = new File(saveHandler.getSaveDirectory(), "players");
    
    		File temp = new File(playersDirectory, username + ".dat.tmp");
    		File playerFile = new File(playersDirectory, username + ".dat");
    		CompressedStreamTools.writeCompressed(playerNbt, new FileOutputStream(temp));
    
    		if (playerFile.exists()) {
    			playerFile.delete();
    		}
    		temp.renameTo(playerFile);
    	} catch (Exception e) {
    		logger.warning("Data failed to save for " + username);
    	}
    }

     

    I've fixed some minor typos, but I can't seem to find those methods for NBTTagCompound and SaveHandlerMP, respectively.

     

    I'm trying setTag instead of setTagList for NBTTagCompound, I'm not sure about how it would work, but it doesn't report any errors.

     

    I've also removed getConfigurationManager() from the 1st line of the class, and used DimensionManager instead.

     

    For further stability, I probably should get the last logged in world of the player, and add another parameter to the method.

     

    As this is obviously going to be part of a SMP mod, should I use SaveHandlerMP instead of SaveHandler?

  2. Hello,

    How can i make a Block sucking XP into it?  :D

    Busti

    You could try doing a spawnentity of type player, placing the spawned player where the block is, and then hiding the player.

  3. CraftInventoryPlayer? You are using Forge, not bukkit :P

    You can use something like this:

    InventoryPlayer inventory = new InventoryPlayer(null);
    inventory.readFromNBT(playerNbt.getTagList("Inventory"));
    // modify the inventory
    playerNbt.setTagList("Inventory", inventory.writeToNbt(new NBTTagList());

     

    Use with caution, it might cause NPE's since the Player instance in the Inventory is null. E.g. addItemStackToInventory will not work.

     

    Erm, right. That was cobbled together from copypasted code.

     

    Could you provide a basic example for the loading and saving of the inventory? I can't seem to find any detailed documentation of that.

    I'm not overly familiar with the way forge works, but assuming I have the InventoryPlayer loaded, would I do:

     

    public void setOfflineInventory(String username, ItemStack[] contents, ItemStack[] armor) {
        //load username's inventory as an InventoryPlayer called inventory
        inventory.armorInventory = armor;
        inventory.mainInventory = contents;
        //save username's inventory and cleanup
    }

     

    Thanks in advance!

     

  4. Suppose I have 2 ItemStack[] s, and want to write them to the inventory of an offline player.

     

    How would I do that, given the player name?

    You can use something like this:

    // modify playerNbt
    try {
        File playersDirectory = new File(saveHandler.getSaveDirectory(), "players");
    
        File temp = new File(playersDirectory, username + ".dat.tmp");
        File playerFile = new File(playersDirectory, username + ".dat");
        CompressedStreamTools.writeCompressed(playerNbt, new FileOutputStream(temp));
    
       if (playerFile.exists()) {
            playerFile.delete();
        }
        temp.renameTo(playerFile);
    } catch (Exception e) {
        logger.warning("Failed to save player data for " + username);
    }
    

    Untested, but should work ;)

    Would I have to go into an NBT editor? And if so, are there any readily available NBT libraries for Forge?

    There is already an NBT library built in Vanilla Minecraft, obviously :P

     

    Thanks, but forgive my noobishness, would I use something like this (haven't had a chance to test it yet) :

     

      public void setOfflineInventory(String username, net.minecraft.entity.player.InventoryPlayer
    inventory) {
        SaveHandler saveHandler =(SaveHandler)MinecraftServer.getServer().getConfigurationManager().worldServers[0].getSaveHandler();
        NBTTagCompound playerNbt = saveHandler.getPlayerData(username);
        //set inventory
        this.playerNBT.set("Inventory", ((CraftInventoryPlayer)inventory).getInventory().a(new NBTTagList()));
    try {
        File playersDirectory = new File(saveHandler.getSaveDirectory(), "players");
    
        File temp = new File(playersDirectory, username + ".dat.tmp");
        File playerFile = new File(playersDirectory, username + ".dat");
        CompressedStreamTools.writeCompressed(playerNbt, new FileOutputStream(temp));
    
       if (playerFile.exists()) {
            playerFile.delete();
        }
        temp.renameTo(playerFile);
    } catch (Exception e) {
        logger.warning("Failed to save player data for " + username);
    }
      }
    

     

  5. Suppose I have 2 ItemStack[] s, and want to write them to the inventory of an offline player.

     

    How would I do that, given the player name?

     

    Specifically, something like:

     

    public void setOfflineInventory(String playername, ItemStack[] contents, ItemStack[] armor) {
    //do stuff here
    }
    

    Would I have to go into an NBT editor? And if so, are there any readily available NBT libraries for Forge?

     

    Thanks in advance.

  6. Well generally decompilling other peoples mod's / classes is kinda something people tend to look down upon, at least if the intention is to do more than just look and learn :P

     

    If it's Fihgu's mod's you are trying to decompile and modify why don't you contact him?

    As far as I can see on the MC forums he is active there and you could PM him and ask for the source you need, if you explain your reasons and ask polite and nicely maybe he will help you out by giving you the part you need to look at or help you inn some other way? Generally having the permission of the mod author to decompile and play around with his source code is more accepted and thereby you would easier get help the problems you are facing while doing so :)

     

    what exactly are you trying to accomplish by decompiling the files? :)

     

    Thanks, I've PMed him, but I'm just patching some exploits related to the /lock function. I'm also patching some vulnerabilities in the login mod.

    I've PMed him my patches (which should fix the issues), and I'm going to ask him for the source.

     

    However, assuming that I did get the source, and the source is the exact same as the decompiled version, what would I be doing wrong if it isn't compiling?

  7. I've been trying to mod Fihgu's protection mod all morning (basically trying to change some strings), and so far, I have the deobfuscated source from BON and JD-Gui, and have modified a single class (EventHandler.java).

     

    However, I'm having serious issues compiling. I've added the deobfuscated and recompiled minecraft.jar from MCP, fihgu's core mod, Forge (both src+universal), all the imports in mcp /lib to the classpath, and for the life of me, still can't get it to compile (see http://www.minecraftforge.net/forum/index.php/topic,5536.0.html).

     

    Am I completely doing it wrong, and if so, how would I do it properly? I honestly don't think that reinventing the wheel is needed just to modify a single .class.

     

    Thanks in advance.

     

    (sorry for not providing more details, a generic answer would be preferred)

  8. I have a problem with my code, and it's quite frustrating.

     

    This line:

    player.mcServer.getConfigurationManager().transferPlayerToDimension(player, this.location.dimension);
    

     

    Returns:

    The method getConfigurationManager() is undefined for the type MinecraftServer, which definitely is wrong.

     

    When I hover over the mcServer part, however, I get:

    The type aa cannot be resolved. It is indirectly referenced from required .class files

     

    Am I using the wrong imports? This is the only thing preventing me from compiling.

  9. Okay, I've deobfuscated and decompiled the code using BON and JD-GUI, and made my patches.

     

    Now, when I'm trying to recompile the .java, I get a lot of symbol not found errors:

     

    EventHandler.java:217: error: cannot find symbol
            ChunkCoordinates spawn = player.worldObj.getSpawnPoint();
            ^
      symbol:   class ChunkCoordinates
      location: class EventHandler
    EventHandler.java:227: error: cannot find symbol
        return EnumSet.of(TickType.SERVER);
                          ^
      symbol:   variable TickType
      location: class EventHandler
    75 errors

     

    How would I go about resolving that?

  10. The problem you have is the JD-GUI decompile's the mod but names all the base java library's as there deobfuscated names. the only way you can get the source code to a persons mod is to ask the mod writer but it is highly unlikely that they will let you have there source code but they might be able to help you to get to what you are trying to do.

    I hope this helps.

     

    I'm pretty sure you're incorrect on that part. I'm currently trying to use Bearded Octo Nemesis to deobfuscate the mod, and need support on that, but that goes into another thread.

  11. I've decided to change around some strings to a Forge mod (namely Fihgu's protection mod), so I've opened the ZIP file (not of the coremod) using JD-GUI, changed it around a bit, and saved it as the original .class name (EventHandler.java).

     

    However, when running:

    javac -classpath protection.zip EventHandler.java

     

    It outputs:

     

    EventHandler.java:3: error: '.' expected
    import aa;
             ^
    EventHandler.java:3: error: ';' expected
    import aa;
              ^
    EventHandler.java:4: error: class, interface, or enum expected
    import cpw.mods.fml.common.IPlayerTracker;
           ^
    EventHandler.java:10: error: '.' expected
    import gm;
             ^
    EventHandler.java:10: error: ';' expected
    import gm;
              ^
    EventHandler.java:11: error: class, interface, or enum expected
    import iq;
           ^
    EventHandler.java:17: error: '.' expected
    import qx;
             ^
    EventHandler.java:17: error: ';' expected
    import qx;
              ^
    EventHandler.java:18: error: class, interface, or enum expected
    import rp;
           ^
    EventHandler.java:19: error: '.' expected
    import s;
            ^
    EventHandler.java:19: error: ';' expected
    import s;
             ^
    EventHandler.java:20: error: class, interface, or enum expected
    import ur;
           ^
    EventHandler.java:21: error: '.' expected
    import y;
            ^
    EventHandler.java:21: error: ';' expected
    import y;
             ^
    EventHandler.java:22: error: class, interface, or enum expected
    import yc;
           ^
    15 errors

     

    Which means that the ClassPath is not being resolved. How would I go about recompiling a .class file from a forge mod (not a coremod)?

     

    Thanks in advance.

  12. Hello folks,

     

    New forge modder here, I just wanted to get some support for this question:

    Is there something similar to PlayerMoveEvent for Bukkit, in which you can cancel the event?

    EntityMoveHelper looks somewhatly related, but doesn't seem to be able to be cancelled.

     

    Of course, I could go with a hackish on TickEnd solution that gets the position of the player, see if it's changed, and then for cancelling, teleport the player to the last recorded location.

     

    However, it is very hackish, so I was wondering if there is a more elegant solution?

  13. Nope. That would be akin to supporting piracy. Not happening

    Legit servers have a need for authentication plugins too (in case of insecure stuff on Mojang's part, linking multiple servers, and just having an additional authentication layer just in case.

    Besides, those plugins mainly use PlayerJoinEvent, AsyncPlayerChatEvent, PlayerLoginEvent, PlayerMoveEvent, etc..., so they provide a good subset of features that many other plugins use.

    While these plugins can be used for piracy, they're not "akin" to it.

    Additionally, supporting (not explicitly of course, but indirectly) these plugins will result in increased compatibility with other plugins that rely on these events, which would help advance the entire project goal.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.