81 lines
2.4 KiB
Java
81 lines
2.4 KiB
Java
package wtf.beatrice.nounspicker.objects;
|
|
|
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
|
import org.bukkit.ChatColor;
|
|
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;
|
|
|
|
// base format is [She/Her]
|
|
final String baseFormat = ChatColor.DARK_GRAY + "[" + ChatColor.RESET + "%main%" +
|
|
ChatColor.DARK_GRAY + "/" + ChatColor.RESET + "%secondary%" +
|
|
ChatColor.DARK_GRAY + "]" + ChatColor.RESET;
|
|
|
|
|
|
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);
|
|
if(pronounId < 0) return "";
|
|
String mainPronounFormat = Cache.dbManager.getPronounFormat(pronounId);
|
|
pronounId = Cache.dbManager.getPlayerPronounId(player.getName(), 1);
|
|
if(pronounId < 0) return "";
|
|
String secondaryPronounFormat = Cache.dbManager.getPronounFormat(pronounId);
|
|
return baseFormat.replace("%main%", mainPronounFormat)
|
|
.replace("%secondary%", secondaryPronounFormat);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|