Changing Names

Discussion in 'Plugin Development' started by geekygenius, Mar 15, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Cirno

    NVM, I was being stupid. Didn't read the post all the way; I thought that was vanilla mc.
    Anways, still awesome.

    EDIT: Oh and how did you recompile this?
     
  2. Offline

    AmberK

    Actually to be perfectly honest, I let someone else worry about the compiling. :\

    I just did the searching and modifying, so the only step left to the puzzle would be recompiling craftbukkit
     
  3. Offline

    Kekec852

  4. Offline

    Cirno

    I can't use Maven because I don't have JDK installed. Can JDK just be downloaded off the net without the installer?
    Anways, I shoved it all into eclipse and this happens.
    Errors (100 of 7932 items)
    never in my life have i ever seen so many errors.

    EDIT: Weird, Eclipse just compiled it like "ohai errors. screw chu, i'm compinlin'" and it just compiled. I'm in the process of patching the new files from the screwed up build into a newly downloaded .jar and see if that works.

    EDIT2: Patch failed;
    Code:
    java.lang.NoClassDefFoundError: net/minecraft/server/EntityHuman (wrong name: ma
    in/java/net/minecraft/server/EntityHuman)
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClass(Unknown Source)
            at java.security.SecureClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.access$000(Unknown Source)
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClassInternal(Unknown Source)
            at net.minecraft.server.Item.<clinit>(SourceFile:75)
            at net.minecraft.server.Block.<clinit>(Block.java:601)
            at net.minecraft.server.StatisticList.a(SourceFile:122)
            at net.minecraft.server.StatisticList.<clinit>(SourceFile:56)
            at net.minecraft.server.MinecraftServer.main(MinecraftServer.java:605)
            at org.bukkit.craftbukkit.Main.main(Main.java:134)
    EDIT3: I got it working! I just did this:
    1: Copy the ENTIRE SOURCE CODE for EntityHuman.
    2: Create a new project folder named Bukkit Recompile
    3: Created a package named "net.minecraft.server".
    4: Created a class named EntityHuman
    5: Copied the source code from the previous and made modifications.
    6: Compiled using Eclipse
    7: Opened newly made .jar with WinRAR along with CraftBukkit
    8: Went into the proper folder and dragged EntityHuman.class into the CraftBukkit folder
    9: Celebrate with cake.

    What do you mean an edited CraftBukkit?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  5. Offline

    Kekec852

    You just did.
     
  6. Offline

    Cirno

    Oh and what I did, does not work at all. It seems that something is perventing it. How I know?
    I did a test with Blocks.java, and replaced the line that defines Grass to this:
    public static final BlockGrass GRASS = (BlockGrass) (new BlockGrass(2)).c(0.6F).a(g).a("sourcery");
    It doesn't work at all.

    EDIT: I managed to do something unbelivable. I switched the ID's between Grass and Dispencer, and now, it works. Grass is now a dispencer ._.

    EDIT2: Never ever ever switch Grass with TNT. It ends badly. Wanna glimpse what happended?
    [​IMG]
    Yeah.
     
  7. Offline

    AmberK

    Modding the server files is pretty fun :cool:

    When you say it didn't work, was there any console errors? I think the person who did it compiled the thing in full, so I can see about figuring this out tomorrow afternoon.

    Just an fyi, in theory I think it's possible to give yourself capes in this way, without spout, just by modding the server file.

    Also don't copy/paste mine, type it in manually. They don't support tabs (use 4 spaces), and I believe there was a couple in my example.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  8. Offline

    Cirno

    If I was able to get a skeleton and a slime to be mounted on a pig, anything is possible.
     
  9. Offline

    AmberK

    A swime?

    Hit me up if you compile a version of it, it'd be interesting to look at (I learn what I can, even if I wrote it xD)
     
  10. Offline

    Cirno

    Eh... It's against the ToS to distribute the classes. I can just tell you the code though. Only sectional though.
    I meant it as a Slime can ride a pig, and a Skeleton can ride a pig, not a Skeleton and a Slime can ride a pig at the same time :p

    Code:
    EntitySkeleton z = new EntitySkeleton(this.world);
                z.setPositionRotation(this.locX, this.locY, this.locZ, this.yaw, this.pitch);
                this.world.addEntity(z, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.LIGHTNING);
    
    PigEntity.class, in function b().

    Mods, if I break the ToS because of this, kindly remove this post.
     
  11. Offline

    Sorroko

    I am pretty sure that tabs work, and craftbukkit is using notchs code and thats not against ToS, also craftbukkit is open source...
     
  12. Offline

    Cirno

    I also forgot;
    No console errors, nothing at all.
    It still said my username over my head, not what I set it to. My IGN is Evangon :p And my code basiclly was
    public String getLocalizedName() {
    if (this.name.equals("LulzAdmin"))
    return (ChatColor.GREEN + "LulzAdmin" + ChatColor.WHITE);
    else return this.name;
    }
     
  13. Offline

    Sorroko

    Cirno your problem is its checking for a player called LulzAdmin and changing name to LulzAdmin.. so that doesnt work :D. This will change anyones name to have a green name:
    Code:
    public String getLocalizedName() {
      return (ChatColor.GREEN + this.name + ChatColor.WHITE);
    }
     
  14. Offline

    AmberK

    Yeah, the reason the code was like that was so I could be special ^_^
    You can also add in names you want for it, so that you can only have certain people, and even just add more statements for different colors, i.e.

    Code:java
    1. public String getLocalizedName() {
    2. if (this.name.equals("LulzAdmin"))
    3. return (ChatColor.GREEN + "LulzAdmin" + ChatColor.WHITE);
    4. else if (this.name.equals("Evangon"))
    5. return (ChatColor.GOLD + "Evangon" + ChatColor.WHITE);
    6. else return this.name;
    7. }


    ...I think? It's funny how far I got on how little java knowledge I have :p
     
  15. Offline

    ZeusAllMighty11

    About modding the classes, is this for Bukkit or Craftbukkit?

    And if I do this, will my users have to download via 3rd party sites like Mediafire? I don't want them to do anything but login and maybe have my server send the new packets to them.
     
  16. Offline

    AmberK

    No, you are modifying your own server files in a way that vanilla players may connect to it. Also, it is craftbukkit.
     
  17. Offline

    Cirno

    Silly me, I meant that I changed equals("LulzAdmin") to equals("Evangon") and the secound one to Cirno.
     
  18. Offline

    AmberK

    I'm having trouble running maven, if I send you the .java can you compile it?
     
  19. Offline

    Cirno

    Don't use Maven, if you're using Eclipse, I did this.

    I downloaded the entire source for Bukkit and imported it into Eclipse. What the heck, 1000+ errors. So what do I do? I basiclly create a new package named "net.server.minecraft" and copied over the files and w00t, it works.
     
  20. Offline

    Sorroko

    I'd like to clear up that bukkit is an empty shell for just referencing the api and cannot run on its own, craftbukkit is built on minecraft vanilla server and the bukkit api, it actually provides the functionality and the way that the api is implemented is in craftbukkit.
    Craftbukkit must be changed with each minecraft update and therefore you will need to make a new build each time, so try to not use craftbukkit in plugins or modify alot of craftbukkit.
    And modifying craftbukkit means you have to distribute your own copy, which is legal but many people wont trust you. Modifying craftbukkit is only good for private or personal use.
     
  21. Offline

    xGhOsTkiLLeRx

    I use the method from page 1.
    Does anybody know how I can keep my skin?
    Because it's changed to the standard one...
     
  22. Offline

    geekygenius

    That's all that's left to figure out. I made a post a few months ago, but no replies. Hopefully, it will be a part of the Mod API. https://bukkit.atlassian.net/browse/BUKKIT-1219
     
  23. Offline

    xGhOsTkiLLeRx

    I voted for this issue, since it's an awesome feature! :)
     
    ZeusAllMighty11 and geekygenius like this.
  24. Offline

    Sorroko

    @xGh0sTkiLLeRx The problem is that you can easily send a fake name to the client but the client will think its the real name and look for the appropriate skin. Unfortunaltely as the skin is client side it means that any name change no matter wether its added to bukkit or not will be able to keep the players skin. There fore you may use spout (personally don't like it) or you may wait for the official server api and see if its possible by then.
     
  25. Offline

    xGhOsTkiLLeRx

    ryan7745
    I already thought the client looks for my new name which is not defined with a custom skin - fall back to default one.
    I can't wait to see the power of the modding API!
     
  26. Offline

    Aza24

    Yeah as EvilSeph said on leaky:

    EvilSeph added a comment - 21/Mar/12 3:31 PM
    Until a better solution comes up to provide this, this will not be added due to breaking skins.
     
  27. Offline

    geekygenius

    Hopefully, the better solution will be mod API support ;)
     
  28. Offline

    winter4w

    So can someone make a plugin that can change the floating name
     
  29. Offline

    caldabeast

    If you actually read the entirety of this post like I just did, you would discover the answer is no.

    EDIT: Unless you are confident enough to modify your own CraftBukkit.jar hehe

    Father Of Time
    I read through your post about how you solved the issue of using the custom characters in chat and about your workaround (modifying a list of allowed characters). Do you think it would be at all possible to take this, use some sort of override similar to what you did there (if my memory serves me correctly), and turn it into a configurable plugin?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  30. It's possible, yes, but it creates some incompatibilities (*cough*Spout*cough*) and involves some really hackish reflection stuff.
    The simple part is making an own class (class NameChangingEntityPlayer extends EntityPlayer) and making it override getLocalizedName(). The difficult part is to introduce the class to the server, so it actually usees it instead of the standard one.
    --------

    Okay, having browsed the server code a bit more, that part should actually not be that difficult. You don't even need to replace any more native classes, but it probably causes tons of more issues.

    ServerConfigurationManager has a list of EntityPlayers. One could just go ahead and remove the old EntityPlayer instance and replace it with the own one (that cloned all the bazillions of attributes of the old instance to be actually the same).
    Speaking of it, that's just complete bullshit, though. The EntityPlayer instance is used everywhere in the server, stored in all kinds of different places. Have fun replacing that everywhere (Last time I checked, Spout only replaced CraftPlayer, not EntityPlayer, by the way).

    So we need to get a different approach: Catching the instance at its origin.

    That one also lies in the ServerConfigurationManager class. It's the only one that calls the constructor of EntityPlayer. The method is attemptLogin (don't ask me what all that crap in there has to with "configurations" ...).

    We could make a class extending it, overriding the method. But it directly creates the entity along with the other crap it does. Due to the way Java works, we can't make use of "super", here, so we have to copy the whole method, changing it to create our own entity instead of the normal one.
    But well, doing it that way will probably break with every other new craftbukkit build anyway, so why bother with that :p

    Okay, next step: Replacing the standard ServerConfigurationManager. It's stored in the class called MinecraftServer - public attribute, not final, we don't even need Reflection to hack that, great!
    Umm, yeah, then lets clone the numerous obfuscated attributes of the original instance to our own one, replace the variable .... and BAM! It should work, at least in my head ...


    So that was just a log of my thoughts, live, while I was working out a way to do it as a plugin.
    If anyone could follow that, congrats!
    Anyway, it would still be easier if bukkit just added one simple API method for that, should be about 95% less effort, and it wouldn't break constantly :p


    PS: All this was written under the assumption that changing the return value of getLocalizedName() actually sends that to the client. I hope I didn't misunderstand that, didn't do any research on that.
     
    kumpelblase2 likes this.
Thread Status:
Not open for further replies.

Share This Page