Lib's Disguises

Discussion in 'Plugin Development' started by CheesyFreezy, Feb 19, 2015.

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

    CheesyFreezy

    Heey developers. I'm trying to make a disguise plugin where players with a certain permission can disguise as a player with a random name. Something in the api is not working.

    • I installed ProtocolLib in my plugins folder
    • I installed LibsDisguises in my plugins folder
    • I'm using spigot #1649
    • I added LibsDisguises in my build path

    Code:
    Code:
            if(command.equalsIgnoreCase("disguise")) {
                if(sender instanceof Player) {
                    Player player = (Player) sender;
                   
                    if(player.hasPermission("core.disguise") || player.isOp()) {
                        Random r = new Random();
                        int newName = r.nextInt(Integer.MAX_VALUE / 100);
                       
                        player.sendMessage(prefix + ChatColor.GRAY + "You've been disguised as " + ChatColor.AQUA + newName + ChatColor.GRAY + "!");
                       
                        String defaultName = player.getName();
                       
                        File file = new File(getDataFolder(), "nicknames.yml");
                        YamlConfiguration fileConfig = YamlConfiguration.loadConfiguration(file);
                        String newNameString = Integer.toString(newName);
                        fileConfig.set(newNameString, defaultName);
                       
                        PlayerDisguise disguise = new PlayerDisguise(newNameString);
                        DisguiseAPI.disguiseToAll(player, disguise);
                    } else {
                        player.sendMessage(prefix + ChatColor.GRAY + "You do not have access to that command!");
                    }
                }
            }
    Please help, i need to finish this today

    Whenever i add
    Code:
    PlayerDisguise disguise = new PlayerDisguise(newNameString);
                DisguiseAPI.disguiseToAll(player, disguise);
    to my code, the plugin won't load anymore

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

    Avygeil

  3. Offline

    CheesyFreezy

    @Avygeil, sorry that i didn't close this thread yet, but i'm trying to figure it out with using packets. But again, it's not working :p


    Maybe you can help me with this than?
    I'm trying to rename the players displayname, the name above its head, in the TAB list and i want to change the skin. The only things that are happening are the displayname and the TAB list, i don't know how to change the other 2.

    Current Code:
    Code:
            if(command.equalsIgnoreCase("disguise")) {
                if(sender instanceof Player) {
                    Player player = (Player) sender;
                   
                    if(player.hasPermission("core.disguise") || player.isOp()) {
                        Random r = new Random();
                        int newName = r.nextInt(Integer.MAX_VALUE / 100);
                       
                        player.sendMessage(prefix + ChatColor.GRAY + "You've been disguised as " + ChatColor.AQUA + newName + ChatColor.GRAY + "!");
                       
                        String defaultName = player.getName();
                       
                        File file = new File(getDataFolder(), "nicknames.yml");
                        YamlConfiguration fileConfig = YamlConfiguration.loadConfiguration(file);
                        String newNameString = Integer.toString(newName);
                        fileConfig.set(newNameString, defaultName);
                        try {
                            fileConfig.save(file);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                       
                        EntityPlayer craftPlayer = ((CraftPlayer)player).getHandle();
                        craftPlayer.displayName = newNameString;
                        craftPlayer.listName = newNameString;
                       
                        for(Player players : Bukkit.getOnlinePlayers()) {
                            if(players != player) {
                                EntityPlayer craftPlayers = ((CraftPlayer)players).getHandle();
                               
                                craftPlayers.playerConnection.sendPacket(new PacketPlayOutSpawnEntity());
                            }
                        }
                    } else {
                        player.sendMessage(prefix + ChatColor.GRAY + "You do not have access to that command!");
                    }
                }
            }
     
Thread Status:
Not open for further replies.

Share This Page