Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

PlaceholderAPI as the condition #365

Open
ArtNRG opened this issue Jun 4, 2018 · 6 comments
Open

PlaceholderAPI as the condition #365

ArtNRG opened this issue Jun 4, 2018 · 6 comments
Labels
enhancement Also known as new features.

Comments

@ArtNRG
Copy link

ArtNRG commented Jun 4, 2018

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

@ArtNRG ArtNRG changed the title New PlaceholderAPI category PlaceholderAPI as the condition Jun 4, 2018
@PyvesB PyvesB added enhancement Also known as new features. help wanted Contributions welcome! labels Jun 13, 2018
@supertassu
Copy link
Contributor

This can be quite hard/resource expensive as PAPI does not have an event when a placeholder changes.

@PyvesB
Copy link
Owner

PyvesB commented Jul 8, 2018

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.

@supertassu
Copy link
Contributor

supertassu commented Jul 8, 2018

Could be possible however hard as some things do not fire an event when changing (bungee total for example).

@Phoetrix
Copy link
Contributor

Phoetrix commented Jul 9, 2018

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 ?

@Phoetrix
Copy link
Contributor

Phoetrix commented Jul 9, 2018

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.

@PyvesB
Copy link
Owner

PyvesB commented Jul 11, 2018

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. 😉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Also known as new features.
Projects
None yet
Development

No branches or pull requests

4 participants