Merge branch 'development' into 'development'

Optimization and more.

See merge request Songoda/epicvouchers!16
This commit is contained in:
Jacob Scott 2019-09-17 10:10:20 +00:00
commit e5b519fd7d
7 changed files with 143 additions and 121 deletions

View File

@ -55,7 +55,7 @@ public class EpicVouchers extends JavaPlugin {
// Setup language
new Locale(this, "en_US");
this.locale = Locale.getLocale(getConfig().getString("System.Language Mode"));
this.locale = Locale.getLocale(getConfig().getString("System.Language Mode", "en_US"));
//Running Songoda Updater
Plugin plugin = new Plugin(this, 25);
@ -106,9 +106,17 @@ public class EpicVouchers extends JavaPlugin {
key = key.toLowerCase();
Voucher voucher = new Voucher(key, this);
ConfigurationSection cs = vouchersFile.getConfig().getConfigurationSection("vouchers." + key);
Material material = cs.getString("material") == null || cs.getString("material").equals("") ? Material.PAPER :
Material.matchMaterial(cs.getString("material")) == null ? Material.PAPER : Material.matchMaterial(cs.getString("material"));
Material material;
String stringMaterial = cs.getString("material");
if (stringMaterial == null || stringMaterial.isEmpty()) {
material = Material.PAPER;
} else {
material = Material.matchMaterial(stringMaterial);
if(material == null) material = Material.PAPER;
}
voucher.setPermission(cs.getString("permission", ""));
voucher.setMaterial(material);
voucher.setData((short) cs.getInt("data", 0));

View File

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

View File

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

View File

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

View File

@ -28,11 +28,13 @@ public class CoolDownManager {
}
public boolean isOnCoolDown(UUID uuid) {
if(!entries.containsKey(uuid)) {
Long time = entries.get(uuid);
if (time == null) {
return false;
}
if(entries.get(uuid) >= System.currentTimeMillis()) {
if (time >= System.currentTimeMillis()) {
return true;
}
@ -41,10 +43,12 @@ public class CoolDownManager {
}
public long getTime(UUID uuid) {
if(!entries.containsKey(uuid)) {
Long time = entries.get(uuid);
if (time == null) {
return 0L;
}
return (entries.get(uuid) - System.currentTimeMillis()) / 1000;
return (time - System.currentTimeMillis()) / 1000;
}
}

View File

@ -141,7 +141,6 @@ public class Voucher {
}
public void give(CommandSender sender, List<Player> players, int amount) {
String giveMessage = instance.getLocale().getMessage("command.give.send")
.processPlaceholder("player", players.size() == 1 ? players.get(0).getName() : "everyone")
.processPlaceholder("voucher", Matcher.quoteReplacement(getName(true)))

View File

@ -45,7 +45,7 @@ public class VoucherExecutor {
} catch (Exception | Error ignore) {
}
if (player.getInventory().getItem(slot) != null && !player.getInventory().getItem(slot).isSimilar(item)) {
if(!item.isSimilar(player.getInventory().getItem(slot))) {
duplication = true;
}
}
@ -54,13 +54,12 @@ public class VoucherExecutor {
if (manual) {
instance.getCoolDowns().addCoolDown(player.getUniqueId(), voucher);
if (voucher.isRemoveItem()) {
ItemStack clone = item.clone();
if (clone.getAmount() <= 1) {
clone = null;
if (item.getAmount() <= 1) {
item = null;
} else {
clone.setAmount(clone.getAmount() - 1);
item.setAmount(item.getAmount() - 1);
}
player.getInventory().setItem(slot, clone);
player.getInventory().setItem(slot, item);
player.updateInventory();
}
}