Vouchers will no longer mix up lore and messages.

Fixed some formatting issues.
This commit is contained in:
Brianna O'Keefe 2018-10-29 16:16:26 -04:00
parent aeeb77797b
commit 3788b72f62
7 changed files with 29 additions and 27 deletions

View File

@ -149,8 +149,8 @@ public class EpicVouchers extends JavaPlugin {
cs.set("permission", voucher.getPermission());
cs.set("material", voucher.getMaterial().name());
cs.set("data", voucher.getData());
cs.set("name", voucher.getName());
cs.set("lore", voucher.getLore());
cs.set("name", voucher.getName(false));
cs.set("lore", voucher.getLore(false));
cs.set("glow", voucher.isGlow());
cs.set("confirm", voucher.isConfirm());
cs.set("unbreakable", voucher.isUnbreakable());

View File

@ -36,7 +36,7 @@ public class CommandForce extends AbstractCommand {
output = "everyone";
for (Player player : Bukkit.getOnlinePlayers()) {
if (player != sender) {
ForceRedeemEvent event = new ForceRedeemEvent(player, voucher.getName(), amount, sender);
ForceRedeemEvent event = new ForceRedeemEvent(player, voucher.getName(true), amount, sender);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return ReturnType.FAILURE;
@ -48,7 +48,7 @@ public class CommandForce extends AbstractCommand {
}
} else {
Player player = Bukkit.getPlayer(args[1]);
ForceRedeemEvent event = new ForceRedeemEvent(player, voucher.getName(), amount, sender);
ForceRedeemEvent event = new ForceRedeemEvent(player, voucher.getName(true), amount, sender);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return ReturnType.FAILURE;
@ -58,7 +58,7 @@ public class CommandForce extends AbstractCommand {
VoucherExecutor.redeemVoucher(player, voucher, player.getItemInHand(), false);
}
}
String message = instance.getLocale().getMessage("command.force.send", output, voucher.getName(), String.valueOf(amount));
String message = instance.getLocale().getMessage("command.force.send", output, voucher.getName(true), String.valueOf(amount));
sender.sendMessage(message);
} catch (Exception error) {
sender.sendMessage(instance.getLocale().getMessage("command.error.notnumber"));

View File

@ -33,12 +33,12 @@ public class CommandGive extends AbstractCommand {
int amount = Integer.parseInt(args[3]);
ItemStack item = voucher.toItemStack(amount);
String output;
receivemessage = receivemessage.replaceAll("%voucher%", voucher.getName());
receivemessage = receivemessage.replaceAll("%voucher%", voucher.getName(true));
receivemessage = receivemessage.replaceAll("%amount%", String.valueOf(amount));
if (args[1].equalsIgnoreCase("everyone")) {
for (Player player : Bukkit.getOnlinePlayers()) {
if (player != sender) {
VoucherReceiveEvent event = new VoucherReceiveEvent(player, voucher.getName(), item, amount, sender);
VoucherReceiveEvent event = new VoucherReceiveEvent(player, voucher.getName(true), item, amount, sender);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return ReturnType.FAILURE;
@ -52,7 +52,7 @@ public class CommandGive extends AbstractCommand {
} else {
Player player = Bukkit.getPlayer(args[1]);
receivemessage = receivemessage.replaceAll("%player%", player.getName());
VoucherReceiveEvent event = new VoucherReceiveEvent(player, voucher.getName(), item, amount, sender);
VoucherReceiveEvent event = new VoucherReceiveEvent(player, voucher.getName(true), item, amount, sender);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return ReturnType.FAILURE;
@ -63,7 +63,7 @@ public class CommandGive extends AbstractCommand {
output = player.getName();
}
givemessage = givemessage.replaceAll("%player%", output);
givemessage = givemessage.replaceAll("%voucher%", voucher.getName());
givemessage = givemessage.replaceAll("%voucher%", voucher.getName(true));
givemessage = givemessage.replaceAll("%amount%", String.valueOf(amount));
sender.sendMessage(givemessage);
} catch (Exception error) {

View File

@ -71,7 +71,7 @@ public class VoucherEditor implements Listener {
title = title.replaceAll("%voucher%", voucher.getKey());
Inventory editormenu = Bukkit.createInventory(null, 27, title);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(Methods.formatText(voucher.getName()));
meta.setDisplayName(Methods.formatText(voucher.getName(true)));
item.setItemMeta(meta);
editormenu.setItem(13, item);
@ -137,7 +137,7 @@ public class VoucherEditor implements Listener {
continue;
}
ItemMeta meta = item.getItemMeta();
if (!meta.hasLore() || !meta.getLore().equals(voucher.getLore())) {
if (!meta.hasLore() || !meta.getLore().equals(voucher.getLore(true))) {
continue;
}
Player player = (Player) event.getWhoClicked();
@ -171,7 +171,7 @@ public class VoucherEditor implements Listener {
player.getInventory().addItem(editor.get(player.getUniqueId()).toItemStack());
player.updateInventory();
String message = instance.getLocale().getMessage("interface.editvoucher.recivemessage");
message = message.replaceAll("%voucher%", editor.get(player.getUniqueId()).getName());
message = message.replaceAll("%voucher%", editor.get(player.getUniqueId()).getName(true));
player.sendMessage(message);
} else if (meta.getDisplayName().equals(instance.getLocale().getMessage("interface.editvoucher.backtitle"))) {
openMenu(player);

View File

@ -36,7 +36,7 @@ public class ClickListener implements Listener {
}
ItemMeta meta = item.getItemMeta();
if (!meta.hasDisplayName() || !meta.getDisplayName().equals(voucher.getName()) || !meta.getLore().equals(voucher.getLore())) {
if (!meta.hasDisplayName() || !meta.getDisplayName().equals(voucher.getName(true)) || !meta.getLore().equals(voucher.getLore(true))) {
continue;
}
UUID uuid = player.getUniqueId();
@ -48,7 +48,7 @@ public class ClickListener implements Listener {
}
event.setCancelled(true);
} else {
String message = instance.getLocale().getMessage("event.general.cooldown", String.valueOf(instance.getCooldowns().getEntries().get(uuid) + 1), voucher.getName());
String message = instance.getLocale().getMessage("event.general.cooldown", String.valueOf(instance.getCooldowns().getEntries().get(uuid) + 1), voucher.getName(true));
player.sendMessage(message);
}
}

View File

@ -63,7 +63,7 @@ public class Voucher {
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(Methods.formatText(name));
if (lore != null) {
meta.setLore(getLore());
meta.setLore(getLore(true));
}
if (glow) {
meta.addEnchant(Enchantment.DURABILITY, 1, false);
@ -108,7 +108,8 @@ public class Voucher {
this.data = data;
}
public String getName() {
public String getName(boolean applyFormatting) {
if (!applyFormatting) return name;
return Methods.formatText(name);
}
@ -116,7 +117,8 @@ public class Voucher {
this.name = name;
}
public List<String> getLore() {
public List<String> getLore(boolean applyFormatting) {
if (!applyFormatting) return lore;
List<String> itemLore = new ArrayList<>();
for (String line : lore) {
itemLore.add(Methods.formatText(line));
@ -214,9 +216,9 @@ public class Voucher {
}
public List<String> getMessages(boolean applyFormatting) {
if (!applyFormatting) return lore;
if (!applyFormatting) return messages;
List<String> itemMessages = new ArrayList<>();
for (String line : lore) {
for (String line : messages) {
itemMessages.add(Methods.formatText(line));
}
return itemMessages;

View File

@ -20,7 +20,7 @@ public class VoucherExecutor {
public static void redeemVoucher(Player player, Voucher voucher, ItemStack item, boolean manual) {
EpicVouchers instance = EpicVouchers.getInstance();
try {
VoucherRedeemEvent event = new VoucherRedeemEvent(player, voucher.getName(), item, manual);
VoucherRedeemEvent event = new VoucherRedeemEvent(player, voucher.getName(true), item, manual);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
@ -55,19 +55,19 @@ public class VoucherExecutor {
String name = player.getName();
for (String broadcast : voucher.getBroadcasts(true)) {
broadcast = broadcast.replaceAll("%player%", name);
broadcast = broadcast.replaceAll("%voucher%", voucher.getName());
broadcast = broadcast.replaceAll("%voucher%", voucher.getName(true));
for (Player everyone : Bukkit.getOnlinePlayers()) {
everyone.sendMessage(broadcast);
}
}
for (String message : voucher.getMessages(true)) {
message = message.replaceAll("%player%", name);
message = message.replaceAll("%voucher%", voucher.getName());
message = message.replaceAll("%voucher%", voucher.getName(true));
player.sendMessage(message);
}
for (String command : voucher.getCommands()) {
command = command.replaceAll("%player%", name);
command = command.replaceAll("%voucher%", voucher.getName());
command = command.replaceAll("%voucher%", voucher.getName(true));
if (command.startsWith("[player]")) {
command = command.replace("[player]", "");
player.performCommand(command);
@ -93,14 +93,14 @@ public class VoucherExecutor {
}
String actionbar = voucher.getActionBar();
actionbar = actionbar.replaceAll("%player%", name);
actionbar = actionbar.replaceAll("%voucher%", voucher.getName());
actionbar = actionbar.replaceAll("%voucher%", voucher.getName(true));
Bountiful.sendActionBar(player, actionbar);
String title = voucher.getTitle();
title = title.replaceAll("%player%", name);
title = title.replaceAll("%voucher%", voucher.getName());
title = title.replaceAll("%voucher%", voucher.getName(true));
String subtitle = voucher.getSubTitle();
subtitle = subtitle.replaceAll("%player%", name);
subtitle = subtitle.replaceAll("%voucher%", voucher.getName());
subtitle = subtitle.replaceAll("%voucher%", voucher.getName(true));
int fadein = voucher.getTitleFadeIn();
int stay = voucher.getTitleStay();
int fadeout = voucher.getTitleFadeOut();
@ -121,7 +121,7 @@ public class VoucherExecutor {
player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(effect), duration, amplifier));
}
System.out.println(Methods.formatText("&f" + player.getName() + " has successfully redeemed the voucher " + voucher.getKey() + "."));
instance.getConnections().saveRedeem(player, voucher.getName());
instance.getConnections().saveRedeem(player, voucher.getName(true));
} else {
System.out.println(Methods.formatText("&c" + player.getName() + " has failed to duplicate the voucher " + voucher.getKey() + "."));
}