Solved Above ActionBar Packet Help?

Discussion in 'Spigot Plugin Development' started by Nosmakos, Jun 6, 2016.

  1. hey guys i want to know is there any way to keep the packet open? not closing when showing the message for example if log in it will give a message above the action bar "Welcome %player%" but after 2 seconds it getting removed (i don't want to add this message) this is the packet i use
    Code (Text):
    PacketPlayOutChat packet = new PacketPlayOutChat(new ChatComponentText(ChatColor.translateAlternateColorCodes('&', "&fYour thirst is: " + "&4" + thirst.put(player, (thirst.get(player) -1))  + "&4%")), (byte)2);
    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
    I know i can do it with a repeating task but i already doing this with a repeating task so i can take the thirst of the player every 18 it changes the thirst but every 17 seconds i can't see it i want it to be permanently showing without disappearing. Is there any way ?
     
  2. Use a bukkit runanble
     
  3. Well if I use a bukkit runnable for it will this be loading again? Because I have an updater already for it for 18 seconds to reload so it will do -1 thirst every 18 seconds
     
  4. I think even Google translate produces better englisch than that o_O
    I cant get your problem. If you want to show it permanently then use a repeating task and send the packet again.
     
  5. Hahaha sorry about that i don't see mostly what i write so .. :p
    Yes but the thing is i use a repeating scheduler so i can make it every 18 seconds to remove -1 from the thirst of the player see an example.
    this is the first line
    Code (Text):
    public void setupthirstPacket(final Player player){
            if (thirst.get(player) == 100){
                PacketPlayOutChat packet = new PacketPlayOutChat(new ChatComponentText(ChatColor.translateAlternateColorCodes('&', "&fYour thirst is: " + "&2" + thirst.put(player, (thirst.get(player) -1)) + "&2%")), (byte)2);
    then i do in a repeating scheduler to update it every 18 seconds but if i use and another runnable for it this will just make the packet to reduce the thirst faster right?
     
  6. 1: ChatColor.translateAlternateColorCodes('&', "&fYour thirst is: " + "&2" + thirst.put(player, (thirst.get(player) -1)) + "&2%")
    This is total nonsense xD you dont have to translate the color Code if you just use §
    2: Then just remove this from the second sched
    thirst.put(player, (thirst.get(player) -1))
    And use
    thirst.get(player)
    Instead.
    3: please tell me that player is a string and not a player object.
     
  7. lot of people telling me to not use "§" so i just turn it like this.
    Also i can't do thirst.get(player) because this will just take the thirst but it won't do -1 that's why i did thirst.put(player, (thirst.get(player) -1)) here
    because if i run a repeating task this will make every 20 sec(example) to reduce -1 from 100 until the number goes to 0 and It's Player, Integer my hashmap because i need to save their thirst data in a ym file.
     
    #7 Nosmakos, Jun 6, 2016
    Last edited: Jun 6, 2016
  8. Well... They are right but then you should not use & neither. You should use ChatColor.YOURCOLOR instead.
    Dont change that in the 20sec repeating task. Change it in the 2 seconds repeating task.
     
  9. ChatColor can be annoying in ways but if i translate it i don't think this can be a wrong thing (i hope)
    if i change it to 2 seconds the thirst will run like 100, after 2 seconds 99 same goes same goes but with this way the players will be thirsty really fast and in every 18 seconds if this reduces 1 in 30 minutes the player will be thirsty but maybe i could make the reduce system inside of the task and then in the packet make another repeating task for showing permanently ?
     
  10. Holy crap im saying all the time to use a second scheduler. Are you trolling me? XD
     
  11. hahaha well i didn't know how to do the method hold on one sec to test it
    ( i hope this won't be laggy )
     
  12. okay so it's working this is what i did in onEnable()
    Code (Text):
            BukkitScheduler Scheduler = Bukkit.getServer().getScheduler();
            Scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
                @Override
                public void run() {
                    for (Player p : Bukkit.getServer().getOnlinePlayers()) {
                        setupthirstPacket(p);
                        thirst.put(p, (thirst.get(p) -1));
                    }
                }
            }, 0, 360L);
         
            BukkitScheduler Schedulerr = Bukkit.getServer().getScheduler();
            Schedulerr.scheduleSyncRepeatingTask(this, new Runnable() {
                @Override
                public void run() {
                    for (Player p : Bukkit.getServer().getOnlinePlayers()) {
                        setupthirstPacket(p);
                    }
                }
            }, 0, 20L);
        }
    and changed from the packets the thirst.put(player, (thirst.get(player) -1)) to thirst.get(player)
    because i added thirst.put(player, (thirst.get(player) -1)) in the task now
     
  13. First: you should always avoid storing a player object in a List, Hashmap,... Because of memory leaks. https://bukkit.org/threads/common-mistakes.100544/
    For more details Google.
    2: your first sched could be a asynchron one if you remove
    setupthirstPacket(p);
    And if you dont use the Player object and if you use the synchronized modifier while acessing the Hashmap.
     
  14. well i use hashmap of course !
    HashMap<Player, Integer > thirst = new HashMap<Player, Integer>();
     
  15. And as i already said: dont save a player object in a List ect.!!! Use the Player name or the uuid instead.
     
  16. everyone told me to use Player than UUID
     
  17. QUOTE from a retired bukkit STAFF
    Whom do you trust more? Some randoms which barely understand Java or the bukkit staff?
     
  18. well basically all of them told me to use Player than UUID xd
     
  19. MiniDigger

    Supporter

    can you link something? it is really bad if ppl give such bad advice
     
  20. Well do so if you want... I dont really care. If you doesnt want to learn new stuff and how to improve your plugin... Fine then trust this pseud devs