|
| 1 | +/* |
| 2 | + * |
| 3 | + * Essentials-Expansion |
| 4 | + * Copyright (C) 2018 Ryan McCarthy |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + * |
| 19 | + * |
| 20 | + */ |
| 21 | +package com.extendedclip.papi.expansion.essentials; |
| 22 | + |
| 23 | +import java.util.Date; |
| 24 | + |
| 25 | +import me.clip.placeholderapi.PlaceholderAPIPlugin; |
| 26 | +import me.clip.placeholderapi.expansion.PlaceholderExpansion; |
| 27 | +import me.clip.placeholderapi.util.TimeUtil; |
| 28 | + |
| 29 | +import org.bukkit.Bukkit; |
| 30 | +import org.bukkit.entity.Player; |
| 31 | + |
| 32 | +import com.earth2me.essentials.Essentials; |
| 33 | +import com.earth2me.essentials.Kit; |
| 34 | +import com.earth2me.essentials.User; |
| 35 | + |
| 36 | +public class EssentialsExpansion extends PlaceholderExpansion { |
| 37 | + |
| 38 | + private Essentials essentials; |
| 39 | + |
| 40 | + private final String VERSION = getClass().getPackage().getImplementationVersion(); |
| 41 | + |
| 42 | + @Override |
| 43 | + public boolean canRegister() { |
| 44 | + return Bukkit.getPluginManager().getPlugin("Essentials") != null; |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public boolean register() { |
| 49 | + essentials = (Essentials) Bukkit.getPluginManager().getPlugin(getPlugin()); |
| 50 | + if (essentials != null) { |
| 51 | + return super.register(); |
| 52 | + } |
| 53 | + return false; |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public String getAuthor() { |
| 58 | + return "clip"; |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public String getIdentifier() { |
| 63 | + return "essentials"; |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + public String getPlugin() { |
| 68 | + return "Essentials"; |
| 69 | + } |
| 70 | + |
| 71 | + @Override |
| 72 | + public String getVersion() { |
| 73 | + return VERSION; |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + public String onPlaceholderRequest(Player p, String identifier) { |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | + if (p == null) { |
| 82 | + return ""; |
| 83 | + } |
| 84 | + |
| 85 | + if (identifier.startsWith("kit_last_use_")) { |
| 86 | + String kit = identifier.split("kit_last_use_")[1]; |
| 87 | + |
| 88 | + Kit k = null; |
| 89 | + |
| 90 | + try { |
| 91 | + k = new Kit(kit, essentials); |
| 92 | + } catch (Exception e) { |
| 93 | + return "invalid kit"; |
| 94 | + } |
| 95 | + |
| 96 | + long time = essentials.getUser(p).getKitTimestamp(k.getName()); |
| 97 | + |
| 98 | + if (time == 1 || time <= 0) { |
| 99 | + return "1"; |
| 100 | + } |
| 101 | + return PlaceholderAPIPlugin.getDateFormat().format(new Date(time)); |
| 102 | + } |
| 103 | + |
| 104 | + if (identifier.startsWith("kit_is_available_")) { |
| 105 | + String kit = identifier.split("kit_is_available_")[1]; |
| 106 | + |
| 107 | + Kit k = null; |
| 108 | + |
| 109 | + User u = essentials.getUser(p); |
| 110 | + |
| 111 | + try { |
| 112 | + k = new Kit(kit, essentials); |
| 113 | + } catch (Exception e) { |
| 114 | + return PlaceholderAPIPlugin.booleanFalse(); |
| 115 | + } |
| 116 | + |
| 117 | + long time = -1 ; |
| 118 | + |
| 119 | + try { |
| 120 | + time = k.getNextUse(u); |
| 121 | + } catch (Exception e) { |
| 122 | + return PlaceholderAPIPlugin.booleanFalse(); |
| 123 | + } |
| 124 | + |
| 125 | + return time == 0 ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); |
| 126 | + } |
| 127 | + |
| 128 | + if (identifier.startsWith("kit_time_until_available_")) { |
| 129 | + String kit = identifier.split("kit_time_until_available_")[1]; |
| 130 | + |
| 131 | + Kit k = null; |
| 132 | + |
| 133 | + User u = essentials.getUser(p); |
| 134 | + |
| 135 | + try { |
| 136 | + k = new Kit(kit, essentials); |
| 137 | + } catch (Exception e) { |
| 138 | + return PlaceholderAPIPlugin.booleanFalse(); |
| 139 | + } |
| 140 | + |
| 141 | + long time = -1; |
| 142 | + |
| 143 | + try { |
| 144 | + time = k.getNextUse(u); |
| 145 | + } catch (Exception e) { |
| 146 | + return "-1"; |
| 147 | + } |
| 148 | + int seconds = (int)(time - System.currentTimeMillis())/1000; |
| 149 | + |
| 150 | + if (seconds <= 0) { |
| 151 | + return "0"; |
| 152 | + } |
| 153 | + return TimeUtil.getTime(seconds); |
| 154 | + } |
| 155 | + |
| 156 | + if (identifier.startsWith("has_kit_")) { |
| 157 | + String kit = identifier.split("has_kit_")[1]; |
| 158 | + return p.hasPermission("essentials.kits." + kit) ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); |
| 159 | + } |
| 160 | + |
| 161 | + switch (identifier) { |
| 162 | + case "is_teleport_enabled": |
| 163 | + return essentials.getUser(p).isTeleportEnabled() ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); |
| 164 | + case "vanished": |
| 165 | + return essentials.getUser(p).isVanished() ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); |
| 166 | + case "afk": |
| 167 | + return essentials.getUser(p).isAfk() ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); |
| 168 | + case "fly": |
| 169 | + return essentials.getUser(p).isFlyClickJump() ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); |
| 170 | + case "nickname": |
| 171 | + return essentials.getUser(p).getNickname() != null ? essentials.getUser(p).getNickname() : p.getName(); |
| 172 | + case "godmode": |
| 173 | + return essentials.getUser(p).isGodModeEnabled() ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); |
| 174 | + case "jailed": |
| 175 | + return String.valueOf(essentials.getUser(p).isJailed()); |
| 176 | + case "pm_recipient": |
| 177 | + User u = essentials.getUser(p); |
| 178 | + if (u.getReplyRecipient() != null) { |
| 179 | + return u.getReplyRecipient().getName(); |
| 180 | + } else { |
| 181 | + return ""; |
| 182 | + } |
| 183 | + } |
| 184 | + |
| 185 | + return null; |
| 186 | + } |
| 187 | + |
| 188 | + |
| 189 | + |
| 190 | + |
| 191 | +} |
0 commit comments