mirror of
https://github.com/songoda/EpicVouchers.git
synced 2024-12-23 00:57:40 +01:00
Fixed some vouchers not working & added delay commands
This commit is contained in:
parent
74c7c43735
commit
85f758c1b3
@ -31,19 +31,17 @@ public class PlayerInteractListener implements Listener {
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
for (Voucher voucher : instance.getVouchers().values()) {
|
||||
final ItemStack voucherItem = voucher.getItemStack();
|
||||
|
||||
final ItemStack voucherItem = voucher.toItemStack();
|
||||
// does the item they're holding match this voucher?
|
||||
if (voucherItem != null && !voucher.getItemStack().isSimilar(item))
|
||||
continue;
|
||||
else if (item.getType() != voucher.getMaterial() || item.getDurability() != voucher.getData())
|
||||
continue;
|
||||
|
||||
if (voucherItem != null && !voucherItem.isSimilar(item)) continue;
|
||||
else if (item.getType() != voucher.getMaterial() || item.getDurability() != voucher.getData()) continue;
|
||||
else {
|
||||
// material matches - verify the name + lore
|
||||
final ItemMeta meta = item.getItemMeta();
|
||||
if (meta == null || !meta.hasDisplayName() || !meta.hasLore()
|
||||
if (meta == null || !meta.hasDisplayName()
|
||||
|| !ChatColor.stripColor(meta.getDisplayName()).equals(ChatColor.stripColor(voucher.getName(true)))
|
||||
|| !meta.getLore().equals(voucher.getLore(true)))
|
||||
|| (meta.hasLore() && !meta.getLore().equals(voucher.getLore(true))))
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -143,12 +143,12 @@ 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)))
|
||||
.processPlaceholder("voucher", getName(true))
|
||||
.processPlaceholder("amount", String.valueOf(amount)).getPrefixedMessage();
|
||||
|
||||
for (Player player : players) {
|
||||
String receiveMessage = instance.getLocale().getMessage("command.give.receive")
|
||||
.processPlaceholder("voucher", Matcher.quoteReplacement(getName(true)))
|
||||
.processPlaceholder("voucher", getName(true))
|
||||
.processPlaceholder("player", player.getName())
|
||||
.processPlaceholder("amount", String.valueOf(amount)).getPrefixedMessage();
|
||||
|
||||
|
@ -8,6 +8,7 @@ import com.songoda.epicvouchers.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
@ -113,9 +114,14 @@ public class VoucherExecutor {
|
||||
} else if (command.startsWith("[chat]")) {
|
||||
command = command.replace("[chat]", "");
|
||||
player.chat(command);
|
||||
} else if (command.startsWith("[delay]")) {
|
||||
//command = command.replace("[delay]", "");
|
||||
throw new UnsupportedOperationException("delay is not supported yet");
|
||||
} else if (command.startsWith("[delay")) {
|
||||
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);
|
||||
} else {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
}
|
||||
@ -162,7 +168,31 @@ public class VoucherExecutor {
|
||||
} catch (Exception error) {
|
||||
instance.getLogger().log(Level.SEVERE, Methods.format("&cFailed to redeem the voucher " + voucher.getKey() + " for the player " + player.getName() + "."));
|
||||
instance.getLogger().log(Level.SEVERE, error.getMessage());
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void runCommand(String command, Player player) {
|
||||
if (command.startsWith("[player]")) {
|
||||
command = command.replace("[player]", "");
|
||||
player.performCommand(command);
|
||||
} else if (command.startsWith("[op]")) {
|
||||
command = command.replace("[op]", "");
|
||||
boolean wasOp = player.isOp();
|
||||
PlayerCommandListener.addCommand(player.getUniqueId(), command);
|
||||
player.setOp(true);
|
||||
player.performCommand(command);
|
||||
|
||||
if (!wasOp) {
|
||||
player.setOp(false);
|
||||
}
|
||||
|
||||
PlayerCommandListener.removeCommand(player.getUniqueId());
|
||||
} else if (command.startsWith("[chat]")) {
|
||||
command = command.replace("[chat]", "");
|
||||
player.chat(command);
|
||||
} else {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user