|
| 1 | +package com.github.elic0de.thejpspit.spigot.cosmetics; |
| 2 | + |
| 3 | +import com.github.elic0de.thejpspit.spigot.player.PitPlayer; |
| 4 | +import java.math.BigDecimal; |
| 5 | +import java.util.List; |
| 6 | +import java.util.logging.Logger; |
| 7 | +import org.bukkit.Bukkit; |
| 8 | +import org.bukkit.inventory.ItemStack; |
| 9 | + |
| 10 | +public abstract class AbstractCosmetic implements Cosmetic { |
| 11 | + |
| 12 | + private static final Logger LOGGER = Bukkit.getLogger(); |
| 13 | + private final ItemStack icon; |
| 14 | + private final String identifier; |
| 15 | + private final String displayName; |
| 16 | + private final String permission; |
| 17 | + private final List<String> description; |
| 18 | + private boolean enabled; |
| 19 | + |
| 20 | + public AbstractCosmetic(String identifier, String displayName, String permission, List<String> description) { |
| 21 | + this.identifier = identifier; |
| 22 | + this.displayName = displayName; |
| 23 | + this.permission = permission; |
| 24 | + this.description = description; |
| 25 | + this.icon = this.getDefaultIcon(); |
| 26 | + this.enabled = true; |
| 27 | + this.validatePerkIntegrity(); |
| 28 | + } |
| 29 | + |
| 30 | + public abstract ItemStack getDefaultIcon(); |
| 31 | + |
| 32 | + private void validatePerkIntegrity() { |
| 33 | + if(this.getIdentifier().contains(",")){ |
| 34 | + throw new IllegalStateException("The identifier of a perk isn't allowed to contain a comma in order to make easy database serializing possible."); |
| 35 | + } |
| 36 | + /*try { |
| 37 | + //NullSafety.validateNotNull(this.getDisplayName(), this.getPermission(), this.getDescription(), this.getIcon()); |
| 38 | + } catch (NullPointerException exception) { |
| 39 | + this.enabled = false; |
| 40 | + LOGGER.log(Level.SEVERE, String.format("Cannot create instance of perk %s: %s", |
| 41 | + this.getClass().getName(), exception.getMessage())); |
| 42 | + }*/ |
| 43 | + } |
| 44 | + |
| 45 | + @Override |
| 46 | + public void perkEnable(PitPlayer player) { |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public void perkDisable(PitPlayer player) { |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public void prePerkDisable(PitPlayer player) { |
| 55 | + this.perkDisable(player); |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public void prePerkEnable(PitPlayer player) { |
| 60 | + this.perkEnable(player); |
| 61 | + } |
| 62 | + |
| 63 | + /* the getter and setter of this class */ |
| 64 | + |
| 65 | + @Override |
| 66 | + public String getIdentifier() { |
| 67 | + return identifier; |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public String getDisplayName() { |
| 72 | + return displayName; |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + public String getPermission() { |
| 77 | + return permission; |
| 78 | + } |
| 79 | + |
| 80 | + @Override |
| 81 | + public List<String> getDescription() { |
| 82 | + return description; |
| 83 | + } |
| 84 | + |
| 85 | + @Override |
| 86 | + public boolean isEnabled() { |
| 87 | + return enabled; |
| 88 | + } |
| 89 | + |
| 90 | + @Override |
| 91 | + public ItemStack getIcon() { |
| 92 | + return this.icon == null ? this.getDefaultIcon() : this.icon; |
| 93 | + } |
| 94 | + |
| 95 | + @Override |
| 96 | + public BigDecimal getPrice() { |
| 97 | + return BigDecimal.ONE; |
| 98 | + } |
| 99 | +} |
0 commit comments