Solved Custom things for certain players

Discussion in 'Spigot Plugin Development' started by ula492, Jun 26, 2016.

  1. So I want to set custom lores for an item, and only certain players with certain ranks can see that lore and the same method will happen when the player clicks on the item, ive tried seeing if the player has the perm with p.hasPerm and user.has because of pex

    but here is my code for the right click:
    Code (Java):
     if(user.has("water.reward")){
                    p.sendMessage(" §7 §m-------------------------------------------------§r ");
                    p.sendMessage("   §f§lYou have redeemed your monthly reward and received \n" +
                            "   the following:");
                    p.sendMessage("    §f§l• §a§l1 Rare Crate Keys");
                    p.sendMessage("    §f§l• §a§l2 Uncommon Crate Keys");
                    p.sendMessage("    §f§l• §a§l$1,000 In-Game Money");
                    p.sendMessage(" §7 §m-------------------------------------------------§r ");
                }else{
                    p.closeInventory();
                    p.sendMessage(" §7 §m-------------------------------------------------§r ");
                    p.sendMessage("   §f§lTo get a special crate from the me");
                    p.sendMessage("   §f§lyou must have §b§lWATER §f§lrank");
                    p.sendMessage(" §7 §m-------------------------------------------------§r ");
                }

    and here is the code for the lore:

    Code (Java):
    ArrayList<String> MonthlyLore = new ArrayList<String>();
            if(p.hasPermission("Water.reward")){
                MonthlyLore.add("");
                MonthlyLore.add("§8§lEvery Month you will Receive the following:");
                MonthlyLore.add("    §f§l• §a§l1 Rare Crate Keys");
                MonthlyLore.add("    §f§l• §a§l2 Uncommon Crate Keys");
                MonthlyLore.add("    §f§l• §a§l$1,000 In-Game Money");
                MonthlyLore.add("Rank:");
                MonthlyLore.add("    §f§l• §b§lWATER");
                MonthlyLore.add("");
            }else{
                MonthlyLore.add("");
                MonthlyLore.add("§f§lTo get a special crate from the villager");
                MonthlyLore.add("§f§lyou must have §b§lWATER §f§lrank");
                MonthlyLore.add("");
            }
    The problem is, it sends the player all msgs (Not the "else" messages) and shows all lores.
     
  2. Are you using per-player GUI's?
     
  3. No.. Im guessing I have too?
     
  4. I just create a GUI and run it with a command and when a player clicks on the NPC it runs the command and opens GUI.
     
  5. So, do you create the GUI when the player runs the command or do you just have a GUI already made and you just make a list for no reason? Show your code that makes the GUI(s)
     
  6. My entire GUI code.

    Code (Text):
        public static void rewardGUI(Player p){
            Inventory inv = Bukkit.getServer().createInventory(null, 27 , "§a§lThe Ancient Villager");

            String group = Main.chat.getPrimaryGroup(p);
            String Prefix = Main.chat.getGroupPrefix(p.getWorld(), group);

            ItemStack Voting = new ItemStack(Material.JUKEBOX);
            ItemMeta VotingMeta = Voting.getItemMeta();
            VotingMeta.setDisplayName("§aVoting");
            ArrayList<String> VotingLore = new ArrayList<String>();
            VotingLore.add("");
            VotingLore.add("§8§lWhen you vote you will Receive the following:");
            VotingLore.add("    §f§l• §a$200 In-Game Money");
            VotingLore.add("    §f§l• §aVoting Crate Key");
            VotingLore.add("");
            VotingLore.add("§8§lTime until next vote:");
            VotingLore.add("COMING SOON");
            VotingLore.add("");
            VotingMeta.setLore(VotingLore);
            Voting.setItemMeta(VotingMeta);

            ItemStack Daily = new ItemStack(Material.DOUBLE_PLANT);
            ItemMeta DailyMeta = Daily.getItemMeta();
            DailyMeta.setDisplayName("§aDaily rewards");
            ArrayList<String> DailyLore = new ArrayList<String>();
            DailyLore.add("");
            DailyLore.add("§8§lEvery day you will Receive the following:");
            DailyLore.add("    §f§l• §a§l1 Common Crate Key");
            DailyLore.add("    §f§l• §a§l$250 In-Game Money");
            DailyLore.add("");
            DailyLore.add("§8§lTime until next vote:");
            DailyLore.add("COMING SOON");
            DailyLore.add("");
            DailyMeta.setLore(DailyLore);
            Daily.setItemMeta(DailyMeta);

            ItemStack Monthly = new ItemStack(Material.CHEST);
            ItemMeta MonthlyMeta = Monthly.getItemMeta();
            MonthlyMeta.setDisplayName("§aMonthly Rewards for ranked players");
            ArrayList<String> MonthlyLore = new ArrayList<String>();
            if(p.hasPermission("Water.reward")){
                MonthlyLore.add("");
                MonthlyLore.add("§8§lEvery Month you will Receive the following:");
                MonthlyLore.add("    §f§l• §a§l1 Rare Crate Keys");
                MonthlyLore.add("    §f§l• §a§l2 Uncommon Crate Keys");
                MonthlyLore.add("    §f§l• §a§l$1,000 In-Game Money");
                MonthlyLore.add("Rank:");
                MonthlyLore.add("    §f§l• §b§lWATER");
                MonthlyLore.add("");
            }else{
                MonthlyLore.add("");
                MonthlyLore.add("§f§lTo get a special crate from the villager");
                MonthlyLore.add("§f§lyou must have §b§lWATER §f§lrank");
                MonthlyLore.add("");
            }
            if(p.hasPermission("Wind.reward")){
                MonthlyLore.add("");
                MonthlyLore.add("§8§lEvery Month you will Receive the following:");
                MonthlyLore.add("    §f§l• §a§l3 Rare Crate Keys");
                MonthlyLore.add("    §f§l• §a§l3 Uncommon Crate Keys");
                MonthlyLore.add("    §f§l• §a§l$5,000 In-Game Money");
                MonthlyLore.add("Rank:");
                MonthlyLore.add("    §f§l• §F§lWIND");
                MonthlyLore.add("");
            }else{
                MonthlyLore.add("");
                MonthlyLore.add("§f§lTo get a special crate from the villager");
                MonthlyLore.add("§f§lyou must have §b§lWATER §f§lrank");
                MonthlyLore.add("");
            }
            if(p.hasPermission("Fire.reward")){
                MonthlyLore.add("");
                MonthlyLore.add("§8§lEvery Month you will Receive the following:");
                MonthlyLore.add("    §f§l• §a§l5 Rare Crates");
                MonthlyLore.add("    §f§l• §a§l$10,000 In-Game Money");
                MonthlyLore.add("Rank:");
                MonthlyLore.add("    §f§l• §C§lFIRE");
                MonthlyLore.add("");
            }else{
                MonthlyLore.add("");
                MonthlyLore.add("§f§lTo get a special crate from the villager");
                MonthlyLore.add("§f§lyou must have §b§lWATER §f§lrank");
                MonthlyLore.add("");
            }
            MonthlyLore.add("");
            MonthlyLore.add("§8§lTime until next vote:");
            MonthlyLore.add("COMING SOON");
            MonthlyLore.add("");
            MonthlyMeta.setLore(MonthlyLore);
            Monthly.setItemMeta(MonthlyMeta);


            inv.setItem(11, Voting);
            inv.setItem(13, Daily);
            inv.setItem(15, Monthly);

            p.openInventory(inv);

        }
     
  7. Huh, other than not following naming conventions for anything, seems like it should work.

    By the way, if people can only have one of the ranks, you should make it else if's
    Code (Text):
    else if (p.hasPermission("Wind.reward")) {
    } else if (p.hasPermission("Fire.reward")) {
    } etc....
    At the moment, if you're OPed the lore for your item will be extraordinarily long.
    (If you're OPed, unless you set otherwise in your plugin.yml, you automatically have all of these perms)
     
  8. Im guessing it would go the same with sending the msgs