|
| 1 | +package com.dumbdogdiner.stickycommands; |
| 2 | + |
| 3 | +import me.clip.placeholderapi.expansion.PlaceholderExpansion; |
| 4 | +import org.bukkit.entity.Player; |
| 5 | + |
| 6 | +public class StickyCommandsPlaceholder extends PlaceholderExpansion { |
| 7 | + private static StickyCommandsPlaceholder INSTANCE; |
| 8 | + private StickyCommandsPlaceholder(){ |
| 9 | + |
| 10 | + } |
| 11 | + |
| 12 | + |
| 13 | + /** |
| 14 | + * Because this is an internal class, |
| 15 | + * you must override this method to let PlaceholderAPI know to not unregister your expansion class when |
| 16 | + * PlaceholderAPI is reloaded |
| 17 | + * |
| 18 | + * @return true to persist through reloads |
| 19 | + */ |
| 20 | + @Override |
| 21 | + public boolean persist(){ |
| 22 | + return true; |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * The name of the person who created this expansion should go here. |
| 27 | + * <br>For convienience do we return the author from the plugin.yml |
| 28 | + * |
| 29 | + * @return The name of the author as a String. |
| 30 | + */ |
| 31 | + @Override |
| 32 | + public String getAuthor(){ |
| 33 | + return StickyCommands.getInstance().getDescription().getAuthors().toString(); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * The placeholder identifier should go here. |
| 38 | + * <br>This is what tells PlaceholderAPI to call our onRequest |
| 39 | + * method to obtain a value if a placeholder starts with our |
| 40 | + * identifier. |
| 41 | + * <br>The identifier has to be lowercase and can't contain _ or % |
| 42 | + * |
| 43 | + * @return The identifier in {@code %<identifier>_<value>%} as String. |
| 44 | + */ |
| 45 | + @Override |
| 46 | + public String getIdentifier(){ |
| 47 | + return StickyCommands.getInstance().getName().toLowerCase(); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * This is the version of the expansion. |
| 52 | + * <br>You don't have to use numbers, since it is set as a String. |
| 53 | + * |
| 54 | + * For convienience do we return the version from the plugin.yml |
| 55 | + * |
| 56 | + * @return The version as a String. |
| 57 | + */ |
| 58 | + @Override |
| 59 | + public String getVersion(){ |
| 60 | + return StickyCommands.getInstance().getDescription().getVersion(); |
| 61 | + } |
| 62 | + |
| 63 | + public static StickyCommandsPlaceholder getInstance(){ |
| 64 | + if(INSTANCE == null) |
| 65 | + INSTANCE = new StickyCommandsPlaceholder(); |
| 66 | + return INSTANCE; |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * This is the method called when a placeholder with our identifier |
| 71 | + * is found and needs a value. |
| 72 | + * <br>We specify the value identifier in this method. |
| 73 | + * <br>Since version 2.9.1 can you use OfflinePlayers in your requests. |
| 74 | + * |
| 75 | + * @param player |
| 76 | + * A {@link org.bukkit.entity.Player Player}. |
| 77 | + * @param identifier |
| 78 | + * A String containing the identifier/value. |
| 79 | + * |
| 80 | + * @return possibly-null String of the requested identifier. |
| 81 | + */ |
| 82 | + @Override |
| 83 | + public String onPlaceholderRequest(Player player, String identifier){ |
| 84 | + // For now: ASSUME player is the player we want to know if is AFK; |
| 85 | + |
| 86 | + // %stickycommands_afk% |
| 87 | + if(identifier.equals("afk")){ |
| 88 | + return StickyCommands.getInstance().getOnlineUser(player.getUniqueId()).isAfk() ? "&8[AFK]" : ""; |
| 89 | + } |
| 90 | + |
| 91 | + |
| 92 | + // We return null if an invalid placeholder was provided |
| 93 | + return null; |
| 94 | + } |
| 95 | +} |
0 commit comments