Open ArtNRG opened 6 years ago
This can be quite hard/resource expensive as PAPI does not have an event when a placeholder changes.
Interesting! Maybe we should submit a feature request to PlaceholderAPI to add support for events? Otherwise we would have to do polling in a clever way.
Could be possible however hard as some things do not fire an event when changing (bungee total for example).
Yes it would be nice! A few months ago, I was thinking about a way to do a system like this with a listener that would be called when a placeholder change. But as supertassu say, it would be hard to do.
Has anyone made the suggestion to the creator of papi ?
I thought about it and I have an idea of how PAPI work. When PAPI catch a placeholder I think he just do a replace of the placeholder by a data returned by a function created by a developper of plugin who use the API of placeholder.
So it would be probably impossible for the creator of PAPI to do an event when a placeholder change. We must to do this ourself directly in AdvancedAchievements.
I have a simple idea to do that. We can play with two listeners, events PlayerJoinEvent and PlayerQuitEvent. When one of the event is fired, we call a function "CheckPlaceholderData(Player player)". In this function, we verify all placeholders registered by the user in the config of AdvancedAchievements. If the registered placeholder return a legit value for AdvancedAchievements, we write the returned data for the player in the database. Then to don't have problems with performances we just need to recall this function every X seconds/minutes for all connected players and update each datas with the same logic of others achievements. It would be impossible to give an achievement to a player directly like others achievements but it should work after the delay that we will define.
I'm no PlaceholderAPI expert, so I'll trust you regarding the impossibility for it to support events.
I don't think we even have to rely on the PlayerJoin and PlayerQuit events. As you suggested, we just have to call a function every X seconds/minutes which loops through all connected players. The AchieveDistanceRunnable and AchievePlayTimeRunnable classes do basically the same thing, so it could be a good starting point if you want to dig into this some more. 😉
Add PlaceholderAPI as the condition. https://pastebin.com/raw/MNRbJcYj - correct look of examples with all spaces.
PlaceholderAPI_example: %simpleclans_in_clan%: true: Message: Join any clan Name: join_clan DisplayName: Clan member Reward: Money: 5
PlaceholderAPI_example2: %mypet_level%: 30: Message: Your pet reached 30 level Name: pet_master DisplayName: Pet master Reward: Money: 5
PlaceholderAPI_example3: %leaderheads_score_elytra_weekly_1%: true: Message: You are the best weekly glider! Name: best_glider DisplayName: Best glider Reward: Money: 5