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,8 +106,16 @@ 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);

View File

@ -52,4 +52,8 @@ public class ForceRedeemEvent extends Event implements Cancellable {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -59,4 +59,8 @@ public class VoucherReceiveEvent extends Event implements Cancellable {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -52,4 +52,8 @@ public class VoucherRedeemEvent extends Event implements Cancellable {
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();
}
}