Util [Reflection] Change player's skin! Disguise!

Discussion in 'Resources' started by xXBeLkAXx, Oct 25, 2014.

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

    xXBeLkAXx

    Hello, world!

    Sometime ago, I've been searching class, what can change player's skin. I DON'T LIKE PROTOCOLLIB, I'd like to use my own class, my code, what I can change, no APIs, no other plugins, because I like to know ALL of the functions, what I can do, while coding something. I didn't find class, what I need. But in all threads, what I found, I saw: "YOU SHOULD CHANGE GAMEPROFILE". I made it! I made class, what can change your skin! I made t with reflection, to use it on the 1.7 versions of Bukkit, this code will work on many cores, not in only one.

    ALSO, FOR ALL NICE WORK, YOU MUST REGISTER THIS CLASS AS LISTENER IN YOUR onEnable() !

    Code:

    ReflectionUtil class, what I used, from my good friend (We are Russians :3) - https://forums.bukkit.org/threads/lib-reflection-utils.246850/

    Code:java
    1. public class SkinChanger implements Listener {
    2.  
    3. private static Map<String, String> changedSkins = new HashMap<>();
    4.  
    5. public static void changeSkin(Player p, String name) {
    6. RefClass classCraftPlayer = ReflectionUtil.getRefClass("{cb}.entity.CraftPlayer");
    7. RefMethod methodGetHandle = classCraftPlayer.getMethod("getHandle");
    8. RefClass classEntityPlayer = ReflectionUtil.getRefClass("{nms}.EntityPlayer");
    9. RefField fieldPlayerConnection = classEntityPlayer.getField("playerConnection");
    10. RefClass classPlayerConnection = ReflectionUtil.getRefClass("{nms}.PlayerConnection");
    11. RefMethod methodSendPacket = classPlayerConnection.findMethodByName("sendPacket");
    12.  
    13. RefClass p29 = ReflectionUtil.getRefClass("{nms}.PacketPlayOutEntityDestroy");
    14.  
    15. RefClass p20 = ReflectionUtil.getRefClass("{nms}.PacketPlayOutNamedEntitySpawn");
    16.  
    17. RefConstructor pp20 = p20.getConstructor(ReflectionUtil.getRefClass("{nms}.EntityHuman"));
    18.  
    19. RefConstructor pp29 = p29.getConstructor(int[].class);
    20.  
    21. int[] entityId;
    22.  
    23. entityId = new int[1];
    24.  
    25. entityId[0] = p.getEntityId();
    26.  
    27. Object packetEntityDestroy = pp29.create(entityId);
    28.  
    29. Object packetNamedEntitySpawn = pp20.create((ReflectionUtil.getRefClass("{cb}.entity.CraftPlayer")).getMethod("getHandle").of(p).call());
    30.  
    31. RefField f = p20.getField("b");
    32.  
    33. RefClass gp = ReflectionUtil.getRefClass("{nm}.util.com.mojang.authlib.GameProfile");
    34.  
    35. RefConstructor rc = gp.getConstructor(UUID.class, String.class);
    36.  
    37. Object gameProfile = rc.create(p.getUniqueId(), name);
    38.  
    39. f.of(packetNamedEntitySpawn).set(gameProfile);
    40.  
    41. changedSkins.put(p.getName(), name);
    42.  
    43. p.setDisplayName(name);
    44. p.setPlayerListName(name);
    45.  
    46. for (Player player : Bukkit.getOnlinePlayers()) {
    47.  
    48. if(player != p) {
    49. Object handle = methodGetHandle.of(player).call();
    50. Object connection = fieldPlayerConnection.of(handle).get();
    51.  
    52. methodSendPacket.of(connection).call(packetEntityDestroy);
    53. methodSendPacket.of(connection).call(packetNamedEntitySpawn);
    54. }
    55. }
    56. }
    57.  
    58. public static void removeSkin(Player p) {
    59. RefClass classCraftPlayer = ReflectionUtil.getRefClass("{cb}.entity.CraftPlayer");
    60. RefMethod methodGetHandle = classCraftPlayer.getMethod("getHandle");
    61. RefClass classEntityPlayer = ReflectionUtil.getRefClass("{nms}.EntityPlayer");
    62. RefField fieldPlayerConnection = classEntityPlayer.getField("playerConnection");
    63. RefClass classPlayerConnection = ReflectionUtil.getRefClass("{nms}.PlayerConnection");
    64. RefMethod methodSendPacket = classPlayerConnection.findMethodByName("sendPacket");
    65.  
    66. RefClass p29 = ReflectionUtil.getRefClass("{nms}.PacketPlayOutEntityDestroy");
    67.  
    68. RefClass p20 = ReflectionUtil.getRefClass("{nms}.PacketPlayOutNamedEntitySpawn");
    69.  
    70. RefConstructor pp20 = p20.getConstructor(ReflectionUtil.getRefClass("{nms}.EntityHuman"));
    71.  
    72. RefConstructor pp29 = p29.getConstructor(int[].class);
    73.  
    74. int[] entityId;
    75.  
    76. entityId = new int[1];
    77.  
    78. entityId[0] = p.getEntityId();
    79.  
    80. Object packetEntityDestroy = pp29.create(entityId);
    81.  
    82. Object packetNamedEntitySpawn = pp20.create((ReflectionUtil.getRefClass("{cb}.entity.CraftPlayer")).getMethod("getHandle").of(p).call());
    83.  
    84. RefField f = p20.getField("b");
    85.  
    86. RefClass gp = ReflectionUtil.getRefClass("{nm}.util.com.mojang.authlib.GameProfile");
    87.  
    88. RefConstructor rc = gp.getConstructor(UUID.class, String.class);
    89.  
    90. Object gameProfile = rc.create(p.getUniqueId(), p.getName());
    91.  
    92. f.of(packetNamedEntitySpawn).set(gameProfile);
    93.  
    94. changedSkins.remove(p.getName());
    95.  
    96. p.setDisplayName(p.getName());
    97. p.setPlayerListName(p.getName());
    98.  
    99. for (Player player : Bukkit.getOnlinePlayers()) {
    100.  
    101. if(player != p) {
    102. Object handle = methodGetHandle.of(player).call();
    103. Object connection = fieldPlayerConnection.of(handle).get();
    104.  
    105. methodSendPacket.of(connection).call(packetEntityDestroy);
    106. methodSendPacket.of(connection).call(packetNamedEntitySpawn);
    107. }
    108. }
    109. }
    110.  
    111. @SuppressWarnings("deprecation")
    112. public static Player[] getPlayersChangedSkins() {
    113. for(int i = 0; i < changedSkins.size(); i++) {
    114. Player[] changed = new Player[changedSkins.size()];
    115.  
    116. for(Entry<String, String> entry : changedSkins.entrySet()) {
    117. changed = Bukkit.getPlayer(entry.getKey());
    118. return changed;
    119. }
    120. }
    121. return null;
    122. }
    123.  
    124. public static String getNewPlayerName(Player p) {
    125. if(changedSkins.containsKey(p.getName())) {
    126. return changedSkins.get(p.getName());
    127. }
    128. return null;
    129. }
    130.  
    131. public static String getOldPlayerName(String name) {
    132. for(Entry<String, String> entry : changedSkins.entrySet()) {
    133. if(entry.getValue().equals(name)) {
    134. return entry.getKey();
    135. }
    136. }
    137. return null;
    138. }
    139.  
    140. @EventHandler
    141. public void onRespawn(final PlayerRespawnEvent e) {
    142. changeSkin(e.getPlayer(), getNewPlayerName(e.getPlayer()));
    143. }
    144.  
    145. @EventHandler
    146. public void onLeave(PlayerQuitEvent e) {
    147. Player p = e.getPlayer();
    148. if (isDisguised(p)) {
    149. removeSkin(p);
    150. }
    151. }
    152.  
    153. public static boolean isDisguised(Player p) {
    154. return changedSkins.containsKey(p.getName());
    155. }
    156.  
    157. }


    WARNING: IT IS WORKING ON 1.7.2-1.7.5! IN HIGHER VERSIONS, MOJANG BROKE THIS FUNCTION!
     
    Last edited: Dec 28, 2014
    GrandmaJam, Plugers11 and FroznMine like this.
  2. Offline

    Plugers11

    xXBeLkAXx
    I have an error :

    Code:
    [19:26:30 INFO]: ShackelFro issued server command: /hggame changeskin skkf
    [19:26:30 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'hgga
    me' in plugin HGGame v0.1
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[cra
    ftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:17
    5) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServe
    r.java:683) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerCon
    nection.java:952) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java
    :814) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :28) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat
    .java:47) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craf
    tbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:6
    55) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2
    50) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5
    45) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
    Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: net.mine
    craft.util.com.mojang.authlib.GameProfile.<init>(java.util.UUID, java.lang.Strin
    g)
            at pl.ijava.hg.utils.ReflectionUtils$RefClass.getConstructor(ReflectionU
    tils.java:160) ~[?:?]
            at pl.ijava.hg.utils.SkinChanger.changeSkin(SkinChanger.java:57) ~[?:?]
            at pl.ijava.hg.commands.HGCommand.onCommand(HGCommand.java:87) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cra
    ftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            ... 13 more
    Caused by: java.lang.NoSuchMethodException: net.minecraft.util.com.mojang.authli
    b.GameProfile.<init>(java.util.UUID, java.lang.String)
            at java.lang.Class.getConstructor0(Unknown Source) ~[?:1.7.0_51]
            at java.lang.Class.getDeclaredConstructor(Unknown Source) ~[?:1.7.0_51]
            at pl.ijava.hg.utils.ReflectionUtils$RefClass.getConstructor(ReflectionU
    tils.java:157) ~[?:?]
            at pl.ijava.hg.utils.SkinChanger.changeSkin(SkinChanger.java:57) ~[?:?]
            at pl.ijava.hg.commands.HGCommand.onCommand(HGCommand.java:87) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cra
    ftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            ... 13 more
    >
    Code:
    else if(args[0].equalsIgnoreCase("changeSkin")){
                            String skin = args[1];
                            SkinChanger.changeSkin(p, skin);
                        }
    Code:
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Map.Entry;
    import java.util.UUID;
     
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.event.player.PlayerRespawnEvent;
     
    import pl.ijava.hg.HGClass;
    import pl.ijava.hg.gameManager.PlayerData;
    import pl.ijava.hg.utils.ReflectionUtils.RefClass;
    import pl.ijava.hg.utils.ReflectionUtils.RefField;
    import pl.ijava.hg.utils.ReflectionUtils.RefMethod;
     
    public class SkinChanger implements Listener{
     
        private static Map<String, String> changedSkins = new HashMap<>();
     
        public static void changeSkin(Player p, String name) {
            RefClass classCraftPlayer = ReflectionUtils.getRefClass("{cb}.entity.CraftPlayer");
            RefMethod methodGetHandle = classCraftPlayer.getMethod("getHandle");
            RefClass classEntityPlayer = ReflectionUtils.getRefClass("{nms}.EntityPlayer");
            RefField fieldPlayerConnection = classEntityPlayer.getField("playerConnection");
            RefClass classPlayerConnection = ReflectionUtils.getRefClass("{nms}.PlayerConnection");
            RefMethod methodSendPacket = classPlayerConnection.findMethodByName("sendPacket");
     
            RefClass p29 = ReflectionUtils.getRefClass("{nms}.PacketPlayOutEntityDestroy");
     
            RefClass p20 = ReflectionUtils.getRefClass("{nms}.PacketPlayOutNamedEntitySpawn");
     
            ReflectionUtils.RefConstructor pp20 = p20.getConstructor(ReflectionUtils.getRefClass("{nms}.EntityHuman"));
     
            ReflectionUtils.RefConstructor pp29 = p29.getConstructor(int[].class);
     
            int[] entityId;
     
            entityId = new int[1];
     
            entityId[0] = p.getEntityId();
     
            Object packetEntityDestroy = pp29.create(entityId);
     
            Object packetNamedEntitySpawn = pp20.create((ReflectionUtils.getRefClass("{cb}.entity.CraftPlayer")).getMethod("getHandle").of(p).call());
     
            RefField f = p20.getField("b");
     
            RefClass gp = ReflectionUtils.getRefClass("{nm}.util.com.mojang.authlib.GameProfile");
     
            ReflectionUtils.RefConstructor rc = gp.getConstructor(UUID.class, String.class);
     
            Object gameProfile = rc.create(p.getUniqueId(), name);
     
            f.of(packetNamedEntitySpawn).set(gameProfile);
     
            changedSkins.put(p.getName(), name);
     
            p.setDisplayName(name);
            p.setPlayerListName(name);
     
            for (Player player : Bukkit.getOnlinePlayers()) {
     
                if(player != p) {
                Object handle = methodGetHandle.of(player).call();
                Object connection = fieldPlayerConnection.of(handle).get();
     
                methodSendPacket.of(connection).call(packetEntityDestroy);
                methodSendPacket.of(connection).call(packetNamedEntitySpawn);
                }
            }
        }
     
        public static void removeSkin(Player p) {
            RefClass classCraftPlayer = ReflectionUtils.getRefClass("{cb}.entity.CraftPlayer");
            RefMethod methodGetHandle = classCraftPlayer.getMethod("getHandle");
            RefClass classEntityPlayer = ReflectionUtils.getRefClass("{nms}.EntityPlayer");
            RefField fieldPlayerConnection = classEntityPlayer.getField("playerConnection");
            RefClass classPlayerConnection = ReflectionUtils.getRefClass("{nms}.PlayerConnection");
            RefMethod methodSendPacket = classPlayerConnection.findMethodByName("sendPacket");
     
            RefClass p29 = ReflectionUtils.getRefClass("{nms}.PacketPlayOutEntityDestroy");
     
            RefClass p20 = ReflectionUtils.getRefClass("{nms}.PacketPlayOutNamedEntitySpawn");
     
            ReflectionUtils.RefConstructor pp20 = p20.getConstructor(ReflectionUtils.getRefClass("{nms}.EntityHuman"));
     
            ReflectionUtils.RefConstructor pp29 = p29.getConstructor(int[].class);
     
            int[] entityId;
     
            entityId = new int[1];
     
            entityId[0] = p.getEntityId();
     
            Object packetEntityDestroy = pp29.create(entityId);
     
            Object packetNamedEntitySpawn = pp20.create((ReflectionUtils.getRefClass("{cb}.entity.CraftPlayer")).getMethod("getHandle").of(p).call());
     
            RefField f = p20.getField("b");
     
            RefClass gp = ReflectionUtils.getRefClass("{nm}.util.com.mojang.authlib.GameProfile");
     
            ReflectionUtils.RefConstructor rc = gp.getConstructor(UUID.class, String.class);
     
            Object gameProfile = rc.create(p.getUniqueId(), p.getName());
     
            f.of(packetNamedEntitySpawn).set(gameProfile);
     
            changedSkins.remove(p.getName());
     
            p.setDisplayName(p.getName());
            p.setPlayerListName(p.getName());
     
            for (Player player : Bukkit.getOnlinePlayers()) {
     
                if(player != p) {
                Object handle = methodGetHandle.of(player).call();
                Object connection = fieldPlayerConnection.of(handle).get();
     
                methodSendPacket.of(connection).call(packetEntityDestroy);
                methodSendPacket.of(connection).call(packetNamedEntitySpawn);
                }
            }
        }
     
        public static Player[] getPlayersChangedSkins() {
            for(int i = 0; i < changedSkins.size(); i++) {
                Player[] changed = new Player[changedSkins.size()];
     
                for(Entry<String, String> entry : changedSkins.entrySet()) {
                  changed[i] = Bukkit.getPlayer(entry.getKey());
                  return changed;
                }
            }
            return null;
        }
     
        public static String getNewPlayerName(Player p) {
            if(changedSkins.containsKey(p.getName())) {
                return changedSkins.get(p.getName());
            }
            return null;
        }
     
        public static String getOldPlayerName(String name) {
            for(Entry<String, String> entry : changedSkins.entrySet()) {
                if(entry.getValue().equals(name)) {
                    return entry.getKey();
                }
            }
            return null;
        }
     
        @EventHandler
        public void onRespawn(final PlayerRespawnEvent e) {
            changeSkin(e.getPlayer(), getNewPlayerName(e.getPlayer()));
        }
     
        @EventHandler
        public void onLeave(PlayerQuitEvent e) {
            Player p = e.getPlayer();
            if (isDisguised(p)) {
                removeSkin(p);
            }
            String pN = p.getName();
            if(HGClass.getMain().getHggm().containsGame(pN)){
                HGClass.getMain().getHggm().removePlayerGame(pN);
                int games = HGClass.getMain().pd.get(pN).getGames();
                HGClass.getMain().pd.get(pN).setGames(games+1);
            }else if(HGClass.getMain().getHggm().containsLobby(pN)){
                HGClass.getMain().getHggm().removePlayerLobby(pN);
           
            }
        }
     
        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            Player p = (Player) e.getPlayer();
            if(isDisguised(p)){
            changeSkin(e.getPlayer(), getNewPlayerName(p));
            }
            String pN = p.getName();
            if(!HGClass.getMain().pd.containsKey(pN)){
                HGClass.getMain().pd.put(pN, new PlayerData(0, new ArrayList<String>()));
            }
        }
     
        public static boolean isDisguised(Player p) {
            return changedSkins.containsKey(p.getName());
        }
     
    }
    I have 1.7.2 server
     
  3. Offline

    xXBeLkAXx

    Plugers11
    This error caused by your core. I'm using Spigot #1543, and in my build class GameProfile has constructor with UUID and String. Your core is elder than mine, and your constructor in GameProfile class is String and String.

    What can u do?

    1. Update your core

    2. Change my code to this, added comments:

    Code:java
    1. package me.belka;
    2.  
    3. import java.util.HashMap;
    4. import java.util.Map;
    5. import java.util.Map.Entry;
    6. import java.util.UUID;
    7.  
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.player.PlayerJoinEvent;
    12. import org.bukkit.event.player.PlayerQuitEvent;
    13. import org.bukkit.event.player.PlayerRespawnEvent;
    14.  
    15. public class SkinChanger {
    16.  
    17. private static Map<String, String> changedSkins = new HashMap<>();
    18.  
    19. public static void changeSkin(Player p, String name) {
    20. RefClass classCraftPlayer = ReflectionUtil.getRefClass("{cb}.entity.CraftPlayer");
    21. RefMethod methodGetHandle = classCraftPlayer.getMethod("getHandle");
    22. RefClass classEntityPlayer = ReflectionUtil.getRefClass("{nms}.EntityPlayer");
    23. RefField fieldPlayerConnection = classEntityPlayer.getField("playerConnection");
    24. RefClass classPlayerConnection = ReflectionUtil.getRefClass("{nms}.PlayerConnection");
    25. RefMethod methodSendPacket = classPlayerConnection.findMethodByName("sendPacket");
    26.  
    27. RefClass p29 = ReflectionUtil.getRefClass("{nms}.PacketPlayOutEntityDestroy");
    28.  
    29. RefClass p20 = ReflectionUtil.getRefClass("{nms}.PacketPlayOutNamedEntitySpawn");
    30.  
    31. RefConstructor pp20 = p20.getConstructor(ReflectionUtil.getRefClass("{nms}.EntityHuman"));
    32.  
    33. RefConstructor pp29 = p29.getConstructor(int[].class);
    34.  
    35. int[] entityId;
    36.  
    37. entityId = new int[1];
    38.  
    39. entityId[0] = p.getEntityId();
    40.  
    41. Object packetEntityDestroy = pp29.create(entityId);
    42.  
    43. Object packetNamedEntitySpawn = pp20.create((ReflectionUtil.getRefClass("{cb}.entity.CraftPlayer")).getMethod("getHandle").of(p).call());
    44.  
    45. RefField f = p20.getField("b");
    46.  
    47. RefClass gp = ReflectionUtil.getRefClass("{nm}.util.com.mojang.authlib.GameProfile");
    48.  
    49. RefConstructor rc = gp.getConstructor(String.class, String.class); // String constructor
    50.  
    51. Object gameProfile = rc.create(String.valueOf(p.getUniqueId()), p.getName()); // String constructor
    52.  
    53. f.of(packetNamedEntitySpawn).set(gameProfile);
    54.  
    55. changedSkins.put(p.getName(), name);
    56.  
    57. p.setDisplayName(name);
    58. p.setPlayerListName(name);
    59.  
    60. for (Player player : Bukkit.getOnlinePlayers()) {
    61.  
    62. if(player != p) {
    63. Object handle = methodGetHandle.of(player).call();
    64. Object connection = fieldPlayerConnection.of(handle).get();
    65.  
    66. methodSendPacket.of(connection).call(packetEntityDestroy);
    67. methodSendPacket.of(connection).call(packetNamedEntitySpawn);
    68. }
    69. }
    70. }
    71.  
    72. public static void removeSkin(Player p) {
    73. RefClass classCraftPlayer = ReflectionUtil.getRefClass("{cb}.entity.CraftPlayer");
    74. RefMethod methodGetHandle = classCraftPlayer.getMethod("getHandle");
    75. RefClass classEntityPlayer = ReflectionUtil.getRefClass("{nms}.EntityPlayer");
    76. RefField fieldPlayerConnection = classEntityPlayer.getField("playerConnection");
    77. RefClass classPlayerConnection = ReflectionUtil.getRefClass("{nms}.PlayerConnection");
    78. RefMethod methodSendPacket = classPlayerConnection.findMethodByName("sendPacket");
    79.  
    80. RefClass p29 = ReflectionUtil.getRefClass("{nms}.PacketPlayOutEntityDestroy");
    81.  
    82. RefClass p20 = ReflectionUtil.getRefClass("{nms}.PacketPlayOutNamedEntitySpawn");
    83.  
    84. RefConstructor pp20 = p20.getConstructor(ReflectionUtil.getRefClass("{nms}.EntityHuman"));
    85.  
    86. RefConstructor pp29 = p29.getConstructor(int[].class);
    87.  
    88. int[] entityId;
    89.  
    90. entityId = new int[1];
    91.  
    92. entityId[0] = p.getEntityId();
    93.  
    94. Object packetEntityDestroy = pp29.create(entityId);
    95.  
    96. Object packetNamedEntitySpawn = pp20.create((ReflectionUtil.getRefClass("{cb}.entity.CraftPlayer")).getMethod("getHandle").of(p).call());
    97.  
    98. RefField f = p20.getField("b");
    99.  
    100. RefClass gp = ReflectionUtil.getRefClass("{nm}.util.com.mojang.authlib.GameProfile");
    101.  
    102. RefConstructor rc = gp.getConstructor(String.class, String.class); // String constructor
    103.  
    104. Object gameProfile = rc.create(String.valueOf(p.getUniqueId()), p.getName()); // String constructor
    105.  
    106. f.of(packetNamedEntitySpawn).set(gameProfile);
    107.  
    108. changedSkins.remove(p.getName());
    109.  
    110. p.setDisplayName(p.getName());
    111. p.setPlayerListName(p.getName());
    112.  
    113. for (Player player : Bukkit.getOnlinePlayers()) {
    114.  
    115. if(player != p) {
    116. Object handle = methodGetHandle.of(player).call();
    117. Object connection = fieldPlayerConnection.of(handle).get();
    118.  
    119. methodSendPacket.of(connection).call(packetEntityDestroy);
    120. methodSendPacket.of(connection).call(packetNamedEntitySpawn);
    121. }
    122. }
    123. }
    124.  
    125. @SuppressWarnings("deprecation")
    126. public static Player[] getPlayersChangedSkins() {
    127. for(int i = 0; i < changedSkins.size(); i++) {
    128. Player[] changed = new Player[changedSkins.size()];
    129.  
    130. for(Entry<String, String> entry : changedSkins.entrySet()) {
    131. changed[i] = Bukkit.getPlayer(entry.getKey());
    132. return changed;
    133. }
    134. }
    135. return null;
    136. }
    137.  
    138. public static String getNewPlayerName(Player p) {
    139. if(changedSkins.containsKey(p.getName())) {
    140. return changedSkins.get(p.getName());
    141. }
    142. return null;
    143. }
    144.  
    145. public static String getOldPlayerName(String name) {
    146. for(Entry<String, String> entry : changedSkins.entrySet()) {
    147. if(entry.getValue().equals(name)) {
    148. return entry.getKey();
    149. }
    150. }
    151. return null;
    152. }
    153.  
    154. @EventHandler
    155. public void onRespawn(final PlayerRespawnEvent e) {
    156. changeSkin(e.getPlayer(), getNewPlayerName(e.getPlayer()));
    157. }
    158.  
    159. @EventHandler
    160. public void onLeave(PlayerQuitEvent e) {
    161. Player p = e.getPlayer();
    162. if (isDisguised(p)) {
    163. removeSkin(p);
    164. }
    165. }
    166.  
    167. @EventHandler
    168. public void onJoin(PlayerJoinEvent e) {
    169. changeSkin(e.getPlayer(), getNewPlayerName(e.getPlayer()));
    170. }
    171.  
    172. public static boolean isDisguised(Player p) {
    173. return changedSkins.containsKey(p.getName());
    174. }
    175.  
    176. }[/i]
     
    GrandmaJam likes this.
  4. Offline

    Plugers11

    Where are comments ? :p

    It's not working now i moved events to oher listener class. No errors. I need change bukkit to spigot ?

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

    xXBeLkAXx

    ProgrammableCake Thank u :D

    Plugers11 I added comments at strings, what I changed :3

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  6. xXBeLkAXx Great job once again! I just have one error to you to fix [ReflectionUtil Should be ReflectionUtils]
     
  7. Offline

    Plugers11

  8. Plugers11 The code is correct I didint test it out fully yet!

    Plugers11 this might cause a problem
    Code:
    Caused by: java.lang.NoSuchMethodException: net.minecraft.util.com.mojang.authli
    b.GameProfile.<init>(java.util.UUID, java.lang.String)
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
    GrandmaJam likes this.
  9. Offline

    Plugers11

    I have the same problem but with 2 strings
     
  10. Offline

    Gater12

    GameProfile is available in 1.7.9 craftbukkit builds.
     
  11. Offline

    Plugers11

  12. Plugers11 I think the error from your log, and I will try to fix the code my self when I get the free time!
     
  13. Offline

    Plugers11

  14. Offline

    xXBeLkAXx

  15. Offline

    xXBeLkAXx

  16. Offline

    xTrollxDudex

    Stop, seriously. There's no reason to bump a resource unless you are like farming, which I hope you aren't.
     
  17. Offline

    xXBeLkAXx

    KK, won't up more :D
     
  18. Offline

    xXBeLkAXx

  19. Offline

    MiniDigger

    seriously?
     
    ChipDev and xTrollxDudex like this.
  20. Offline

    eyamaz

    Welcome to a locked thread.
     
Thread Status:
Not open for further replies.

Share This Page