How do you change someone's skin to a steve and change the player's in-game name to args[0]?

Discussion in 'Plugin Development' started by FoxinatorDev, Oct 25, 2017.

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

    FoxinatorDev

    How do you change someone's skin to a steve and change the player's in-game name to args[0]? (including nametag)

    Please reply if you know. I have been struggling on this for a few months.
     
  2. Offline

    Zombie_Striker

    @FoxinatorDev
    If you're looking for a plugin to do this, you can use ChangeSkin:
    <Edit by Moderator: Redacted not allowed paid resource url>
     
    Last edited by a moderator: Feb 9, 2021
  3. Offline

    FoxinatorDev

     
    Last edited by a moderator: Feb 9, 2021
  4. Online

    timtower Administrator Administrator Moderator

    You can use it as an API.
     
  5. Offline

    FoxinatorDev

    Is that a plugin or api? If it is an API, how do I use it? I've never used an API before
     
  6. Offline

    PikaThieme

    @FoxinatorDev set the plugin in your build path (and in your server plugin folder). And use the static methods from the plugin.
     
  7. Offline

    FoxinatorDev

    It's not working :/
    Code:
    package duels.main;
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.URL;
    import java.util.HashMap;
    import java.util.UUID;
    
    import javax.net.ssl.HttpsURLConnection;
    
    import org.apache.logging.log4j.core.net.Protocol;
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import com.bringholm.nametagchanger.NameTagChanger;
    import com.bringholm.nametagchanger.skin.Skin;
    import com.mojang.authlib.GameProfile;
    import com.mojang.authlib.properties.Property;
    import com.mojang.util.UUIDTypeAdapter;
    
    import net.minecraft.server.v1_8_R3.EntityPlayer;
    
    public class Main extends JavaPlugin {
       
        HashMap<Player, String> invsee = new HashMap<Player, String>();
       
        public void onEnable() {
        }
       
        public void onDisable() {
           
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            Player p = (Player) sender;
           
            if(label.equalsIgnoreCase("invsee")) {
                Player target = Bukkit.getPlayer(args[0]);
                p.openInventory(target.getInventory());
            } else if(label.equalsIgnoreCase("nick")) {
                String nick = args[0];
               
                GameProfile gp = ((CraftPlayer)p).getProfile();
                NameTagChanger.INSTANCE.changePlayerName(p, nick);
                NameTagChanger.INSTANCE.setPlayerSkin(p, Skin.EMPTY_SKIN);
                NameTagChanger.INSTANCE.updatePlayer(p);
                p.sendMessage("New Nickname: " + nick);
            }
       
        return true;
    }
    
    public static boolean setSkin(GameProfile profile, UUID uuid) {
        try {
            HttpsURLConnection connection = (HttpsURLConnection) new URL(String.format("https://sessionserver.mojang.com/session/minecraft/profile/%s?unsigned=false", UUIDTypeAdapter.fromUUID(uuid))).openConnection();
            if (connection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
                String reply = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine();
                String skin = reply.split("\"value\":\"")[1].split("\"")[0];
                String signature = reply.split("\"signature\":\"")[1].split("\"")[0];
                profile.getProperties().put("textures", new Property("textures", skin, signature));
                return true;
            } else {
                System.out.println("Connection could not be opened (Response code " + connection.getResponseCode() + ", " + connection.getResponseMessage() + ")");
                return false;
            }
        } catch (IOException e) {
            e.printStackTrace();
            return false;
            }
        }
    }
    
    Don't mind the setSkin method. I was testing that earlier but did not work

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 27, 2017
  8. Offline

    FoxinatorDev

    I use eclipse. I can't switch IDE's cause I'm too poor to buy IntelliJ and I don't like Maven at all.

    The plugin is also not loading. I made sure I have ProtocolLib and idk if bStats is an actual plugin

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  9. Offline

    Zombie_Striker

    IntelliJ is free: Use the community version.

    What do you mean by "not loading"? Does it appear in the console? Are there any errors in the console? If so, post them.
     
  10. Offline

    FoxinatorDev

    Here is my error: https://pastebin.com/BDZTAt6Q
     
  11. Offline

    Zombie_Striker

    @FoxinatorDev
    Your plugin does not contain a plugin.yml. Make sure it is included in the jar when you export it, and that the file is at the root of the jar (not in any sub-folders).
     
  12. Offline

    FoxinatorDev

    It's not my plugin, it's the API that won't work.
     
  13. Offline

    Zombie_Striker

    @FoxinatorDev
    It should be: The contents of the api should be in your jar. NameTagChanger is just an api: not a plugin, so you can't just drop the jar into your plugins folder for it to work. You need to copy all of the contents of the api into your jar, either by using shading , or by just copying the class files into the jar manually if you are lazy/cant do it with eclipse.
     
  14. Offline

    FoxinatorDev

    I added the API to my plugins folder and my plugin. But my plugin won't work properly without the API.
     
  15. @FoxinatorDev
    Read carefully. NameTagChanger is not an API you put in your plugins folder, it is an API you shade into your plugin. What this means is that NameTagChanger will be in the same jar as your own plugin.

    The way to do this is dependent on what setup you have. Using eclipse, there is no easy way to do it, you either have to use maven, or open the jar files with a zip program and add them in.
     
  16. Offline

    FoxinatorDev

    I need help with shading the api into my plugin. I do not know where "JARs or directories" is.
     
  17. Offline

    FoxinatorDev

    Yeah... I'm an IntelliJ user now. It's kind of easier. What I'm asking is where do you find "JARs or directories" in Add Module?
     
  18. @FoxinatorDev
    You click the green plus on the right side of the menu, which will pop up a thing with 3 options, one of them being 'JARs or directories'.
     
  19. Offline

    FoxinatorDev

    upload_2017-10-28_10-36-49.png I do not see it.

    upload_2017-10-28_10-38-11.png There is also not a green plus on the right for me. Unless I'm just blind

    Nevermind. I was in the sources. Not dependencies.

    Code:
    null
    org.bukkit.command.CommandException: Unhandled exception executing command 'nick' in plugin ExtraCommands v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [spigot.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [spigot.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-21fe707-e1ebe52]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_144]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_144]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-21fe707-e1ebe52]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_144]
    Caused by: java.lang.NoClassDefFoundError: com/bringholm/nametagchanger/NameTagChanger
            at duels.commands.Nick.onCommand(Nick.java:28) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
            ... 15 more
    Caused by: java.lang.ClassNotFoundException: com.bringholm.nametagchanger.NameTagChanger
            at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_144]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:101) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:86) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_144]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_144]
            at duels.commands.Nick.onCommand(Nick.java:28) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
            ... 15 more
    Lines 28 and 29:
    NameTagChanger.INSTANCE.changePlayerName(p, nickname);
    NameTagChanger.INSTANCE.setPlayerSkin(p, Skin.EMPTY);
     
    Last edited by a moderator: Oct 28, 2017
  20. @FoxinatorDev
    Show me a screenshot of the dependencies menu. The option should be set to 'Compile'.
     
  21. Offline

    FoxinatorDev

    It is, I made sure.
    upload_2017-10-28_10-57-12.png
     
  22. @FoxinatorDev
    Can you show me the artifact you use to build the jar?
     
  23. Offline

    FoxinatorDev

  24. @FoxinatorDev
    Seems like it is including the packaged jar. This usually occurs when you add the dependency after creating the artifact. Removing and re-adding the artifact should fix the problem.
     
  25. Offline

    FoxinatorDev

    Still does not work. Is there any code I need to add for it to work? I added the setplugin in the enable method and the if statement in enable and disable.
     
  26. @FoxinatorDev
    You do not need any code. Can you show me a new screenshot of the artifact? It should say Extracted 'NameTagChanger...' instead of just the jar.
     
  27. Offline

    FoxinatorDev

Thread Status:
Not open for further replies.

Share This Page