74 lines
2.2 KiB
Java
74 lines
2.2 KiB
Java
package wtf.beatrice.nounspicker.objects;
|
|
|
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
|
import org.bukkit.entity.Player;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import wtf.beatrice.nounspicker.NounsPicker;
|
|
import wtf.beatrice.nounspicker.utils.Cache;
|
|
|
|
public class PAPIManager extends PlaceholderExpansion
|
|
{
|
|
|
|
private final NounsPicker plugin;
|
|
public PAPIManager(NounsPicker plugin)
|
|
{
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
@Override
|
|
public boolean persist(){
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean canRegister(){
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public @NotNull String getIdentifier() {
|
|
return "nouns";
|
|
}
|
|
|
|
@Override
|
|
public @NotNull String getAuthor() {
|
|
return plugin.getDescription().getAuthors().toString();
|
|
}
|
|
|
|
@Override
|
|
public @NotNull String getVersion() {
|
|
return plugin.getDescription().getVersion();
|
|
}
|
|
|
|
|
|
@Override
|
|
public String onPlaceholderRequest(Player player, @NotNull String identifier) {
|
|
|
|
if (player == null) {
|
|
return "";
|
|
}
|
|
|
|
int pronounId;
|
|
|
|
// todo: this sends query every time we get a papi call, which is horrible for performance.
|
|
// todo: we should cache player pronouns too.
|
|
|
|
switch (identifier.toLowerCase()) {
|
|
case "main_pronoun":
|
|
pronounId = Cache.dbManager.getPlayerPronounId(player.getName(), 0);
|
|
return Cache.dbManager.getPronounFormat(pronounId);
|
|
case "secondary_pronoun":
|
|
pronounId = Cache.dbManager.getPlayerPronounId(player.getName(), 1);
|
|
return Cache.dbManager.getPronounFormat(pronounId);
|
|
case "full_tag":
|
|
pronounId = Cache.dbManager.getPlayerPronounId(player.getName(), 0);
|
|
String mainPronounFormat = Cache.dbManager.getPronounFormat(pronounId);
|
|
pronounId = Cache.dbManager.getPlayerPronounId(player.getName(), 1);
|
|
String secondaryPronounFormat = Cache.dbManager.getPronounFormat(pronounId);
|
|
return "[" + mainPronounFormat + "/" + secondaryPronounFormat + "]";
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|