Heavy code style changes and slight refactoring

This commit is contained in:
Christian Koop 2023-07-18 15:04:03 +02:00
parent 4aee977bfa
commit b63bd350c6
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
33 changed files with 361 additions and 376 deletions

View File

@ -37,8 +37,6 @@ import java.util.Collections;
import java.util.List; import java.util.List;
public class EpicVouchers extends SongodaPlugin { public class EpicVouchers extends SongodaPlugin {
private static EpicVouchers INSTANCE;
private final GuiManager guiManager = new GuiManager(this); private final GuiManager guiManager = new GuiManager(this);
private CommandManager commandManager; private CommandManager commandManager;
private VoucherManager voucherManager; private VoucherManager voucherManager;
@ -48,18 +46,21 @@ public class EpicVouchers extends SongodaPlugin {
private VoucherExecutor voucherExecutor; private VoucherExecutor voucherExecutor;
private final Config vouchersConfig = new Config(this, "vouchers.yml"); private final Config vouchersConfig = new Config(this, "vouchers.yml");
/**
* @deprecated Use {@link org.bukkit.plugin.java.JavaPlugin#getPlugin(Class)} instead
*/
@Deprecated
public static EpicVouchers getInstance() { public static EpicVouchers getInstance() {
return INSTANCE; return getPlugin(EpicVouchers.class);
} }
@Override @Override
public void onPluginLoad() { public void onPluginLoad() {
INSTANCE = this;
} }
@Override @Override
public void onPluginDisable() { public void onPluginDisable() {
connections.closeMySQL(); this.connections.closeMySQL();
saveVouchers(); saveVouchers();
} }
@ -96,7 +97,7 @@ public class EpicVouchers extends SongodaPlugin {
PluginManager manager = Bukkit.getServer().getPluginManager(); PluginManager manager = Bukkit.getServer().getPluginManager();
// Listeners // Listeners
guiManager.init(); this.guiManager.init();
manager.registerEvents(new PlayerInteractListener(this), this); manager.registerEvents(new PlayerInteractListener(this), this);
manager.registerEvents(new PlayerCommandListener(), this); manager.registerEvents(new PlayerCommandListener(), this);
} }
@ -107,13 +108,13 @@ public class EpicVouchers extends SongodaPlugin {
saveResource("vouchers.yml", false); saveResource("vouchers.yml", false);
} }
synchronized (vouchersConfig) { synchronized (this.vouchersConfig) {
vouchersConfig.load(); this.vouchersConfig.load();
} }
loadVouchersFromFile(); loadVouchersFromFile();
connections.openMySQL(); this.connections.openMySQL();
// FIXME: Config system needs to be greatly redone and only write changes when changes were made - Maybe even split it into multiple smaler files // FIXME: Config system needs to be greatly redone and only write changes when changes were made - Maybe even split it into multiple smaler files
// Issue https://support.songoda.com/browse/SD-8155 has been hotfixed by writing changes to the file async and blocking the main thread when needed. This requires the use of `synchronized` // Issue https://support.songoda.com/browse/SD-8155 has been hotfixed by writing changes to the file async and blocking the main thread when needed. This requires the use of `synchronized`
@ -129,13 +130,13 @@ public class EpicVouchers extends SongodaPlugin {
} }
private void loadVouchersFromFile() { private void loadVouchersFromFile() {
synchronized (vouchersConfig) { synchronized (this.vouchersConfig) {
voucherManager.clearVouchers(); this.voucherManager.clearVouchers();
if (vouchersConfig.contains("vouchers")) { if (this.vouchersConfig.contains("vouchers")) {
for (String key : vouchersConfig.getConfigurationSection("vouchers").getKeys(false)) { for (String key : this.vouchersConfig.getConfigurationSection("vouchers").getKeys(false)) {
Voucher voucher = new Voucher(key, this); Voucher voucher = new Voucher(key, this);
ConfigurationSection cs = vouchersConfig.getConfigurationSection("vouchers." + key); ConfigurationSection cs = this.vouchersConfig.getConfigurationSection("vouchers." + key);
Material material; Material material;
String stringMaterial = cs.getString("material"); String stringMaterial = cs.getString("material");
@ -144,7 +145,9 @@ public class EpicVouchers extends SongodaPlugin {
material = Material.PAPER; material = Material.PAPER;
} else { } else {
material = Material.matchMaterial(stringMaterial); material = Material.matchMaterial(stringMaterial);
if (material == null) material = Material.PAPER; if (material == null) {
material = Material.PAPER;
}
} }
voucher.setPermission(cs.getString("permission", "")) voucher.setPermission(cs.getString("permission", ""))
@ -178,7 +181,7 @@ public class EpicVouchers extends SongodaPlugin {
.setEffectAmplifier(cs.getInt("effects.amplifier")) .setEffectAmplifier(cs.getInt("effects.amplifier"))
.setItemStack(cs.getItemStack("itemstack", null)); .setItemStack(cs.getItemStack("itemstack", null));
voucherManager.addVoucher(voucher); this.voucherManager.addVoucher(voucher);
} }
} }
} }
@ -201,14 +204,14 @@ public class EpicVouchers extends SongodaPlugin {
private void saveVouchersAsync(Callback callback) { private void saveVouchersAsync(Callback callback) {
new Thread(() -> { new Thread(() -> {
try { try {
synchronized (vouchersConfig) { synchronized (this.vouchersConfig) {
Collection<Voucher> voucherList = voucherManager.getVouchers(); Collection<Voucher> voucherList = this.voucherManager.getVouchers();
ConfigurationSection cfgSec = vouchersConfig.getConfigurationSection("vouchers"); ConfigurationSection cfgSec = this.vouchersConfig.getConfigurationSection("vouchers");
if (cfgSec != null) { if (cfgSec != null) {
for (String voucherName : cfgSec.getKeys(false)) { for (String voucherName : cfgSec.getKeys(false)) {
if (voucherList.stream().noneMatch(voucher -> voucher.getKey().equals(voucherName))) { if (voucherList.stream().noneMatch(voucher -> voucher.getKey().equals(voucherName))) {
vouchersConfig.set("vouchers." + voucherName, null); this.vouchersConfig.set("vouchers." + voucherName, null);
} }
} }
} }
@ -216,39 +219,39 @@ public class EpicVouchers extends SongodaPlugin {
for (Voucher voucher : voucherList) { for (Voucher voucher : voucherList) {
String prefix = "vouchers." + voucher.getKey() + "."; String prefix = "vouchers." + voucher.getKey() + ".";
vouchersConfig.set(prefix + "permission", voucher.getPermission()); this.vouchersConfig.set(prefix + "permission", voucher.getPermission());
vouchersConfig.set(prefix + "material", voucher.getMaterial().name()); this.vouchersConfig.set(prefix + "material", voucher.getMaterial().name());
vouchersConfig.set(prefix + "data", voucher.getData()); this.vouchersConfig.set(prefix + "data", voucher.getData());
vouchersConfig.set(prefix + "name", voucher.getName()); this.vouchersConfig.set(prefix + "name", voucher.getName());
vouchersConfig.set(prefix + "lore", voucher.getLore()); this.vouchersConfig.set(prefix + "lore", voucher.getLore());
vouchersConfig.set(prefix + "texture", voucher.getTexture()); this.vouchersConfig.set(prefix + "texture", voucher.getTexture());
vouchersConfig.set(prefix + "glow", voucher.isGlow()); this.vouchersConfig.set(prefix + "glow", voucher.isGlow());
vouchersConfig.set(prefix + "confirm", voucher.isConfirm()); this.vouchersConfig.set(prefix + "confirm", voucher.isConfirm());
vouchersConfig.set(prefix + "unbreakable", voucher.isUnbreakable()); this.vouchersConfig.set(prefix + "unbreakable", voucher.isUnbreakable());
vouchersConfig.set(prefix + "hide-attributes", voucher.isHideAttributes()); this.vouchersConfig.set(prefix + "hide-attributes", voucher.isHideAttributes());
vouchersConfig.set(prefix + "remove-item", voucher.isRemoveItem()); this.vouchersConfig.set(prefix + "remove-item", voucher.isRemoveItem());
vouchersConfig.set(prefix + "heal-player", voucher.isHealPlayer()); this.vouchersConfig.set(prefix + "heal-player", voucher.isHealPlayer());
vouchersConfig.set(prefix + "smite-effect", voucher.isSmiteEffect()); this.vouchersConfig.set(prefix + "smite-effect", voucher.isSmiteEffect());
vouchersConfig.set(prefix + "coolDown", voucher.getCoolDown()); this.vouchersConfig.set(prefix + "coolDown", voucher.getCoolDown());
vouchersConfig.set(prefix + "broadcasts", voucher.getBroadcasts()); this.vouchersConfig.set(prefix + "broadcasts", voucher.getBroadcasts());
vouchersConfig.set(prefix + "messages", voucher.getMessages()); this.vouchersConfig.set(prefix + "messages", voucher.getMessages());
vouchersConfig.set(prefix + "commands", voucher.getCommands()); this.vouchersConfig.set(prefix + "commands", voucher.getCommands());
vouchersConfig.set(prefix + "actionbar", voucher.getActionBar()); this.vouchersConfig.set(prefix + "actionbar", voucher.getActionBar());
vouchersConfig.set(prefix + "titles.title", voucher.getTitle()); this.vouchersConfig.set(prefix + "titles.title", voucher.getTitle());
vouchersConfig.set(prefix + "titles.subtitle", voucher.getSubTitle()); this.vouchersConfig.set(prefix + "titles.subtitle", voucher.getSubTitle());
vouchersConfig.set(prefix + "titles.fade-in", voucher.getTitleFadeIn()); this.vouchersConfig.set(prefix + "titles.fade-in", voucher.getTitleFadeIn());
vouchersConfig.set(prefix + "titles.stay", voucher.getTitleStay()); this.vouchersConfig.set(prefix + "titles.stay", voucher.getTitleStay());
vouchersConfig.set(prefix + "titles.fade-out", voucher.getTitleFadeOut()); this.vouchersConfig.set(prefix + "titles.fade-out", voucher.getTitleFadeOut());
vouchersConfig.set(prefix + "sounds.sound", voucher.getSound()); this.vouchersConfig.set(prefix + "sounds.sound", voucher.getSound());
vouchersConfig.set(prefix + "sounds.pitch", voucher.getSoundPitch()); this.vouchersConfig.set(prefix + "sounds.pitch", voucher.getSoundPitch());
vouchersConfig.set(prefix + "particles.particle", voucher.getParticle()); this.vouchersConfig.set(prefix + "particles.particle", voucher.getParticle());
vouchersConfig.set(prefix + "particles.amount", voucher.getParticleAmount()); this.vouchersConfig.set(prefix + "particles.amount", voucher.getParticleAmount());
vouchersConfig.set(prefix + "effects.effect", voucher.getEffect()); this.vouchersConfig.set(prefix + "effects.effect", voucher.getEffect());
vouchersConfig.set(prefix + "effects.amplifier", voucher.getEffectAmplifier()); this.vouchersConfig.set(prefix + "effects.amplifier", voucher.getEffectAmplifier());
vouchersConfig.set(prefix + "itemstack", voucher.getItemStack()); this.vouchersConfig.set(prefix + "itemstack", voucher.getItemStack());
} }
vouchersConfig.saveChanges(); this.vouchersConfig.saveChanges();
callback.accept(null); callback.accept(null);
} }
@ -260,8 +263,8 @@ public class EpicVouchers extends SongodaPlugin {
@Override @Override
public void onConfigReload() { public void onConfigReload() {
synchronized (vouchersConfig) { synchronized (this.vouchersConfig) {
vouchersConfig.load(); this.vouchersConfig.load();
} }
loadVouchersFromFile(); loadVouchersFromFile();
@ -272,7 +275,7 @@ public class EpicVouchers extends SongodaPlugin {
@Override @Override
public List<Config> getExtraConfig() { public List<Config> getExtraConfig() {
return Collections.singletonList(vouchersConfig); return Collections.singletonList(this.vouchersConfig);
} }
public Connections getConnections() { public Connections getConnections() {
@ -288,14 +291,14 @@ public class EpicVouchers extends SongodaPlugin {
} }
public CommandManager getCommandManager() { public CommandManager getCommandManager() {
return commandManager; return this.commandManager;
} }
public VoucherManager getVoucherManager() { public VoucherManager getVoucherManager() {
return voucherManager; return this.voucherManager;
} }
public GuiManager getGuiManager() { public GuiManager getGuiManager() {
return guiManager; return this.guiManager;
} }
} }

View File

@ -12,13 +12,13 @@ public class CommandEditor extends AbstractCommand {
final EpicVouchers instance; final EpicVouchers instance;
public CommandEditor(EpicVouchers instance) { public CommandEditor(EpicVouchers instance) {
super(true, "editor"); super(CommandType.PLAYER_ONLY, "EpicVouchers");
this.instance = instance; this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
new VoucherMenu(instance).open((Player) sender); new VoucherMenu(this.instance).open((Player) sender);
return ReturnType.SUCCESS; return ReturnType.SUCCESS;
} }

View File

@ -11,17 +11,17 @@ public class CommandEpicVouchers extends AbstractCommand {
final EpicVouchers instance; final EpicVouchers instance;
public CommandEpicVouchers(EpicVouchers instance) { public CommandEpicVouchers(EpicVouchers instance) {
super(false, "EpicVouchers"); super(CommandType.CONSOLE_OK, "EpicVouchers");
this.instance = instance; this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
sender.sendMessage(""); sender.sendMessage("");
instance.getLocale().newMessage("&7Version " + instance.getDescription().getVersion() this.instance.getLocale().newMessage("&7Version " + this.instance.getDescription().getVersion()
+ " Created with <3 by &5&l&oSongoda").sendPrefixedMessage(sender); + " Created with <3 by &5&l&oSongoda").sendPrefixedMessage(sender);
for (AbstractCommand command : instance.getCommandManager().getAllCommands()) { for (AbstractCommand command : this.instance.getCommandManager().getAllCommands()) {
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) { if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription())); sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription()));
} }

View File

@ -15,29 +15,30 @@ public class CommandForce extends AbstractCommand {
final EpicVouchers instance; final EpicVouchers instance;
public CommandForce(EpicVouchers instance) { public CommandForce(EpicVouchers instance) {
super(false, "force"); super(CommandType.CONSOLE_OK, "force");
this.instance = instance; this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length != 3) if (args.length != 3) {
return ReturnType.SYNTAX_ERROR; return ReturnType.SYNTAX_ERROR;
}
Player player = Bukkit.getPlayer(args[0]); Player player = Bukkit.getPlayer(args[0]);
if (Bukkit.getPlayer(args[0]) == null) { if (Bukkit.getPlayer(args[0]) == null) {
instance.getLocale().newMessage("&cThat player does not exist or is currently offline.").sendPrefixedMessage(sender); this.instance.getLocale().newMessage("&cThat player does not exist or is currently offline.").sendPrefixedMessage(sender);
return ReturnType.FAILURE; return ReturnType.FAILURE;
} }
Voucher voucher = instance.getVoucherManager().getVoucher(args[1]); Voucher voucher = this.instance.getVoucherManager().getVoucher(args[1]);
if (voucher == null) { if (voucher == null) {
sender.sendMessage("Unknown voucher..."); sender.sendMessage("Unknown voucher...");
return ReturnType.FAILURE; return ReturnType.FAILURE;
} }
voucher.forceRedeem(sender, Collections.singletonList(player), Integer.parseInt(args[2])); voucher.forceRedeem(sender, Collections.singletonList(player), Integer.parseInt(args[2]));
instance.getLocale().getMessage("command.force.send") this.instance.getLocale().getMessage("command.force.send")
.processPlaceholder("player", player.getName()) .processPlaceholder("player", player.getName())
.processPlaceholder("voucher", voucher.getName(true)) .processPlaceholder("voucher", voucher.getName(true))
.processPlaceholder("amount", args[2].trim()) .processPlaceholder("amount", args[2].trim())
@ -54,7 +55,7 @@ public class CommandForce extends AbstractCommand {
result.add(online.getName()); result.add(online.getName());
} }
} else if (args.length == 2) { } else if (args.length == 2) {
for (Voucher voucher : instance.getVoucherManager().getVouchers()) { for (Voucher voucher : this.instance.getVoucherManager().getVouchers()) {
result.add(voucher.getKey()); result.add(voucher.getKey());
} }
} else if (args.length == 3) { } else if (args.length == 3) {

View File

@ -13,23 +13,24 @@ public class CommandForceAll extends AbstractCommand {
final EpicVouchers instance; final EpicVouchers instance;
public CommandForceAll(EpicVouchers instance) { public CommandForceAll(EpicVouchers instance) {
super(false, "forceall"); super(CommandType.CONSOLE_OK, "forceall");
this.instance = instance; this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length != 2) if (args.length != 2) {
return ReturnType.SYNTAX_ERROR; return ReturnType.SYNTAX_ERROR;
}
Voucher voucher = instance.getVoucherManager().getVoucher(args[0]); Voucher voucher = this.instance.getVoucherManager().getVoucher(args[0]);
if (voucher == null) { if (voucher == null) {
sender.sendMessage("Unknown voucher..."); sender.sendMessage("Unknown voucher...");
return ReturnType.FAILURE; return ReturnType.FAILURE;
} }
voucher.forceRedeem(sender, new ArrayList<>(Bukkit.getOnlinePlayers()), Integer.parseInt(args[1])); voucher.forceRedeem(sender, new ArrayList<>(Bukkit.getOnlinePlayers()), Integer.parseInt(args[1]));
instance.getLocale().getMessage("command.force.send") this.instance.getLocale().getMessage("command.force.send")
.processPlaceholder("player", "everyone") .processPlaceholder("player", "everyone")
.processPlaceholder("voucher", voucher.getName(true)) .processPlaceholder("voucher", voucher.getName(true))
.processPlaceholder("amount", args[1].trim()) .processPlaceholder("amount", args[1].trim())
@ -42,7 +43,7 @@ public class CommandForceAll extends AbstractCommand {
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
if (args.length == 1) { if (args.length == 1) {
for (Voucher voucher : instance.getVoucherManager().getVouchers()) { for (Voucher voucher : this.instance.getVoucherManager().getVouchers()) {
result.add(voucher.getKey()); result.add(voucher.getKey());
} }
} else if (args.length == 2) { } else if (args.length == 2) {

View File

@ -15,22 +15,23 @@ public class CommandGive extends AbstractCommand {
final EpicVouchers instance; final EpicVouchers instance;
public CommandGive(EpicVouchers instance) { public CommandGive(EpicVouchers instance) {
super(false, "give"); super(CommandType.CONSOLE_OK, "give");
this.instance = instance; this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length != 3) if (args.length != 3) {
return ReturnType.SYNTAX_ERROR; return ReturnType.SYNTAX_ERROR;
}
Player player = Bukkit.getPlayer(args[0]); Player player = Bukkit.getPlayer(args[0]);
if (Bukkit.getPlayer(args[0]) == null) { if (Bukkit.getPlayer(args[0]) == null) {
instance.getLocale().newMessage("&cThat player does not exist or is currently offline.").sendPrefixedMessage(sender); this.instance.getLocale().newMessage("&cThat player does not exist or is currently offline.").sendPrefixedMessage(sender);
return ReturnType.FAILURE; return ReturnType.FAILURE;
} }
Voucher voucher = instance.getVoucherManager().getVoucher(args[1]); Voucher voucher = this.instance.getVoucherManager().getVoucher(args[1]);
if (voucher == null) { if (voucher == null) {
sender.sendMessage("Unknown voucher..."); sender.sendMessage("Unknown voucher...");
return ReturnType.FAILURE; return ReturnType.FAILURE;
@ -49,7 +50,7 @@ public class CommandGive extends AbstractCommand {
result.add(online.getName()); result.add(online.getName());
} }
} else if (args.length == 2) { } else if (args.length == 2) {
for (Voucher voucher : instance.getVoucherManager().getVouchers()) { for (Voucher voucher : this.instance.getVoucherManager().getVouchers()) {
result.add(voucher.getKey()); result.add(voucher.getKey());
} }
} else if (args.length == 3) { } else if (args.length == 3) {

View File

@ -12,16 +12,17 @@ public class CommandGiveAll extends AbstractCommand {
final EpicVouchers instance; final EpicVouchers instance;
public CommandGiveAll(EpicVouchers instance) { public CommandGiveAll(EpicVouchers instance) {
super(false, "giveall"); super(CommandType.CONSOLE_OK, "giveall");
this.instance = instance; this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length != 2) if (args.length != 2) {
return ReturnType.SYNTAX_ERROR; return ReturnType.SYNTAX_ERROR;
}
Voucher voucher = instance.getVoucherManager().getVoucher(args[0]); Voucher voucher = this.instance.getVoucherManager().getVoucher(args[0]);
if (voucher == null) { if (voucher == null) {
sender.sendMessage("Unknown voucher..."); sender.sendMessage("Unknown voucher...");
return ReturnType.FAILURE; return ReturnType.FAILURE;
@ -36,7 +37,7 @@ public class CommandGiveAll extends AbstractCommand {
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
if (args.length == 1) { if (args.length == 1) {
for (Voucher voucher : instance.getVoucherManager().getVouchers()) { for (Voucher voucher : this.instance.getVoucherManager().getVouchers()) {
result.add(voucher.getKey()); result.add(voucher.getKey());
} }
} else if (args.length == 2) { } else if (args.length == 2) {

View File

@ -12,18 +12,18 @@ public class CommandList extends AbstractCommand {
final EpicVouchers instance; final EpicVouchers instance;
public CommandList(EpicVouchers instance) { public CommandList(EpicVouchers instance) {
super(false, "list"); super(CommandType.CONSOLE_OK, "list");
this.instance = instance; this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
StringJoiner joiner = new StringJoiner(", "); StringJoiner joiner = new StringJoiner(", ");
for (Voucher voucher : instance.getVoucherManager().getVouchers()) { for (Voucher voucher : this.instance.getVoucherManager().getVouchers()) {
joiner.add(voucher.getKey()); joiner.add(voucher.getKey());
} }
instance.getLocale().getMessage("command.list.list") this.instance.getLocale().getMessage("command.list.list")
.processPlaceholder("list", joiner.toString()) .processPlaceholder("list", joiner.toString())
.sendPrefixedMessage(sender); .sendPrefixedMessage(sender);

View File

@ -10,14 +10,14 @@ public class CommandReload extends AbstractCommand {
final EpicVouchers instance; final EpicVouchers instance;
public CommandReload(EpicVouchers instance) { public CommandReload(EpicVouchers instance) {
super(false, "reload"); super(CommandType.CONSOLE_OK, "reload");
this.instance = instance; this.instance = instance;
} }
@Override @Override
protected ReturnType runCommand(CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
instance.reloadConfig(); this.instance.reloadConfig();
instance.getLocale().getMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender); this.instance.getLocale().getMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender);
return ReturnType.SUCCESS; return ReturnType.SUCCESS;
} }

View File

@ -7,7 +7,7 @@ import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
public class ForceRedeemEvent extends Event implements Cancellable { public class ForceRedeemEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList HANDLER_LIST = new HandlerList();
private final Player player; private final Player player;
private final String voucher; private final String voucher;
@ -24,35 +24,35 @@ public class ForceRedeemEvent extends Event implements Cancellable {
} }
public Player getPlayer() { public Player getPlayer() {
return player; return this.player;
} }
public String getVoucher() { public String getVoucher() {
return voucher; return this.voucher;
} }
public int getAmount() { public int getAmount() {
return amount; return this.amount;
} }
public CommandSender getSender() { public CommandSender getSender() {
return sender; return this.sender;
} }
public boolean isCancelled() { public boolean isCancelled() {
return cancelled; return this.cancelled;
} }
public void setCancelled(boolean cancelled) { public void setCancelled(boolean cancel) {
this.cancelled = cancelled; this.cancelled = cancel;
} }
@Override @Override
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handlers; return HANDLER_LIST;
} }
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return handlers; return HANDLER_LIST;
} }
} }

View File

@ -8,8 +8,7 @@ import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class VoucherReceiveEvent extends Event implements Cancellable { public class VoucherReceiveEvent extends Event implements Cancellable {
private static final HandlerList HANDLER_LIST = new HandlerList();
private static final HandlerList handlers = new HandlerList();
private final Player player; private final Player player;
private final String voucher; private final String voucher;
@ -28,39 +27,39 @@ public class VoucherReceiveEvent extends Event implements Cancellable {
} }
public Player getPlayer() { public Player getPlayer() {
return player; return this.player;
} }
public String getVoucher() { public String getVoucher() {
return voucher; return this.voucher;
} }
public ItemStack getItem() { public ItemStack getItem() {
return item; return this.item;
} }
public int getAmount() { public int getAmount() {
return amount; return this.amount;
} }
public CommandSender getSender() { public CommandSender getSender() {
return sender; return this.sender;
} }
public boolean isCancelled() { public boolean isCancelled() {
return cancelled; return this.cancelled;
} }
public void setCancelled(boolean cancelled) { public void setCancelled(boolean cancel) {
this.cancelled = cancelled; this.cancelled = cancel;
} }
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handlers; return HANDLER_LIST;
} }
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return handlers; return HANDLER_LIST;
} }
} }

View File

@ -7,8 +7,7 @@ import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class VoucherRedeemEvent extends Event implements Cancellable { public class VoucherRedeemEvent extends Event implements Cancellable {
private static final HandlerList HANDLER_LIST = new HandlerList();
private static final HandlerList handlers = new HandlerList();
private final Player player; private final Player player;
private final String voucher; private final String voucher;
@ -25,35 +24,35 @@ public class VoucherRedeemEvent extends Event implements Cancellable {
} }
public Player getPlayer() { public Player getPlayer() {
return player; return this.player;
} }
public String getVoucher() { public String getVoucher() {
return voucher; return this.voucher;
} }
public ItemStack getItem() { public ItemStack getItem() {
return item; return this.item;
} }
public boolean getManual() { public boolean getManual() {
return manual; return this.manual;
} }
public boolean isCancelled() { public boolean isCancelled() {
return cancelled; return this.cancelled;
} }
public void setCancelled(boolean cancelled) { public void setCancelled(boolean cancel) {
this.cancelled = cancelled; this.cancelled = cancel;
} }
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handlers; return HANDLER_LIST;
} }
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return handlers; return HANDLER_LIST;
} }
} }

View File

@ -19,17 +19,17 @@ public class Connections {
} }
public void openMySQL() { public void openMySQL() {
if (!instance.getConfig().getBoolean("Database.Activate Mysql Support") || connection == null) { if (!this.instance.getConfig().getBoolean("Database.Activate Mysql Support") || this.connection == null) {
return; return;
} }
try { try {
String mysqlIP = instance.getConfig().getString("Database.IP"); String mysqlIP = this.instance.getConfig().getString("Database.IP");
String mysqlPort = instance.getConfig().getString("Database.PORT"); String mysqlPort = this.instance.getConfig().getString("Database.PORT");
String mysqlDatabase = instance.getConfig().getString("Database.Database Name"); String mysqlDatabase = this.instance.getConfig().getString("Database.Database Name");
String mysqlUsername = instance.getConfig().getString("Database.Username"); String mysqlUsername = this.instance.getConfig().getString("Database.Username");
String mysqlPassword = instance.getConfig().getString("Database.Password"); String mysqlPassword = this.instance.getConfig().getString("Database.Password");
connection = DriverManager.getConnection("jdbc:mysql://" + mysqlIP + ":" + mysqlPort + "/" + mysqlDatabase + "?useSSL=true?autoReconnect=true", mysqlUsername, mysqlPassword); this.connection = DriverManager.getConnection("jdbc:mysql://" + mysqlIP + ":" + mysqlPort + "/" + mysqlDatabase + "?useSSL=true?autoReconnect=true", mysqlUsername, mysqlPassword);
System.out.println(TextUtils.formatText("&fSuccessfully created a connection with MySQL.")); System.out.println(TextUtils.formatText("&fSuccessfully created a connection with MySQL."));
} catch (Exception error) { } catch (Exception error) {
System.out.println(TextUtils.formatText("&cFailed to create a connection with MySQL.")); System.out.println(TextUtils.formatText("&cFailed to create a connection with MySQL."));
@ -38,11 +38,11 @@ public class Connections {
} }
public void closeMySQL() { public void closeMySQL() {
if (!instance.getConfig().getBoolean("Database.Activate Mysql Support") || connection == null) { if (!this.instance.getConfig().getBoolean("Database.Activate Mysql Support") || this.connection == null) {
return; return;
} }
try { try {
connection.close(); this.connection.close();
System.out.println(TextUtils.formatText("&fSuccessfully closed the MySQL connection.")); System.out.println(TextUtils.formatText("&fSuccessfully closed the MySQL connection."));
} catch (Exception error) { } catch (Exception error) {
System.out.println(TextUtils.formatText("&cFailed to close the MySQL connection.")); System.out.println(TextUtils.formatText("&cFailed to close the MySQL connection."));
@ -51,14 +51,14 @@ public class Connections {
} }
public void saveRedeem(Player player, String voucher) { public void saveRedeem(Player player, String voucher) {
if (!instance.getConfig().getBoolean("Database.Activate Mysql Support") || connection == null) { if (!this.instance.getConfig().getBoolean("Database.Activate Mysql Support") || this.connection == null) {
return; return;
} }
Timestamp stamp = new Timestamp(System.currentTimeMillis()); Timestamp stamp = new Timestamp(System.currentTimeMillis());
Date date = new Date(stamp.getTime()); Date date = new Date(stamp.getTime());
String time = date.toString(); String time = date.toString();
try { try {
Statement statement = connection.createStatement(); Statement statement = this.connection.createStatement();
statement.execute("CREATE TABLE IF NOT EXISTS redeems (id INT NOT NULL AUTO_INCREMENT, player varchar(120) NOT NULL, voucher varchar(120) NOT NULL, timestamp varchar(120) NOT NULL, PRIMARY KEY (ID));"); statement.execute("CREATE TABLE IF NOT EXISTS redeems (id INT NOT NULL AUTO_INCREMENT, player varchar(120) NOT NULL, voucher varchar(120) NOT NULL, timestamp varchar(120) NOT NULL, PRIMARY KEY (ID));");
statement.execute("INSERT INTO redeems VALUES (default, '" + player.getName() + "', '" + voucher + "', '" + time + "');"); statement.execute("INSERT INTO redeems VALUES (default, '" + player.getName() + "', '" + voucher + "', '" + time + "');");
statement.close(); statement.close();

View File

@ -63,7 +63,7 @@ public class ItemBuilder {
} }
public ItemMeta getMeta() { public ItemMeta getMeta() {
return meta; return this.meta;
} }
public ItemBuilder meta(ItemMeta meta) { public ItemBuilder meta(ItemMeta meta) {
@ -75,15 +75,15 @@ public class ItemBuilder {
* Name: * Name:
*/ */
public boolean hasName() { public boolean hasName() {
return meta.hasDisplayName(); return this.meta.hasDisplayName();
} }
public String getName() { public String getName() {
return meta.getDisplayName(); return this.meta.getDisplayName();
} }
public ItemBuilder name(String name) { public ItemBuilder name(String name) {
meta.setDisplayName(name); this.meta.setDisplayName(name);
return this; return this;
} }
@ -91,11 +91,11 @@ public class ItemBuilder {
* Lore: * Lore:
*/ */
public boolean hasLore() { public boolean hasLore() {
return meta.hasLore(); return this.meta.hasLore();
} }
public List<String> getLore() { public List<String> getLore() {
return meta.getLore(); return this.meta.getLore();
} }
public ItemBuilder lore(String... lore) { public ItemBuilder lore(String... lore) {
@ -103,7 +103,7 @@ public class ItemBuilder {
} }
public ItemBuilder lore(List<String> lore) { public ItemBuilder lore(List<String> lore) {
meta.setLore(lore); this.meta.setLore(lore);
return this; return this;
} }
@ -111,28 +111,28 @@ public class ItemBuilder {
* Enchantments: * Enchantments:
*/ */
public boolean hasEnchants() { public boolean hasEnchants() {
return meta.hasEnchants(); return this.meta.hasEnchants();
} }
public boolean hasEnchant(Enchantment enchantment) { public boolean hasEnchant(Enchantment enchantment) {
return meta.hasEnchant(enchantment); return this.meta.hasEnchant(enchantment);
} }
public boolean hasConflictingEnchant(Enchantment enchantment) { public boolean hasConflictingEnchant(Enchantment enchantment) {
return meta.hasConflictingEnchant(enchantment); return this.meta.hasConflictingEnchant(enchantment);
} }
public Map<Enchantment, Integer> getEnchants() { public Map<Enchantment, Integer> getEnchants() {
return meta.getEnchants(); return this.meta.getEnchants();
} }
public ItemBuilder enchant(Enchantment enchantment, int level) { public ItemBuilder enchant(Enchantment enchantment, int level) {
meta.addEnchant(enchantment, level, true); this.meta.addEnchant(enchantment, level, true);
return this; return this;
} }
public ItemBuilder removeEnchant(Enchantment enchantment) { public ItemBuilder removeEnchant(Enchantment enchantment) {
meta.removeEnchant(enchantment); this.meta.removeEnchant(enchantment);
return this; return this;
} }
@ -144,20 +144,20 @@ public class ItemBuilder {
* Flags: * Flags:
*/ */
public boolean hasFlag(ItemFlag flag) { public boolean hasFlag(ItemFlag flag) {
return meta.hasItemFlag(flag); return this.meta.hasItemFlag(flag);
} }
public Set<ItemFlag> getFlags() { public Set<ItemFlag> getFlags() {
return meta.getItemFlags(); return this.meta.getItemFlags();
} }
public ItemBuilder addFlags(ItemFlag... flags) { public ItemBuilder addFlags(ItemFlag... flags) {
meta.addItemFlags(flags); this.meta.addItemFlags(flags);
return this; return this;
} }
public ItemBuilder removeFlags(ItemFlag... flags) { public ItemBuilder removeFlags(ItemFlag... flags) {
meta.removeItemFlags(flags); this.meta.removeItemFlags(flags);
return this; return this;
} }
@ -165,16 +165,15 @@ public class ItemBuilder {
* Unbreakability: * Unbreakability:
*/ */
public boolean isUnbreakable() { public boolean isUnbreakable() {
return meta.isUnbreakable(); return this.meta.isUnbreakable();
} }
public ItemBuilder unbreakable() { public ItemBuilder unbreakable() {
return unbreakable(true); return unbreakable(true);
} }
@SuppressWarnings("deprecation")
public ItemBuilder unbreakable(boolean unbreakable) { public ItemBuilder unbreakable(boolean unbreakable) {
meta.setUnbreakable(unbreakable); this.meta.setUnbreakable(unbreakable);
return this; return this;
} }
@ -190,36 +189,36 @@ public class ItemBuilder {
* Banners: * Banners:
*/ */
public DyeColor getBannerBaseColor() { public DyeColor getBannerBaseColor() {
return ((BannerMeta) meta).getBaseColor(); return ((BannerMeta) this.meta).getBaseColor();
} }
public List<Pattern> getBannerPatterns() { public List<Pattern> getBannerPatterns() {
return ((BannerMeta) meta).getPatterns(); return ((BannerMeta) this.meta).getPatterns();
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public ItemBuilder bannerBaseColor(DyeColor color) { public ItemBuilder bannerBaseColor(DyeColor color) {
((BannerMeta) meta).setBaseColor(color); ((BannerMeta) this.meta).setBaseColor(color);
return this; return this;
} }
public ItemBuilder bannerPatterns(List<Pattern> patterns) { public ItemBuilder bannerPatterns(List<Pattern> patterns) {
((BannerMeta) meta).setPatterns(patterns); ((BannerMeta) this.meta).setPatterns(patterns);
return this; return this;
} }
public ItemBuilder bannerPattern(int i, Pattern pattern) { public ItemBuilder bannerPattern(int i, Pattern pattern) {
((BannerMeta) meta).setPattern(i, pattern); ((BannerMeta) this.meta).setPattern(i, pattern);
return this; return this;
} }
public ItemBuilder addBannerPatterns(Pattern pattern) { public ItemBuilder addBannerPatterns(Pattern pattern) {
((BannerMeta) meta).addPattern(pattern); ((BannerMeta) this.meta).addPattern(pattern);
return this; return this;
} }
public ItemBuilder removeBannerPattern(int i) { public ItemBuilder removeBannerPattern(int i) {
((BannerMeta) meta).removePattern(i); ((BannerMeta) this.meta).removePattern(i);
return this; return this;
} }
@ -227,11 +226,11 @@ public class ItemBuilder {
* Leather armor: * Leather armor:
*/ */
public Color getLeatherArmorColor() { public Color getLeatherArmorColor() {
return ((LeatherArmorMeta) meta).getColor(); return ((LeatherArmorMeta) this.meta).getColor();
} }
public ItemBuilder leatherArmorColor(Color color) { public ItemBuilder leatherArmorColor(Color color) {
((LeatherArmorMeta) meta).setColor(color); ((LeatherArmorMeta) this.meta).setColor(color);
return this; return this;
} }
@ -239,23 +238,23 @@ public class ItemBuilder {
* Skulls: * Skulls:
*/ */
public boolean hasSkullOwner() { public boolean hasSkullOwner() {
return ((SkullMeta) meta).hasOwner(); return ((SkullMeta) this.meta).hasOwner();
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public String getSkullOwner() { public String getSkullOwner() {
return ((SkullMeta) meta).getOwner(); return ((SkullMeta) this.meta).getOwner();
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public ItemBuilder skullOwner(String owner) { public ItemBuilder skullOwner(String owner) {
item.setDurability((short) 3); this.item.setDurability((short) 3);
((SkullMeta) meta).setOwner(owner); ((SkullMeta) this.meta).setOwner(owner);
return this; return this;
} }
public ItemBuilder durability(int durability) { public ItemBuilder durability(int durability) {
item.setDurability((short) durability); this.item.setDurability((short) durability);
return this; return this;
} }
@ -263,19 +262,19 @@ public class ItemBuilder {
* Potions: * Potions:
*/ */
public boolean hasPotionEffect(PotionEffectType type) { public boolean hasPotionEffect(PotionEffectType type) {
return ((PotionMeta) meta).hasCustomEffect(type); return ((PotionMeta) this.meta).hasCustomEffect(type);
} }
public boolean hasPotionEffects() { public boolean hasPotionEffects() {
return ((PotionMeta) meta).hasCustomEffects(); return ((PotionMeta) this.meta).hasCustomEffects();
} }
public List<PotionEffect> getPotionEffects() { public List<PotionEffect> getPotionEffects() {
return ((PotionMeta) meta).getCustomEffects(); return ((PotionMeta) this.meta).getCustomEffects();
} }
public ItemBuilder addPotionEffect(PotionEffect effect, boolean overwrite) { public ItemBuilder addPotionEffect(PotionEffect effect, boolean overwrite) {
((PotionMeta) meta).addCustomEffect(effect, overwrite); ((PotionMeta) this.meta).addCustomEffect(effect, overwrite);
return this; return this;
} }
@ -283,7 +282,7 @@ public class ItemBuilder {
* Build the ItemStack. * Build the ItemStack.
*/ */
public ItemStack build() { public ItemStack build() {
item.setItemMeta(meta); this.item.setItemMeta(this.meta);
return item; return this.item;
} }
} }

View File

@ -70,7 +70,6 @@ public class FastInv implements InventoryHolder {
* *
* @param type The type of the menus. * @param type The type of the menus.
* @param title The title of the menus. * @param title The title of the menus.
*
* @throws IllegalStateException if FastInv is not init with FastInv.init(Plugin plugin) * @throws IllegalStateException if FastInv is not init with FastInv.init(Plugin plugin)
*/ */
public FastInv(InventoryType type, String title) { public FastInv(InventoryType type, String title) {
@ -84,9 +83,9 @@ public class FastInv implements InventoryHolder {
runSync(() -> { runSync(() -> {
if (type == InventoryType.CHEST && size > 0) { if (type == InventoryType.CHEST && size > 0) {
inventory = Bukkit.createInventory(this, size, title); this.inventory = Bukkit.createInventory(this, size, title);
} else { } else {
inventory = Bukkit.createInventory(this, type, title); this.inventory = Bukkit.createInventory(this, type, title);
} }
}); });
} }
@ -107,7 +106,6 @@ public class FastInv implements InventoryHolder {
* Add an {@link ItemStack} to the menus. * Add an {@link ItemStack} to the menus.
* *
* @param item The item to add * @param item The item to add
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public FastInv addItem(ItemStack item) { public FastInv addItem(ItemStack item) {
@ -119,12 +117,11 @@ public class FastInv implements InventoryHolder {
* *
* @param item The item to add. * @param item The item to add.
* @param listener The {@link FastInvClickListener} for the item. * @param listener The {@link FastInvClickListener} for the item.
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public FastInv addItem(ItemStack item, FastInvClickListener listener) { public FastInv addItem(ItemStack item, FastInvClickListener listener) {
runSync(() -> { runSync(() -> {
int slot = inventory.firstEmpty(); int slot = this.inventory.firstEmpty();
if (slot >= 0) { if (slot >= 0) {
addItem(slot, item, listener); addItem(slot, item, listener);
} }
@ -135,13 +132,12 @@ public class FastInv implements InventoryHolder {
/** /**
* Add an {@link ItemStack} to the menus on a specific slot. * Add an {@link ItemStack} to the menus on a specific slot.
* *
* @param slot The slot of the item. * @param slot The slot of the item.
* @param item The item to add. * @param itemStack The item to add.
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public FastInv addItem(int slot, ItemStack item) { public FastInv addItem(int slot, ItemStack itemStack) {
return addItem(slot, item, null); return addItem(slot, itemStack, null);
} }
/** /**
@ -149,17 +145,16 @@ public class FastInv implements InventoryHolder {
* *
* @param slot The slot of the item. * @param slot The slot of the item.
* @param itemStack The icon to add. * @param itemStack The icon to add.
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public FastInv addItem(int slot, ItemStack itemStack, FastInvClickListener listener) { public FastInv addItem(int slot, ItemStack itemStack, FastInvClickListener listener) {
runSync(() -> { runSync(() -> {
inventory.setItem(slot, itemStack); this.inventory.setItem(slot, itemStack);
if (listener != null) { if (listener != null) {
itemListeners.put(slot, listener); this.itemListeners.put(slot, listener);
} else { } else {
itemListeners.remove(slot); this.itemListeners.remove(slot);
} }
}); });
@ -169,29 +164,27 @@ public class FastInv implements InventoryHolder {
/** /**
* Add an {@link ItemStack} to the menus on a range of slots. * Add an {@link ItemStack} to the menus on a range of slots.
* *
* @param slotFrom Starting slot to put the item in. * @param slotFrom Starting slot to put the item in.
* @param slotTo Ending slot to put the item in. * @param slotTo Ending slot to put the item in.
* @param item The item to add. * @param itemStack The item to add.
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public FastInv addItem(int slotFrom, int slotTo, ItemStack item) { public FastInv addItem(int slotFrom, int slotTo, ItemStack itemStack) {
return addItem(slotFrom, slotTo, item, null); return addItem(slotFrom, slotTo, itemStack, null);
} }
/** /**
* Add an {@link ItemStack} to the menus on a range of slots with a {@link FastInvClickListener} to handle clicks. * Add an {@link ItemStack} to the menus on a range of slots with a {@link FastInvClickListener} to handle clicks.
* *
* @param slotFrom Starting slot to put the item in. * @param slotFrom Starting slot to put the item in.
* @param slotTo Ending slot to put the item in. * @param slotTo Ending slot to put the item in.
* @param item The item to add. * @param itemStack The item to add.
* @param listener The IconClickListener for the item. * @param listener The IconClickListener for the item.
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public FastInv addItem(int slotFrom, int slotTo, ItemStack item, FastInvClickListener listener) { public FastInv addItem(int slotFrom, int slotTo, ItemStack itemStack, FastInvClickListener listener) {
for (int i = slotFrom; i <= slotTo; i++) { for (int i = slotFrom; i <= slotTo; i++) {
addItem(i, item, listener); addItem(i, itemStack, listener);
} }
return this; return this;
} }
@ -201,7 +194,6 @@ public class FastInv implements InventoryHolder {
* *
* @param slots The slot of the item. * @param slots The slot of the item.
* @param item The item to add. * @param item The item to add.
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public FastInv addItem(int[] slots, ItemStack item) { public FastInv addItem(int[] slots, ItemStack item) {
@ -212,14 +204,13 @@ public class FastInv implements InventoryHolder {
* Add an {@link ItemStack} to the menus on the edges. * Add an {@link ItemStack} to the menus on the edges.
* *
* @param item The item to add. * @param item The item to add.
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public FastInv edge(ItemStack item) { public FastInv edge(ItemStack item) {
int height = inventory.getSize() / 9; int height = this.inventory.getSize() / 9;
addItem(0, 9, item); addItem(0, 9, item);
addItem(inventory.getSize() - 9, inventory.getSize() - 1, item); addItem(this.inventory.getSize() - 9, this.inventory.getSize() - 1, item);
for (int i = 0; i < height; i++) { for (int i = 0; i < height; i++) {
addItem(i * 9, item); addItem(i * 9, item);
@ -235,7 +226,6 @@ public class FastInv implements InventoryHolder {
* @param slots The slots to place the item. * @param slots The slots to place the item.
* @param item The item to add. * @param item The item to add.
* @param listener The IconClickListener for the item. * @param listener The IconClickListener for the item.
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public FastInv addItem(int[] slots, ItemStack item, FastInvClickListener listener) { public FastInv addItem(int[] slots, ItemStack item, FastInvClickListener listener) {
@ -247,8 +237,8 @@ public class FastInv implements InventoryHolder {
public FastInv fill(ItemStack itemStack, FastInvClickListener listener) { public FastInv fill(ItemStack itemStack, FastInvClickListener listener) {
runSync(() -> { runSync(() -> {
for (int i = 0; i < inventory.getSize(); i++) { for (int i = 0; i < this.inventory.getSize(); i++) {
if (inventory.getItem(i) == null) { if (this.inventory.getItem(i) == null) {
addItem(i, itemStack, listener); addItem(i, itemStack, listener);
} }
} }
@ -264,11 +254,10 @@ public class FastInv implements InventoryHolder {
* Add a {@link FastInvCloseListener} to listen on menus close. * Add a {@link FastInvCloseListener} to listen on menus close.
* *
* @param listener The {@link FastInvCloseListener} to add. * @param listener The {@link FastInvCloseListener} to add.
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public FastInv onClose(FastInvCloseListener listener) { public FastInv onClose(FastInvCloseListener listener) {
closeListeners.add(listener); this.closeListeners.add(listener);
return this; return this;
} }
@ -276,21 +265,20 @@ public class FastInv implements InventoryHolder {
* Add a {@link FastInvClickListener} to listen on menus click. * Add a {@link FastInvClickListener} to listen on menus click.
* *
* @param listener The {@link FastInvClickListener} to add. * @param listener The {@link FastInvClickListener} to add.
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public FastInv onClick(FastInvClickListener listener) { public FastInv onClick(FastInvClickListener listener) {
clickListeners.add(listener); this.clickListeners.add(listener);
return this; return this;
} }
public FastInv setDefaultCancel(boolean value) { public FastInv setDefaultCancel(boolean value) {
cancelled = value; this.cancelled = value;
return this; return this;
} }
public boolean getDefaultCancel() { public boolean getDefaultCancel() {
return cancelled; return this.cancelled;
} }
/** /**
@ -298,7 +286,6 @@ public class FastInv implements InventoryHolder {
* *
* @param period Delay between each run. * @param period Delay between each run.
* @param runnable The {@link Runnable} task to run. * @param runnable The {@link Runnable} task to run.
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public FastInv onUpdate(long period, Runnable runnable) { public FastInv onUpdate(long period, Runnable runnable) {
@ -311,11 +298,10 @@ public class FastInv implements InventoryHolder {
* @param delay Ticks to wait before starting the task. * @param delay Ticks to wait before starting the task.
* @param period Delay between each run. * @param period Delay between each run.
* @param runnable The {@link Runnable} task to run. * @param runnable The {@link Runnable} task to run.
*
* @return This FastInv instance, for chaining * @return This FastInv instance, for chaining
*/ */
public FastInv onUpdate(long delay, long period, Runnable runnable) { public FastInv onUpdate(long delay, long period, Runnable runnable) {
tasks.add(Bukkit.getScheduler().runTaskTimer(plugin, runnable, delay, period)); this.tasks.add(Bukkit.getScheduler().runTaskTimer(plugin, runnable, delay, period));
return this; return this;
} }
@ -325,7 +311,7 @@ public class FastInv implements InventoryHolder {
* @param player The player to open the menu. * @param player The player to open the menu.
*/ */
public void open(Player player) { public void open(Player player) {
Bukkit.getScheduler().runTask(plugin, () -> player.openInventory(inventory)); Bukkit.getScheduler().runTask(plugin, () -> player.openInventory(this.inventory));
} }
/** /**
@ -336,7 +322,7 @@ public class FastInv implements InventoryHolder {
public void open(Player... players) { public void open(Player... players) {
Bukkit.getScheduler().runTask(plugin, () -> { Bukkit.getScheduler().runTask(plugin, () -> {
for (Player p : players) { for (Player p : players) {
p.openInventory(inventory); p.openInventory(this.inventory);
} }
}); });
} }
@ -345,8 +331,8 @@ public class FastInv implements InventoryHolder {
* Cancel all tasks. * Cancel all tasks.
*/ */
public void cancelTasks() { public void cancelTasks() {
tasks.forEach(BukkitTask::cancel); this.tasks.forEach(BukkitTask::cancel);
tasks.clear(); this.tasks.clear();
} }
/** /**
@ -388,7 +374,7 @@ public class FastInv implements InventoryHolder {
* @return This associated FastInv instance. * @return This associated FastInv instance.
*/ */
public FastInv getInventory() { public FastInv getInventory() {
return inventory; return this.inventory;
} }
/** /**
@ -397,7 +383,7 @@ public class FastInv implements InventoryHolder {
* @return the player who clicked. * @return the player who clicked.
*/ */
public Player getPlayer() { public Player getPlayer() {
return player; return this.player;
} }
/** /**
@ -406,7 +392,7 @@ public class FastInv implements InventoryHolder {
* @return Whether the event was cancelled. * @return Whether the event was cancelled.
*/ */
public boolean isCancelled() { public boolean isCancelled() {
return cancelled; return this.cancelled;
} }
/** /**
@ -485,7 +471,7 @@ public class FastInv implements InventoryHolder {
*/ */
@Override @Override
public Inventory getInventory() { public Inventory getInventory() {
return inventory; return this.inventory;
} }
private static Listener getListener() { private static Listener getListener() {
@ -549,7 +535,6 @@ public class FastInv implements InventoryHolder {
* Set if the tasks will be cancel on menus close. * Set if the tasks will be cancel on menus close.
* *
* @param cancelTasksOnClose Set if the tasks will be cancel * @param cancelTasksOnClose Set if the tasks will be cancel
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public FastInv setCancelTasksOnClose(boolean cancelTasksOnClose) { public FastInv setCancelTasksOnClose(boolean cancelTasksOnClose) {
@ -560,7 +545,7 @@ public class FastInv implements InventoryHolder {
public void reOpen(Player player) { public void reOpen(Player player) {
player.closeInventory(); player.closeInventory();
refresh(); refresh();
player.openInventory(inventory); player.openInventory(this.inventory);
} }
public void refresh() { public void refresh() {

View File

@ -72,7 +72,6 @@ public class IconInv implements InventoryHolder {
* *
* @param type The type of the menus. * @param type The type of the menus.
* @param title The title of the menus. * @param title The title of the menus.
*
* @throws IllegalStateException if FastInv is not init with FastInv.init(Plugin plugin) * @throws IllegalStateException if FastInv is not init with FastInv.init(Plugin plugin)
*/ */
public IconInv(InventoryType type, String title) { public IconInv(InventoryType type, String title) {
@ -86,9 +85,9 @@ public class IconInv implements InventoryHolder {
runSync(() -> { runSync(() -> {
if (type == InventoryType.CHEST && size > 0) { if (type == InventoryType.CHEST && size > 0) {
inventory = Bukkit.createInventory(this, size, title); this.inventory = Bukkit.createInventory(this, size, title);
} else { } else {
inventory = Bukkit.createInventory(this, type, title); this.inventory = Bukkit.createInventory(this, type, title);
} }
}); });
} }
@ -109,12 +108,11 @@ public class IconInv implements InventoryHolder {
* Add an {@link ItemStack} to the menus with a {@link IconClickListener} to handle clicks. * Add an {@link ItemStack} to the menus with a {@link IconClickListener} to handle clicks.
* *
* @param icon The icon to add. * @param icon The icon to add.
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public IconInv addIcon(Icon icon) { public IconInv addIcon(Icon icon) {
runSync(() -> { runSync(() -> {
int slot = inventory.firstEmpty(); int slot = this.inventory.firstEmpty();
if (slot >= 0) { if (slot >= 0) {
addIcon(slot, icon); addIcon(slot, icon);
} }
@ -127,13 +125,12 @@ public class IconInv implements InventoryHolder {
* *
* @param slot The slot of the item. * @param slot The slot of the item.
* @param icon The icon to add. * @param icon The icon to add.
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public IconInv addIcon(int slot, Icon icon) { public IconInv addIcon(int slot, Icon icon) {
runSync(() -> { runSync(() -> {
inventory.setItem(slot, icon.getItemStack()); this.inventory.setItem(slot, icon.getItemStack());
itemListeners.put(slot, icon); this.itemListeners.put(slot, icon);
}); });
return this; return this;
@ -145,7 +142,6 @@ public class IconInv implements InventoryHolder {
* @param slotFrom Starting slot to put the item in. * @param slotFrom Starting slot to put the item in.
* @param slotTo Ending slot to put the item in. * @param slotTo Ending slot to put the item in.
* @param icon The icon to add. * @param icon The icon to add.
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public IconInv addIcon(int slotFrom, int slotTo, Icon icon) { public IconInv addIcon(int slotFrom, int slotTo, Icon icon) {
@ -159,14 +155,13 @@ public class IconInv implements InventoryHolder {
* Add an {@link ItemStack} to the menus on the edges. * Add an {@link ItemStack} to the menus on the edges.
* *
* @param icon The icon to add. * @param icon The icon to add.
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public IconInv edge(Icon icon) { public IconInv edge(Icon icon) {
int height = inventory.getSize() / 9; int height = this.inventory.getSize() / 9;
addIcon(0, 9, icon); addIcon(0, 9, icon);
addIcon(inventory.getSize() - 9, inventory.getSize() - 1, icon); addIcon(this.inventory.getSize() - 9, this.inventory.getSize() - 1, icon);
for (int i = 0; i < height; i++) { for (int i = 0; i < height; i++) {
addIcon(i * 9, icon); addIcon(i * 9, icon);
@ -181,7 +176,6 @@ public class IconInv implements InventoryHolder {
* *
* @param slots The slots to place the item. * @param slots The slots to place the item.
* @param icon The icon to add. * @param icon The icon to add.
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public IconInv addIcon(int[] slots, Icon icon) { public IconInv addIcon(int[] slots, Icon icon) {
@ -193,8 +187,8 @@ public class IconInv implements InventoryHolder {
public IconInv fill(Icon icon) { public IconInv fill(Icon icon) {
runSync(() -> { runSync(() -> {
for (int i = 0; i < inventory.getSize(); i++) { for (int i = 0; i < this.inventory.getSize(); i++) {
if (inventory.getItem(i) == null) { if (this.inventory.getItem(i) == null) {
addIcon(i, icon); addIcon(i, icon);
} }
} }
@ -218,11 +212,10 @@ public class IconInv implements InventoryHolder {
* Add a {@link IconInvCloseListener} to listen on menus close. * Add a {@link IconInvCloseListener} to listen on menus close.
* *
* @param listener The {@link IconInvCloseListener} to add. * @param listener The {@link IconInvCloseListener} to add.
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public IconInv onClose(IconInvCloseListener listener) { public IconInv onClose(IconInvCloseListener listener) {
closeListeners.add(listener); this.closeListeners.add(listener);
return this; return this;
} }
@ -230,11 +223,10 @@ public class IconInv implements InventoryHolder {
* Add a {@link IconClickListener} to listen on menus click. * Add a {@link IconClickListener} to listen on menus click.
* *
* @param listener The {@link IconClickListener} to add. * @param listener The {@link IconClickListener} to add.
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public IconInv onClick(IconClickListener listener) { public IconInv onClick(IconClickListener listener) {
clickListeners.add(listener); this.clickListeners.add(listener);
return this; return this;
} }
@ -243,7 +235,6 @@ public class IconInv implements InventoryHolder {
* *
* @param period Delay between each run. * @param period Delay between each run.
* @param runnable The {@link Runnable} task to run. * @param runnable The {@link Runnable} task to run.
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public IconInv onUpdate(long period, Runnable runnable) { public IconInv onUpdate(long period, Runnable runnable) {
@ -256,11 +247,10 @@ public class IconInv implements InventoryHolder {
* @param delay Ticks to wait before starting the task. * @param delay Ticks to wait before starting the task.
* @param period Delay between each run. * @param period Delay between each run.
* @param runnable The {@link Runnable} task to run. * @param runnable The {@link Runnable} task to run.
*
* @return This FastInv instance, for chaining * @return This FastInv instance, for chaining
*/ */
public IconInv onUpdate(long delay, long period, Runnable runnable) { public IconInv onUpdate(long delay, long period, Runnable runnable) {
tasks.add(Bukkit.getScheduler().runTaskTimer(plugin, runnable, delay, period)); this.tasks.add(Bukkit.getScheduler().runTaskTimer(plugin, runnable, delay, period));
return this; return this;
} }
@ -270,7 +260,7 @@ public class IconInv implements InventoryHolder {
* @param player The player to open the menu. * @param player The player to open the menu.
*/ */
public void open(Player player) { public void open(Player player) {
Bukkit.getScheduler().runTask(plugin, () -> player.openInventory(inventory)); Bukkit.getScheduler().runTask(plugin, () -> player.openInventory(this.inventory));
} }
/** /**
@ -281,7 +271,7 @@ public class IconInv implements InventoryHolder {
public void open(Player... players) { public void open(Player... players) {
Bukkit.getScheduler().runTask(plugin, () -> { Bukkit.getScheduler().runTask(plugin, () -> {
for (Player p : players) { for (Player p : players) {
p.openInventory(inventory); p.openInventory(this.inventory);
} }
}); });
} }
@ -290,8 +280,8 @@ public class IconInv implements InventoryHolder {
* Cancel all tasks. * Cancel all tasks.
*/ */
public void cancelTasks() { public void cancelTasks() {
tasks.forEach(BukkitTask::cancel); this.tasks.forEach(BukkitTask::cancel);
tasks.clear(); this.tasks.clear();
} }
/** /**
@ -311,7 +301,6 @@ public class IconInv implements InventoryHolder {
* Set if the tasks will be cancel on menus close. * Set if the tasks will be cancel on menus close.
* *
* @param cancelTasksOnClose Set if the tasks will be cancel * @param cancelTasksOnClose Set if the tasks will be cancel
*
* @return This FastInv instance, for chaining. * @return This FastInv instance, for chaining.
*/ */
public IconInv setCancelTasksOnClose(boolean cancelTasksOnClose) { public IconInv setCancelTasksOnClose(boolean cancelTasksOnClose) {
@ -327,7 +316,7 @@ public class IconInv implements InventoryHolder {
void onClose(IconInvCloseEvent event); void onClose(IconInvCloseEvent event);
} }
public static abstract class IconEvent { public abstract static class IconEvent {
private final Player player; private final Player player;
private final IconInv inventory; private final IconInv inventory;
private boolean cancelled; private boolean cancelled;
@ -344,7 +333,7 @@ public class IconInv implements InventoryHolder {
* @return This associated FastInv instance. * @return This associated FastInv instance.
*/ */
public IconInv getInventory() { public IconInv getInventory() {
return inventory; return this.inventory;
} }
/** /**
@ -353,7 +342,7 @@ public class IconInv implements InventoryHolder {
* @return the player who clicked. * @return the player who clicked.
*/ */
public Player getPlayer() { public Player getPlayer() {
return player; return this.player;
} }
/** /**
@ -362,7 +351,7 @@ public class IconInv implements InventoryHolder {
* @return Whether the event was cancelled. * @return Whether the event was cancelled.
*/ */
public boolean isCancelled() { public boolean isCancelled() {
return cancelled; return this.cancelled;
} }
/** /**
@ -434,11 +423,11 @@ public class IconInv implements InventoryHolder {
} }
public boolean getDefaultCancel() { public boolean getDefaultCancel() {
return cancelled; return this.cancelled;
} }
public IconInv setDefaultCancel(boolean value) { public IconInv setDefaultCancel(boolean value) {
cancelled = value; this.cancelled = value;
return this; return this;
} }
@ -449,7 +438,7 @@ public class IconInv implements InventoryHolder {
*/ */
@Override @Override
public Inventory getInventory() { public Inventory getInventory() {
return inventory; return this.inventory;
} }
private static Listener getListener() { private static Listener getListener() {

View File

@ -41,16 +41,16 @@ public abstract class PlayersMenu extends FastInv {
@Override @Override
public void refresh() { public void refresh() {
fill(null); fill(null);
final int startIndex = page * (players.size() - 1); final int startIndex = this.page * (this.players.size() - 1);
IntStream.rangeClosed(0, SLOTS).forEach(slot -> { IntStream.rangeClosed(0, this.SLOTS).forEach(slot -> {
int index = startIndex + slot; int index = startIndex + slot;
if (index >= players.size()) { if (index >= this.players.size()) {
return; return;
} }
Player player = players.get(index); Player player = this.players.get(index);
ItemStack itemStack = CompatibleMaterial.PLAYER_HEAD.getItem(); ItemStack itemStack = CompatibleMaterial.PLAYER_HEAD.getItem();
@ -64,42 +64,43 @@ public abstract class PlayersMenu extends FastInv {
skullMeta.setDisplayName(YELLOW + player.getName()); skullMeta.setDisplayName(YELLOW + player.getName());
itemStack.setItemMeta(skullMeta); itemStack.setItemMeta(skullMeta);
addItem(slot, itemStack, event -> playerConsumer.accept(event.getPlayer(), player)); addItem(slot, itemStack, event -> this.playerConsumer.accept(event.getPlayer(), player));
}); });
if (players.size() / SLOTS > page) { if (this.players.size() / this.SLOTS > this.page) {
addItem(26, new ItemBuilder(ARROW) addItem(26, new ItemBuilder(ARROW)
.name(YELLOW + "Next") .name(YELLOW + "Next")
.lore(GRAY + "Click to go to the next page of players") .lore(GRAY + "Click to go to the next page of players")
.build(), event -> { .build(), event -> {
page++; this.page++;
refresh(); refresh();
}); });
} else { } else {
addItem(26, null); addItem(26, null);
} }
if (page > 0) { if (this.page > 0) {
addItem(18, new ItemBuilder(ARROW) addItem(18, new ItemBuilder(ARROW)
.name(YELLOW + "Previous") .name(YELLOW + "Previous")
.lore(GRAY + "Click to go to the previous page of players") .lore(GRAY + "Click to go to the previous page of players")
.build(), event -> { .build(), event -> {
page--; this.page--;
refresh(); refresh();
}); });
} else { } else {
addItem(18, new ItemBuilder(BARRIER) addItem(18, new ItemBuilder(BARRIER)
.name(YELLOW + "Return") .name(YELLOW + "Return")
.lore(GRAY + "Return to the action menu") .lore(GRAY + "Return to the action menu")
.addGlow().build(), event -> new ActionMenu(instance, voucher).open(event.getPlayer())); .addGlow().build(), event -> new ActionMenu(this.instance, this.voucher).open(event.getPlayer()));
} }
if (instance.getConfig().getBoolean("Interface.Fill Interfaces With Glass")) { if (this.instance.getConfig().getBoolean("Interface.Fill Interfaces With Glass")) {
ItemStack fillItem = CompatibleMaterial.GRAY_STAINED_GLASS_PANE.getItem(); ItemStack fillItem = CompatibleMaterial.GRAY_STAINED_GLASS_PANE.getItem();
IntStream.rangeClosed(SLOTS + 1, 26).forEach(slot -> { IntStream.rangeClosed(this.SLOTS + 1, 26).forEach(slot -> {
if (getInventory().getItem(slot) == null) if (getInventory().getItem(slot) == null) {
addItem(slot, new ItemBuilder(fillItem).name(ChatColor.RESET.toString()).build()); addItem(slot, new ItemBuilder(fillItem).name(ChatColor.RESET.toString()).build());
}
}); });
} }
} }

View File

@ -9,8 +9,9 @@ public class Icon {
private final ItemStack itemStack; private final ItemStack itemStack;
private final Consumer<IconClickEvent> consumer; private final Consumer<IconClickEvent> consumer;
public Icon(ItemStack itemStack) { public Icon(ItemStack item) {
this(itemStack, event -> { }); this(item, event -> {
});
} }
public Icon(ItemStack item, Consumer<IconClickEvent> consumer) { public Icon(ItemStack item, Consumer<IconClickEvent> consumer) {
@ -18,7 +19,11 @@ public class Icon {
this.consumer = consumer; this.consumer = consumer;
} }
public void run(IconClickEvent e) { consumer.accept(e); } public void run(IconClickEvent e) {
this.consumer.accept(e);
}
public ItemStack getItemStack() { return itemStack; } public ItemStack getItemStack() {
return this.itemStack;
}
} }

View File

@ -38,12 +38,12 @@ public class StringIcon extends Icon {
.lore(GRAY + "Current: " + WHITE + current, GRAY + "Right click to edit", GRAY + "Left click to clear").build(), current, consumer, predicate, noLeft); .lore(GRAY + "Current: " + WHITE + current, GRAY + "Right click to edit", GRAY + "Left click to clear").build(), current, consumer, predicate, noLeft);
} }
public StringIcon(EpicVouchers instance, ItemStack itemStack, String current, BiConsumer<Player, String> consumer) { public StringIcon(EpicVouchers instance, ItemStack item, String current, BiConsumer<Player, String> consumer) {
this(instance, itemStack, current, consumer, s -> true, false); this(instance, item, current, consumer, s -> true, false);
} }
public StringIcon(EpicVouchers instance, ItemStack itemStack, String current, BiConsumer<Player, String> consumer, Predicate<String> predicate, boolean noLeft) { public StringIcon(EpicVouchers instance, ItemStack item, String current, BiConsumer<Player, String> consumer, Predicate<String> predicate, boolean noLeft) {
super(itemStack, event -> { super(item, event -> {
if (!noLeft && event.getClickType() == ClickType.LEFT) { if (!noLeft && event.getClickType() == ClickType.LEFT) {
consumer.accept(event.getPlayer(), ""); consumer.accept(event.getPlayer(), "");
event.getPlayer().sendMessage(TextUtils.formatText("&7Successfully cleared&7.")); event.getPlayer().sendMessage(TextUtils.formatText("&7Successfully cleared&7."));

View File

@ -8,18 +8,19 @@ import org.bukkit.Material;
import java.util.function.Consumer; import java.util.function.Consumer;
public class ToggleableIcon extends Icon { public class ToggleableIcon extends Icon {
private Consumer<IconClickEvent> consumer; private final Consumer<IconClickEvent> consumer;
public ToggleableIcon(String displayname, Consumer<IconClickEvent> consumer, boolean state) { public ToggleableIcon(String displayname, Consumer<IconClickEvent> consumer, boolean state) {
super(new ItemBuilder(Material.PAPER) super(new ItemBuilder(Material.PAPER)
.name(ChatColor.YELLOW + displayname) .name(ChatColor.YELLOW + displayname)
.lore(state ? ChatColor.GREEN + "ENABLED" : ChatColor.RED + "DISABLED") .lore(state ? ChatColor.GREEN + "ENABLED" : ChatColor.RED + "DISABLED")
.build(), event -> { }); .build(), event -> {
});
this.consumer = consumer; this.consumer = consumer;
} }
@Override @Override
public void run(IconClickEvent event) { public void run(IconClickEvent e) {
consumer.accept(event); this.consumer.accept(e);
} }
} }

View File

@ -85,8 +85,8 @@ public class PlayerInteractListener implements Listener {
/** /**
* @deprecated This is a legacy method that is only used for backwards compatibility * @deprecated This is a legacy method that is only used for backwards compatibility
* with vouchers that were created before the voucher key was stored in NBT. * with vouchers that were created before the voucher key was stored in NBT.
* Some checks in here don't even look like they make sense or look redundant... Hard to touch this. * Some checks in here don't even look like they make sense or look redundant... Hard to touch this.
*/ */
@Deprecated @Deprecated
private Voucher findVoucherForLegacyItem(ItemStack item, Collection<Voucher> allVouchers) { private Voucher findVoucherForLegacyItem(ItemStack item, Collection<Voucher> allVouchers) {

View File

@ -131,6 +131,6 @@ public class VoucherEditorMenu extends IconInv {
} }
private void reopen(Player player) { private void reopen(Player player) {
new VoucherEditorMenu(instance, voucher).open(player); new VoucherEditorMenu(this.instance, this.voucher).open(player);
} }
} }

View File

@ -34,7 +34,7 @@ public class VoucherMenu extends IconInv {
.lore(TextUtils.formatText("&eCreate a new voucher with set id.")).build(), event -> { .lore(TextUtils.formatText("&eCreate a new voucher with set id.")).build(), event -> {
AnvilGui gui = new AnvilGui(event.getPlayer()); AnvilGui gui = new AnvilGui(event.getPlayer());
gui.setTitle("Insert id"); gui.setTitle("Insert id");
gui.setAction(aevent -> { gui.setAction(aEvent -> {
final String msg = gui.getInputText().trim(); final String msg = gui.getInputText().trim();
if (instance.getVoucherManager().getVoucher(msg) != null) { if (instance.getVoucherManager().getVoucher(msg) != null) {
event.getPlayer().sendMessage(TextUtils.formatText("&cAlready a voucher registered with the id: " + msg)); event.getPlayer().sendMessage(TextUtils.formatText("&cAlready a voucher registered with the id: " + msg));

View File

@ -32,6 +32,5 @@ public class SoundsMenu extends IconInv {
.name(YELLOW + "Return") .name(YELLOW + "Return")
.lore(GRAY + "Return to the editor") .lore(GRAY + "Return to the editor")
.build(), event -> new VoucherEditorMenu(instance, voucher).open(event.getPlayer())); .build(), event -> new VoucherEditorMenu(instance, voucher).open(event.getPlayer()));
} }
} }

View File

@ -5,11 +5,8 @@ import com.songoda.core.configuration.ConfigSetting;
import com.songoda.epicvouchers.EpicVouchers; import com.songoda.epicvouchers.EpicVouchers;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
/**
* Created by songo on 6/4/2017.
*/
public class Settings implements Listener { public class Settings implements Listener {
static final Config config = EpicVouchers.getInstance().getCoreConfig(); static final Config config = EpicVouchers.getPlugin(EpicVouchers.class).getCoreConfig();
public static final ConfigSetting FILL_GLASS = new ConfigSetting(config, "Interface.Fill Interfaces With Glass", true); public static final ConfigSetting FILL_GLASS = new ConfigSetting(config, "Interface.Fill Interfaces With Glass", true);
public static final ConfigSetting COOLDOWN_DELAY = new ConfigSetting(config, "Main.Cooldown Delay", 10); public static final ConfigSetting COOLDOWN_DELAY = new ConfigSetting(config, "Main.Cooldown Delay", 10);

View File

@ -25,16 +25,16 @@ public class CachedSet<K> {
clearStale(); clearStale();
} }
return this.cache.computeIfPresent(obj, (k, aLong) -> System.currentTimeMillis()) != null; return this.cache.computeIfPresent(obj, (key, aLong) -> System.currentTimeMillis()) != null;
} }
public void clearStale() { public void clearStale() {
this.cache.entrySet().removeIf(entry -> System.currentTimeMillis() - entry.getValue() >= ttl); this.cache.entrySet().removeIf(entry -> System.currentTimeMillis() - entry.getValue() >= this.ttl);
this.lastClear = System.currentTimeMillis(); this.lastClear = System.currentTimeMillis();
} }
private boolean shouldClear() { private boolean shouldClear() {
return !this.cache.isEmpty() && System.currentTimeMillis() - lastClear > ttl; return !this.cache.isEmpty() && System.currentTimeMillis() - this.lastClear > this.ttl;
} }
} }

View File

@ -19,7 +19,9 @@ public class Pair<K, V> implements Serializable {
* *
* @return key for this pair * @return key for this pair
*/ */
public String getKey() { return key; } public String getKey() {
return this.key;
}
/** /**
* Value of this this <code>Pair</code>. * Value of this this <code>Pair</code>.
@ -31,7 +33,9 @@ public class Pair<K, V> implements Serializable {
* *
* @return value for this pair * @return value for this pair
*/ */
public String getValue() { return value; } public String getValue() {
return this.value;
}
/** /**
* Creates a new pair * Creates a new pair
@ -54,7 +58,7 @@ public class Pair<K, V> implements Serializable {
*/ */
@Override @Override
public String toString() { public String toString() {
return key + "=" + value; return this.key + "=" + this.value;
} }
/** /**
@ -72,7 +76,7 @@ public class Pair<K, V> implements Serializable {
// these two parameters: // these two parameters:
// name: a value: aa // name: a value: aa
// name: aa value: a // name: aa value: a
return key.hashCode() * 13 + (value == null ? 0 : value.hashCode()); return this.key.hashCode() * 13 + (this.value == null ? 0 : this.value.hashCode());
} }
/** /**
@ -88,17 +92,19 @@ public class Pair<K, V> implements Serializable {
* *
* @param o the <code>Object</code> to test for * @param o the <code>Object</code> to test for
* equality with this <code>Pair</code> * equality with this <code>Pair</code>
*
* @return <code>true</code> if the given <code>Object</code> is * @return <code>true</code> if the given <code>Object</code> is
* equal to this <code>Pair</code> else <code>false</code> * equal to this <code>Pair</code> else <code>false</code>
*/ */
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) {
if (o == null || getClass() != o.getClass()) return false; return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Pair<?, ?> pair = (Pair<?, ?>) o; Pair<?, ?> pair = (Pair<?, ?>) o;
return Objects.equals(key, pair.key) && Objects.equals(value, pair.value); return Objects.equals(this.key, pair.key) && Objects.equals(this.value, pair.value);
} }
} }

View File

@ -8,10 +8,10 @@ public class ThreadSync {
private final AtomicReference<Boolean> waiting = new AtomicReference<>(true); private final AtomicReference<Boolean> waiting = new AtomicReference<>(true);
public void waitForRelease() { public void waitForRelease() {
synchronized (syncObj) { synchronized (this.syncObj) {
while (waiting.get()) { while (this.waiting.get()) {
try { try {
syncObj.wait(); this.syncObj.wait();
} catch (Exception ignore) { } catch (Exception ignore) {
} }
} }
@ -19,13 +19,13 @@ public class ThreadSync {
} }
public void release() { public void release() {
synchronized (syncObj) { synchronized (this.syncObj) {
waiting.set(false); this.waiting.set(false);
syncObj.notifyAll(); this.syncObj.notifyAll();
} }
} }
public void reset() { public void reset() {
waiting.set(true); this.waiting.set(true);
} }
} }

View File

@ -21,14 +21,14 @@ public class CoolDownManager {
} }
if (voucher.getCoolDown() != 0) { if (voucher.getCoolDown() != 0) {
entries.put(uuid, System.currentTimeMillis() + voucher.getCoolDown() * 1000L); this.entries.put(uuid, System.currentTimeMillis() + voucher.getCoolDown() * 1000L);
} else { } else {
entries.put(uuid, System.currentTimeMillis() + instance.getConfig().getInt("Main.Cooldown Delay") * 1000L); this.entries.put(uuid, System.currentTimeMillis() + this.instance.getConfig().getInt("Main.Cooldown Delay") * 1000L);
} }
} }
public boolean isOnCoolDown(UUID uuid) { public boolean isOnCoolDown(UUID uuid) {
Long time = entries.get(uuid); Long time = this.entries.get(uuid);
if (time == null) { if (time == null) {
return false; return false;
@ -38,12 +38,12 @@ public class CoolDownManager {
return true; return true;
} }
entries.remove(uuid); this.entries.remove(uuid);
return false; return false;
} }
public long getTime(UUID uuid) { public long getTime(UUID uuid) {
Long time = entries.get(uuid); Long time = this.entries.get(uuid);
if (time == null) { if (time == null) {
return 0L; return 0L;

View File

@ -81,32 +81,32 @@ public class Voucher {
} }
public ItemStack toItemStack(int amount) { public ItemStack toItemStack(int amount) {
ItemStack item = itemStack == null ? new ItemStack(material, amount, data) : itemStack; ItemStack item = this.itemStack == null ? new ItemStack(this.material, amount, this.data) : this.itemStack;
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
if (meta == null) { if (meta == null) {
meta = Bukkit.getItemFactory().getItemMeta(material); meta = Bukkit.getItemFactory().getItemMeta(this.material);
} }
if (!name.isEmpty()) { if (!this.name.isEmpty()) {
meta.setDisplayName(TextUtils.formatText(name)); meta.setDisplayName(TextUtils.formatText(this.name));
} }
if (lore != null) { if (this.lore != null) {
meta.setLore(getLore(true)); meta.setLore(getLore(true));
} }
if (glow) { if (this.glow) {
meta.addEnchant(Enchantment.DURABILITY, 1, false); meta.addEnchant(Enchantment.DURABILITY, 1, false);
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
} }
if (hideAttributes) { if (this.hideAttributes) {
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE); meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
} }
if (unbreakable) { if (this.unbreakable) {
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)) { if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)) {
meta.setUnbreakable(true); meta.setUnbreakable(true);
item.setItemMeta(meta); item.setItemMeta(meta);
@ -119,18 +119,18 @@ public class Voucher {
} }
} }
if (texture != null && !texture.isEmpty() && CompatibleMaterial.PLAYER_HEAD.getMaterial() == material) { if (this.texture != null && !this.texture.isEmpty() && CompatibleMaterial.PLAYER_HEAD.getMaterial() == this.material) {
item = ItemUtils.getCustomHead(texture); item = ItemUtils.getCustomHead(this.texture);
} }
NBTItem nbtItem = new NBTItem(item); NBTItem nbtItem = new NBTItem(item);
nbtItem.setString("epicvouchers:voucher", key); nbtItem.setString("epicvouchers:voucher", this.key);
return nbtItem.getItem(); return nbtItem.getItem();
} }
public String getName(boolean applyFormatting) { public String getName(boolean applyFormatting) {
return applyFormatting ? TextUtils.formatText(name) : name; return applyFormatting ? TextUtils.formatText(this.name) : this.name;
} }
public List<String> getLore(boolean applyFormatting) { public List<String> getLore(boolean applyFormatting) {
@ -172,23 +172,23 @@ public class Voucher {
public void saveSetting(String key, List<String> list) { public void saveSetting(String key, List<String> list) {
switch (key) { switch (key) {
case "Commands": case "Commands":
commands = list; this.commands = list;
break; break;
case "Broadcasts": case "Broadcasts":
broadcasts = list; this.broadcasts = list;
break; break;
case "Messages": case "Messages":
messages = list; this.messages = list;
break; break;
case "Lore": case "Lore":
lore = list; this.lore = list;
break; break;
} }
} }
@Override @Override
public String toString() { public String toString() {
return key; return this.key;
} }
public void giveAll(CommandSender sender, int amount) { public void giveAll(CommandSender sender, int amount) {
@ -196,13 +196,13 @@ public class Voucher {
} }
public void give(CommandSender sender, List<Player> players, int amount) { public void give(CommandSender sender, List<Player> players, int amount) {
String giveMessage = instance.getLocale().getMessage("command.give.send") String giveMessage = this.instance.getLocale().getMessage("command.give.send")
.processPlaceholder("player", players.size() == 1 ? players.get(0).getName() : "everyone") .processPlaceholder("player", players.size() == 1 ? players.get(0).getName() : "everyone")
.processPlaceholder("voucher", getName(true)) .processPlaceholder("voucher", getName(true))
.processPlaceholder("amount", String.valueOf(amount)).getPrefixedMessage(); .processPlaceholder("amount", String.valueOf(amount)).getPrefixedMessage();
for (Player player : players) { for (Player player : players) {
String receiveMessage = instance.getLocale().getMessage("command.give.receive") String receiveMessage = this.instance.getLocale().getMessage("command.give.receive")
.processPlaceholder("voucher", getName(true)) .processPlaceholder("voucher", getName(true))
.processPlaceholder("player", player.getName()) .processPlaceholder("player", player.getName())
.processPlaceholder("amount", String.valueOf(amount)).getPrefixedMessage(); .processPlaceholder("amount", String.valueOf(amount)).getPrefixedMessage();
@ -211,7 +211,7 @@ public class Voucher {
Bukkit.getServer().getPluginManager().callEvent(event); Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
instance.getLocale().getMessage("command.give.cancelled").sendPrefixedMessage(sender); this.instance.getLocale().getMessage("command.give.cancelled").sendPrefixedMessage(sender);
continue; continue;
} }
@ -232,7 +232,7 @@ public class Voucher {
} }
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
instance.getVoucherExecutor().redeemVoucher(player, this, player.getItemInHand(), false, null); this.instance.getVoucherExecutor().redeemVoucher(player, this, player.getItemInHand(), false, null);
} }
} }
} }
@ -241,45 +241,46 @@ public class Voucher {
Player player = event.getPlayer(); Player player = event.getPlayer();
// does the player have permission to redeem this voucher? // does the player have permission to redeem this voucher?
if (!permission.isEmpty() && !player.hasPermission(permission)) { if (!this.permission.isEmpty() && !player.hasPermission(this.permission)) {
player.sendMessage(instance.getLocale().getMessage("event.general.nopermission").getPrefixedMessage()); player.sendMessage(this.instance.getLocale().getMessage("event.general.nopermission").getPrefixedMessage());
return; return;
} }
UUID uuid = player.getUniqueId(); UUID uuid = player.getUniqueId();
if (instance.getCoolDowns().isOnCoolDown(uuid)) { if (this.instance.getCoolDowns().isOnCoolDown(uuid)) {
instance.getLocale().getMessage("event.general.cooldown") this.instance.getLocale().getMessage("event.general.cooldown")
.processPlaceholder("time", instance.getCoolDowns().getTime(uuid)) .processPlaceholder("time", this.instance.getCoolDowns().getTime(uuid))
.processPlaceholder("voucher", getName(true)) .processPlaceholder("voucher", getName(true))
.sendPrefixedMessage(player); .sendPrefixedMessage(player);
return; return;
} }
if (confirm) { if (this.confirm) {
new ConfirmMenu(instance, new ConfirmMenu(this.instance,
() -> instance.getVoucherExecutor().redeemVoucher(player, this, event.getItem(), true, event), () -> this.instance.getVoucherExecutor().redeemVoucher(player, this, event.getItem(), true, event),
() -> { }) () -> {
})
.open(player); .open(player);
} else { } else {
instance.getVoucherExecutor().redeemVoucher(player, this, event.getItem(), true, event); this.instance.getVoucherExecutor().redeemVoucher(player, this, event.getItem(), true, event);
} }
} }
public String getTexture() { public String getTexture() {
return texture; return this.texture;
} }
public String getActionBar() { public String getActionBar() {
return TextUtils.formatText(actionBar); return TextUtils.formatText(this.actionBar);
} }
public String getSubTitle() { public String getSubTitle() {
return TextUtils.formatText(subTitle); return TextUtils.formatText(this.subTitle);
} }
public String getTitle() { public String getTitle() {
return TextUtils.formatText(title); return TextUtils.formatText(this.title);
} }
public String getKey() { public String getKey() {

View File

@ -51,7 +51,7 @@ public class VoucherExecutor {
if (!duplication) { if (!duplication) {
if (manual) { if (manual) {
instance.getCoolDowns().addCoolDown(player.getUniqueId(), voucher); this.instance.getCoolDowns().addCoolDown(player.getUniqueId(), voucher);
if (voucher.isRemoveItem()) { if (voucher.isRemoveItem()) {
if (item.getAmount() <= 1) { if (item.getAmount() <= 1) {
item = null; item = null;
@ -116,17 +116,14 @@ public class VoucherExecutor {
String delayCommand = StringUtils.substringBetween(command, "[", "]"); String delayCommand = StringUtils.substringBetween(command, "[", "]");
int delay = Integer.parseInt(delayCommand.split("-", 2)[1]); int delay = Integer.parseInt(delayCommand.split("-", 2)[1]);
final String finalCommand = command.replace("[" + delayCommand + "]", ""); final String finalCommand = command.replace("[" + delayCommand + "]", "");
final ItemStack heldItem = item; Bukkit.getScheduler().scheduleSyncDelayedTask(this.instance, () -> runCommand(finalCommand, player), 20L * delay);
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
runCommand(finalCommand, player);
}, 20 * delay);
} else { } else {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command); Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
} }
} }
if (voucher.getActionBar() != null && !voucher.getActionBar().isEmpty()) { if (voucher.getActionBar() != null && !voucher.getActionBar().isEmpty()) {
String actionbar = voucher.getActionBar().replaceAll("%player%", name).replaceAll("%voucher%", voucher.getName(true)); String actionbar = voucher.getActionBar().replaceAll("%player%", name).replaceAll("%voucher%", voucher.getName(true));
instance.getLocale().newMessage(actionbar).sendActionBar(player); this.instance.getLocale().newMessage(actionbar).sendActionBar(player);
} }
if (voucher.getTitle() != null && !voucher.getTitle().isEmpty()) { if (voucher.getTitle() != null && !voucher.getTitle().isEmpty()) {
@ -166,14 +163,14 @@ public class VoucherExecutor {
player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(effect), duration, amplifier)); player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(effect), duration, amplifier));
} }
instance.getLogger().log(Level.INFO, player.getName() + " has successfully redeemed the voucher " + voucher.getKey() + "."); this.instance.getLogger().log(Level.INFO, player.getName() + " has successfully redeemed the voucher " + voucher.getKey() + ".");
instance.getConnections().saveRedeem(player, voucher.getName(true)); this.instance.getConnections().saveRedeem(player, voucher.getName(true));
} else { } else {
instance.getLogger().log(Level.WARNING, player.getName() + " has failed to duplicate the voucher " + voucher.getKey() + "."); this.instance.getLogger().log(Level.WARNING, player.getName() + " has failed to duplicate the voucher " + voucher.getKey() + ".");
} }
} catch (Exception error) { } catch (Exception error) {
instance.getLogger().log(Level.SEVERE, "Failed to redeem the voucher " + voucher.getKey() + " for the player " + player.getName() + "."); this.instance.getLogger().log(Level.SEVERE, "Failed to redeem the voucher " + voucher.getKey() + " for the player " + player.getName() + ".");
instance.getLogger().log(Level.SEVERE, error.getMessage()); this.instance.getLogger().log(Level.SEVERE, error.getMessage());
error.printStackTrace(); error.printStackTrace();
} }
} }

View File

@ -8,22 +8,22 @@ public class VoucherManager {
private final Map<String, Voucher> registeredVouchers = new HashMap<>(); private final Map<String, Voucher> registeredVouchers = new HashMap<>();
public Voucher addVoucher(Voucher voucher) { public Voucher addVoucher(Voucher voucher) {
return registeredVouchers.put(voucher.getKey(), voucher); return this.registeredVouchers.put(voucher.getKey(), voucher);
} }
public Voucher removeVoucher(Voucher voucher) { public Voucher removeVoucher(Voucher voucher) {
return registeredVouchers.remove(voucher); return this.registeredVouchers.remove(voucher);
} }
public Voucher getVoucher(String key) { public Voucher getVoucher(String key) {
return registeredVouchers.get(key); return this.registeredVouchers.get(key);
} }
public Collection<Voucher> getVouchers() { public Collection<Voucher> getVouchers() {
return registeredVouchers.values(); return this.registeredVouchers.values();
} }
public void clearVouchers() { public void clearVouchers() {
registeredVouchers.clear(); this.registeredVouchers.clear();
} }
} }

View File

@ -12,5 +12,5 @@ commands:
epicvouchers: epicvouchers:
description: View information on this plugin. description: View information on this plugin.
default: true default: true
aliases: [ev] aliases: [ ev ]
usage: /ev usage: /ev