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;
public class EpicVouchers extends SongodaPlugin {
private static EpicVouchers INSTANCE;
private final GuiManager guiManager = new GuiManager(this);
private CommandManager commandManager;
private VoucherManager voucherManager;
@ -48,18 +46,21 @@ public class EpicVouchers extends SongodaPlugin {
private VoucherExecutor voucherExecutor;
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() {
return INSTANCE;
return getPlugin(EpicVouchers.class);
}
@Override
public void onPluginLoad() {
INSTANCE = this;
}
@Override
public void onPluginDisable() {
connections.closeMySQL();
this.connections.closeMySQL();
saveVouchers();
}
@ -96,7 +97,7 @@ public class EpicVouchers extends SongodaPlugin {
PluginManager manager = Bukkit.getServer().getPluginManager();
// Listeners
guiManager.init();
this.guiManager.init();
manager.registerEvents(new PlayerInteractListener(this), this);
manager.registerEvents(new PlayerCommandListener(), this);
}
@ -107,13 +108,13 @@ public class EpicVouchers extends SongodaPlugin {
saveResource("vouchers.yml", false);
}
synchronized (vouchersConfig) {
vouchersConfig.load();
synchronized (this.vouchersConfig) {
this.vouchersConfig.load();
}
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
// 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() {
synchronized (vouchersConfig) {
voucherManager.clearVouchers();
synchronized (this.vouchersConfig) {
this.voucherManager.clearVouchers();
if (vouchersConfig.contains("vouchers")) {
for (String key : vouchersConfig.getConfigurationSection("vouchers").getKeys(false)) {
if (this.vouchersConfig.contains("vouchers")) {
for (String key : this.vouchersConfig.getConfigurationSection("vouchers").getKeys(false)) {
Voucher voucher = new Voucher(key, this);
ConfigurationSection cs = vouchersConfig.getConfigurationSection("vouchers." + key);
ConfigurationSection cs = this.vouchersConfig.getConfigurationSection("vouchers." + key);
Material material;
String stringMaterial = cs.getString("material");
@ -144,7 +145,9 @@ public class EpicVouchers extends SongodaPlugin {
material = Material.PAPER;
} else {
material = Material.matchMaterial(stringMaterial);
if (material == null) material = Material.PAPER;
if (material == null) {
material = Material.PAPER;
}
}
voucher.setPermission(cs.getString("permission", ""))
@ -178,7 +181,7 @@ public class EpicVouchers extends SongodaPlugin {
.setEffectAmplifier(cs.getInt("effects.amplifier"))
.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) {
new Thread(() -> {
try {
synchronized (vouchersConfig) {
Collection<Voucher> voucherList = voucherManager.getVouchers();
synchronized (this.vouchersConfig) {
Collection<Voucher> voucherList = this.voucherManager.getVouchers();
ConfigurationSection cfgSec = vouchersConfig.getConfigurationSection("vouchers");
ConfigurationSection cfgSec = this.vouchersConfig.getConfigurationSection("vouchers");
if (cfgSec != null) {
for (String voucherName : cfgSec.getKeys(false)) {
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) {
String prefix = "vouchers." + voucher.getKey() + ".";
vouchersConfig.set(prefix + "permission", voucher.getPermission());
vouchersConfig.set(prefix + "material", voucher.getMaterial().name());
vouchersConfig.set(prefix + "data", voucher.getData());
vouchersConfig.set(prefix + "name", voucher.getName());
vouchersConfig.set(prefix + "lore", voucher.getLore());
vouchersConfig.set(prefix + "texture", voucher.getTexture());
vouchersConfig.set(prefix + "glow", voucher.isGlow());
vouchersConfig.set(prefix + "confirm", voucher.isConfirm());
vouchersConfig.set(prefix + "unbreakable", voucher.isUnbreakable());
vouchersConfig.set(prefix + "hide-attributes", voucher.isHideAttributes());
vouchersConfig.set(prefix + "remove-item", voucher.isRemoveItem());
vouchersConfig.set(prefix + "heal-player", voucher.isHealPlayer());
vouchersConfig.set(prefix + "smite-effect", voucher.isSmiteEffect());
vouchersConfig.set(prefix + "coolDown", voucher.getCoolDown());
vouchersConfig.set(prefix + "broadcasts", voucher.getBroadcasts());
vouchersConfig.set(prefix + "messages", voucher.getMessages());
vouchersConfig.set(prefix + "commands", voucher.getCommands());
vouchersConfig.set(prefix + "actionbar", voucher.getActionBar());
vouchersConfig.set(prefix + "titles.title", voucher.getTitle());
vouchersConfig.set(prefix + "titles.subtitle", voucher.getSubTitle());
vouchersConfig.set(prefix + "titles.fade-in", voucher.getTitleFadeIn());
vouchersConfig.set(prefix + "titles.stay", voucher.getTitleStay());
vouchersConfig.set(prefix + "titles.fade-out", voucher.getTitleFadeOut());
vouchersConfig.set(prefix + "sounds.sound", voucher.getSound());
vouchersConfig.set(prefix + "sounds.pitch", voucher.getSoundPitch());
vouchersConfig.set(prefix + "particles.particle", voucher.getParticle());
vouchersConfig.set(prefix + "particles.amount", voucher.getParticleAmount());
vouchersConfig.set(prefix + "effects.effect", voucher.getEffect());
vouchersConfig.set(prefix + "effects.amplifier", voucher.getEffectAmplifier());
vouchersConfig.set(prefix + "itemstack", voucher.getItemStack());
this.vouchersConfig.set(prefix + "permission", voucher.getPermission());
this.vouchersConfig.set(prefix + "material", voucher.getMaterial().name());
this.vouchersConfig.set(prefix + "data", voucher.getData());
this.vouchersConfig.set(prefix + "name", voucher.getName());
this.vouchersConfig.set(prefix + "lore", voucher.getLore());
this.vouchersConfig.set(prefix + "texture", voucher.getTexture());
this.vouchersConfig.set(prefix + "glow", voucher.isGlow());
this.vouchersConfig.set(prefix + "confirm", voucher.isConfirm());
this.vouchersConfig.set(prefix + "unbreakable", voucher.isUnbreakable());
this.vouchersConfig.set(prefix + "hide-attributes", voucher.isHideAttributes());
this.vouchersConfig.set(prefix + "remove-item", voucher.isRemoveItem());
this.vouchersConfig.set(prefix + "heal-player", voucher.isHealPlayer());
this.vouchersConfig.set(prefix + "smite-effect", voucher.isSmiteEffect());
this.vouchersConfig.set(prefix + "coolDown", voucher.getCoolDown());
this.vouchersConfig.set(prefix + "broadcasts", voucher.getBroadcasts());
this.vouchersConfig.set(prefix + "messages", voucher.getMessages());
this.vouchersConfig.set(prefix + "commands", voucher.getCommands());
this.vouchersConfig.set(prefix + "actionbar", voucher.getActionBar());
this.vouchersConfig.set(prefix + "titles.title", voucher.getTitle());
this.vouchersConfig.set(prefix + "titles.subtitle", voucher.getSubTitle());
this.vouchersConfig.set(prefix + "titles.fade-in", voucher.getTitleFadeIn());
this.vouchersConfig.set(prefix + "titles.stay", voucher.getTitleStay());
this.vouchersConfig.set(prefix + "titles.fade-out", voucher.getTitleFadeOut());
this.vouchersConfig.set(prefix + "sounds.sound", voucher.getSound());
this.vouchersConfig.set(prefix + "sounds.pitch", voucher.getSoundPitch());
this.vouchersConfig.set(prefix + "particles.particle", voucher.getParticle());
this.vouchersConfig.set(prefix + "particles.amount", voucher.getParticleAmount());
this.vouchersConfig.set(prefix + "effects.effect", voucher.getEffect());
this.vouchersConfig.set(prefix + "effects.amplifier", voucher.getEffectAmplifier());
this.vouchersConfig.set(prefix + "itemstack", voucher.getItemStack());
}
vouchersConfig.saveChanges();
this.vouchersConfig.saveChanges();
callback.accept(null);
}
@ -260,8 +263,8 @@ public class EpicVouchers extends SongodaPlugin {
@Override
public void onConfigReload() {
synchronized (vouchersConfig) {
vouchersConfig.load();
synchronized (this.vouchersConfig) {
this.vouchersConfig.load();
}
loadVouchersFromFile();
@ -272,7 +275,7 @@ public class EpicVouchers extends SongodaPlugin {
@Override
public List<Config> getExtraConfig() {
return Collections.singletonList(vouchersConfig);
return Collections.singletonList(this.vouchersConfig);
}
public Connections getConnections() {
@ -288,14 +291,14 @@ public class EpicVouchers extends SongodaPlugin {
}
public CommandManager getCommandManager() {
return commandManager;
return this.commandManager;
}
public VoucherManager getVoucherManager() {
return voucherManager;
return this.voucherManager;
}
public GuiManager getGuiManager() {
return guiManager;
return this.guiManager;
}
}

View File

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

View File

@ -11,17 +11,17 @@ public class CommandEpicVouchers extends AbstractCommand {
final EpicVouchers instance;
public CommandEpicVouchers(EpicVouchers instance) {
super(false, "EpicVouchers");
super(CommandType.CONSOLE_OK, "EpicVouchers");
this.instance = instance;
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
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);
for (AbstractCommand command : instance.getCommandManager().getAllCommands()) {
for (AbstractCommand command : this.instance.getCommandManager().getAllCommands()) {
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
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;
public CommandForce(EpicVouchers instance) {
super(false, "force");
super(CommandType.CONSOLE_OK, "force");
this.instance = instance;
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length != 3)
if (args.length != 3) {
return ReturnType.SYNTAX_ERROR;
}
Player player = Bukkit.getPlayer(args[0]);
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;
}
Voucher voucher = instance.getVoucherManager().getVoucher(args[1]);
Voucher voucher = this.instance.getVoucherManager().getVoucher(args[1]);
if (voucher == null) {
sender.sendMessage("Unknown voucher...");
return ReturnType.FAILURE;
}
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("voucher", voucher.getName(true))
.processPlaceholder("amount", args[2].trim())
@ -54,7 +55,7 @@ public class CommandForce extends AbstractCommand {
result.add(online.getName());
}
} else if (args.length == 2) {
for (Voucher voucher : instance.getVoucherManager().getVouchers()) {
for (Voucher voucher : this.instance.getVoucherManager().getVouchers()) {
result.add(voucher.getKey());
}
} else if (args.length == 3) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,7 +7,7 @@ import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
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 String voucher;
@ -24,35 +24,35 @@ public class ForceRedeemEvent extends Event implements Cancellable {
}
public Player getPlayer() {
return player;
return this.player;
}
public String getVoucher() {
return voucher;
return this.voucher;
}
public int getAmount() {
return amount;
return this.amount;
}
public CommandSender getSender() {
return sender;
return this.sender;
}
public boolean isCancelled() {
return cancelled;
return this.cancelled;
}
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
@Override
public HandlerList getHandlers() {
return handlers;
return HANDLER_LIST;
}
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;
public class VoucherReceiveEvent 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 String voucher;
@ -28,39 +27,39 @@ public class VoucherReceiveEvent extends Event implements Cancellable {
}
public Player getPlayer() {
return player;
return this.player;
}
public String getVoucher() {
return voucher;
return this.voucher;
}
public ItemStack getItem() {
return item;
return this.item;
}
public int getAmount() {
return amount;
return this.amount;
}
public CommandSender getSender() {
return sender;
return this.sender;
}
public boolean isCancelled() {
return cancelled;
return this.cancelled;
}
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
return HANDLER_LIST;
}
}
public static HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

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

View File

@ -19,17 +19,17 @@ public class Connections {
}
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;
}
try {
String mysqlIP = instance.getConfig().getString("Database.IP");
String mysqlPort = instance.getConfig().getString("Database.PORT");
String mysqlDatabase = instance.getConfig().getString("Database.Database Name");
String mysqlUsername = instance.getConfig().getString("Database.Username");
String mysqlPassword = instance.getConfig().getString("Database.Password");
String mysqlIP = this.instance.getConfig().getString("Database.IP");
String mysqlPort = this.instance.getConfig().getString("Database.PORT");
String mysqlDatabase = this.instance.getConfig().getString("Database.Database Name");
String mysqlUsername = this.instance.getConfig().getString("Database.Username");
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."));
} catch (Exception error) {
System.out.println(TextUtils.formatText("&cFailed to create a connection with MySQL."));
@ -38,11 +38,11 @@ public class Connections {
}
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;
}
try {
connection.close();
this.connection.close();
System.out.println(TextUtils.formatText("&fSuccessfully closed the MySQL connection."));
} catch (Exception error) {
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) {
if (!instance.getConfig().getBoolean("Database.Activate Mysql Support") || connection == null) {
if (!this.instance.getConfig().getBoolean("Database.Activate Mysql Support") || this.connection == null) {
return;
}
Timestamp stamp = new Timestamp(System.currentTimeMillis());
Date date = new Date(stamp.getTime());
String time = date.toString();
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("INSERT INTO redeems VALUES (default, '" + player.getName() + "', '" + voucher + "', '" + time + "');");
statement.close();

View File

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

View File

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

View File

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

View File

@ -41,16 +41,16 @@ public abstract class PlayersMenu extends FastInv {
@Override
public void refresh() {
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;
if (index >= players.size()) {
if (index >= this.players.size()) {
return;
}
Player player = players.get(index);
Player player = this.players.get(index);
ItemStack itemStack = CompatibleMaterial.PLAYER_HEAD.getItem();
@ -64,42 +64,43 @@ public abstract class PlayersMenu extends FastInv {
skullMeta.setDisplayName(YELLOW + player.getName());
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)
.name(YELLOW + "Next")
.lore(GRAY + "Click to go to the next page of players")
.build(), event -> {
page++;
this.page++;
refresh();
});
} else {
addItem(26, null);
}
if (page > 0) {
if (this.page > 0) {
addItem(18, new ItemBuilder(ARROW)
.name(YELLOW + "Previous")
.lore(GRAY + "Click to go to the previous page of players")
.build(), event -> {
page--;
this.page--;
refresh();
});
} else {
addItem(18, new ItemBuilder(BARRIER)
.name(YELLOW + "Return")
.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();
IntStream.rangeClosed(SLOTS + 1, 26).forEach(slot -> {
if (getInventory().getItem(slot) == null)
IntStream.rangeClosed(this.SLOTS + 1, 26).forEach(slot -> {
if (getInventory().getItem(slot) == null) {
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 Consumer<IconClickEvent> consumer;
public Icon(ItemStack itemStack) {
this(itemStack, event -> { });
public Icon(ItemStack item) {
this(item, event -> {
});
}
public Icon(ItemStack item, Consumer<IconClickEvent> consumer) {
@ -18,7 +19,11 @@ public class Icon {
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);
}
public StringIcon(EpicVouchers instance, ItemStack itemStack, String current, BiConsumer<Player, String> consumer) {
this(instance, itemStack, current, consumer, s -> true, false);
public StringIcon(EpicVouchers instance, ItemStack item, String current, BiConsumer<Player, String> consumer) {
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) {
super(itemStack, event -> {
public StringIcon(EpicVouchers instance, ItemStack item, String current, BiConsumer<Player, String> consumer, Predicate<String> predicate, boolean noLeft) {
super(item, event -> {
if (!noLeft && event.getClickType() == ClickType.LEFT) {
consumer.accept(event.getPlayer(), "");
event.getPlayer().sendMessage(TextUtils.formatText("&7Successfully cleared&7."));

View File

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

View File

@ -131,6 +131,6 @@ public class VoucherEditorMenu extends IconInv {
}
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 -> {
AnvilGui gui = new AnvilGui(event.getPlayer());
gui.setTitle("Insert id");
gui.setAction(aevent -> {
gui.setAction(aEvent -> {
final String msg = gui.getInputText().trim();
if (instance.getVoucherManager().getVoucher(msg) != null) {
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")
.lore(GRAY + "Return to the editor")
.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 org.bukkit.event.Listener;
/**
* Created by songo on 6/4/2017.
*/
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 COOLDOWN_DELAY = new ConfigSetting(config, "Main.Cooldown Delay", 10);

View File

@ -25,16 +25,16 @@ public class CachedSet<K> {
clearStale();
}
return this.cache.computeIfPresent(obj, (k, aLong) -> System.currentTimeMillis()) != null;
return this.cache.computeIfPresent(obj, (key, aLong) -> System.currentTimeMillis()) != null;
}
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();
}
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
*/
public String getKey() { return key; }
public String getKey() {
return this.key;
}
/**
* Value of this this <code>Pair</code>.
@ -31,7 +33,9 @@ public class Pair<K, V> implements Serializable {
*
* @return value for this pair
*/
public String getValue() { return value; }
public String getValue() {
return this.value;
}
/**
* Creates a new pair
@ -54,7 +58,7 @@ public class Pair<K, V> implements Serializable {
*/
@Override
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:
// name: a value: aa
// 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
* equality with this <code>Pair</code>
*
* @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
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
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);
public void waitForRelease() {
synchronized (syncObj) {
while (waiting.get()) {
synchronized (this.syncObj) {
while (this.waiting.get()) {
try {
syncObj.wait();
this.syncObj.wait();
} catch (Exception ignore) {
}
}
@ -19,13 +19,13 @@ public class ThreadSync {
}
public void release() {
synchronized (syncObj) {
waiting.set(false);
syncObj.notifyAll();
synchronized (this.syncObj) {
this.waiting.set(false);
this.syncObj.notifyAll();
}
}
public void reset() {
waiting.set(true);
this.waiting.set(true);
}
}

View File

@ -21,14 +21,14 @@ public class CoolDownManager {
}
if (voucher.getCoolDown() != 0) {
entries.put(uuid, System.currentTimeMillis() + voucher.getCoolDown() * 1000L);
this.entries.put(uuid, System.currentTimeMillis() + voucher.getCoolDown() * 1000L);
} 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) {
Long time = entries.get(uuid);
Long time = this.entries.get(uuid);
if (time == null) {
return false;
@ -38,12 +38,12 @@ public class CoolDownManager {
return true;
}
entries.remove(uuid);
this.entries.remove(uuid);
return false;
}
public long getTime(UUID uuid) {
Long time = entries.get(uuid);
Long time = this.entries.get(uuid);
if (time == null) {
return 0L;

View File

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

View File

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

View File

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

View File

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