From d325c187d844e0bd1d1d4652da4e704edfdd230f Mon Sep 17 00:00:00 2001 From: BadBones69 Date: Thu, 21 May 2020 03:54:38 -0400 Subject: [PATCH] Switched to replace method to fix NPE from #107 --- .../me/badbones69/crazyauctions/Methods.java | 10 +++++----- .../crazyauctions/api/Messages.java | 6 +++--- .../crazyauctions/controllers/GUI.java | 20 +++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/java/me/badbones69/crazyauctions/Methods.java b/src/main/java/me/badbones69/crazyauctions/Methods.java index 7bc0b78..74ac664 100644 --- a/src/main/java/me/badbones69/crazyauctions/Methods.java +++ b/src/main/java/me/badbones69/crazyauctions/Methods.java @@ -175,7 +175,7 @@ public class Methods { public static Integer getVersion() { String ver = Bukkit.getServer().getClass().getPackage().getName(); ver = ver.substring(ver.lastIndexOf('.') + 1); - ver = ver.replaceAll("_", "").replaceAll("R", "").replaceAll("v", ""); + ver = ver.replace("_", "").replace("R", "").replace("v", ""); return Integer.parseInt(ver); } @@ -344,16 +344,16 @@ public class Methods { Calendar cal = Calendar.getInstance(); for (String i : time.split(" ")) { if (i.contains("D") || i.contains("d")) { - cal.add(Calendar.DATE, Integer.parseInt(i.replaceAll("D", "").replaceAll("d", ""))); + cal.add(Calendar.DATE, Integer.parseInt(i.replace("D", "").replace("d", ""))); } if (i.contains("H") || i.contains("h")) { - cal.add(Calendar.HOUR, Integer.parseInt(i.replaceAll("H", "").replaceAll("h", ""))); + cal.add(Calendar.HOUR, Integer.parseInt(i.replace("H", "").replace("h", ""))); } if (i.contains("M") || i.contains("m")) { - cal.add(Calendar.MINUTE, Integer.parseInt(i.replaceAll("M", "").replaceAll("m", ""))); + cal.add(Calendar.MINUTE, Integer.parseInt(i.replace("M", "").replace("m", ""))); } if (i.contains("S") || i.contains("s")) { - cal.add(Calendar.SECOND, Integer.parseInt(i.replaceAll("S", "").replaceAll("s", ""))); + cal.add(Calendar.SECOND, Integer.parseInt(i.replace("S", "").replace("s", ""))); } } return cal.getTimeInMillis(); diff --git a/src/main/java/me/badbones69/crazyauctions/api/Messages.java b/src/main/java/me/badbones69/crazyauctions/api/Messages.java index 6fd619b..203a7db 100644 --- a/src/main/java/me/badbones69/crazyauctions/api/Messages.java +++ b/src/main/java/me/badbones69/crazyauctions/api/Messages.java @@ -84,7 +84,7 @@ public enum Messages { message += Methods.color(m) + "\n"; } for (String ph : placeholders.keySet()) { - message = Methods.color(message.replaceAll(ph, placeholders.get(ph))).replaceAll(ph, placeholders.get(ph).toLowerCase()); + message = Methods.color(message.replace(ph, placeholders.get(ph))).replace(ph, placeholders.get(ph).toLowerCase()); } return message; } @@ -139,7 +139,7 @@ public enum Messages { } for (String ph : placeholders.keySet()) { if (message.contains(ph)) { - message = message.replaceAll(ph, placeholders.get(ph)).replaceAll(ph, placeholders.get(ph).toLowerCase()); + message = message.replace(ph, placeholders.get(ph)).replace(ph, placeholders.get(ph).toLowerCase()); } } } @@ -178,7 +178,7 @@ public enum Messages { } for (String ph : placeholders.keySet()) { if (message.contains(ph)) { - message = message.replaceAll(ph, placeholders.get(ph)).replaceAll(ph, placeholders.get(ph).toLowerCase()); + message = message.replace(ph, placeholders.get(ph)).replace(ph, placeholders.get(ph).toLowerCase()); } } } diff --git a/src/main/java/me/badbones69/crazyauctions/controllers/GUI.java b/src/main/java/me/badbones69/crazyauctions/controllers/GUI.java index 58172a9..3089f29 100644 --- a/src/main/java/me/badbones69/crazyauctions/controllers/GUI.java +++ b/src/main/java/me/badbones69/crazyauctions/controllers/GUI.java @@ -62,7 +62,7 @@ public class GUI implements Listener { String seller = data.getString("Items." + i + ".Seller"); String topbidder = data.getString("Items." + i + ".TopBidder"); for (String l : config.getStringList("Settings.GUISettings.Bidding")) { - lore.add(l.replaceAll("%TopBid%", Methods.getPrice(i, false)).replaceAll("%topbid%", Methods.getPrice(i, false)).replaceAll("%Seller%", seller).replaceAll("%seller%", seller).replaceAll("%TopBidder%", topbidder).replaceAll("%topbidder%", topbidder).replaceAll("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replaceAll("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire")))); + lore.add(l.replace("%TopBid%", Methods.getPrice(i, false)).replace("%topbid%", Methods.getPrice(i, false)).replace("%Seller%", seller).replace("%seller%", seller).replace("%TopBidder%", topbidder).replace("%topbidder%", topbidder).replace("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire")))); } items.add(Methods.addLore(data.getItemStack("Items." + i + ".Item").clone(), lore)); ID.add(data.getInt("Items." + i + ".StoreID")); @@ -70,7 +70,7 @@ public class GUI implements Listener { } else { if (sell == ShopType.SELL) { for (String l : config.getStringList("Settings.GUISettings.SellingItemLore")) { - lore.add(l.replaceAll("%Price%", String.format(Locale.ENGLISH, "%,d", Long.parseLong(Methods.getPrice(i, false)))).replaceAll("%price%", String.format(Locale.ENGLISH, "%,d", Long.parseLong(Methods.getPrice(i, false)))).replaceAll("%Seller%", data.getString("Items." + i + ".Seller")).replaceAll("%seller%", data.getString("Items." + i + ".Seller")).replaceAll("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replaceAll("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire")))); + lore.add(l.replace("%Price%", String.format(Locale.ENGLISH, "%,d", Long.parseLong(Methods.getPrice(i, false)))).replace("%price%", String.format(Locale.ENGLISH, "%,d", Long.parseLong(Methods.getPrice(i, false)))).replace("%Seller%", data.getString("Items." + i + ".Seller")).replace("%seller%", data.getString("Items." + i + ".Seller")).replace("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire")))); } items.add(Methods.addLore(data.getItemStack("Items." + i + ".Item").clone(), lore)); ID.add(data.getInt("Items." + i + ".StoreID")); @@ -117,7 +117,7 @@ public class GUI implements Listener { String cName = Methods.color(config.getString("Settings.GUISettings.Category-Settings." + shopCategory.get(player).getName() + ".Name")); if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Lore")) { for (String l : config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore")) { - lore.add(l.replaceAll("%Category%", cName).replaceAll("%category%", cName)); + lore.add(l.replace("%Category%", cName).replace("%category%", cName)); } inv.setItem(slot - 1, Methods.makeItem(id, 1, name, lore)); } else { @@ -197,7 +197,7 @@ public class GUI implements Listener { if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getName())) { List lore = new ArrayList<>(); for (String l : config.getStringList("Settings.GUISettings.CurrentLore")) { - lore.add(l.replaceAll("%Price%", Methods.getPrice(i, false)).replaceAll("%price%", Methods.getPrice(i, false)).replaceAll("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replaceAll("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire")))); + lore.add(l.replace("%Price%", Methods.getPrice(i, false)).replace("%price%", Methods.getPrice(i, false)).replace("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire")))); } items.add(Methods.addLore(data.getItemStack("Items." + i + ".Item").clone(), lore)); ID.add(data.getInt("Items." + i + ".StoreID")); @@ -225,7 +225,7 @@ public class GUI implements Listener { if (data.getString("OutOfTime/Cancelled." + i + ".Seller").equalsIgnoreCase(player.getName())) { List lore = new ArrayList<>(); for (String l : config.getStringList("Settings.GUISettings.Cancelled/ExpiredLore")) { - lore.add(l.replaceAll("%Price%", Methods.getPrice(i, true)).replaceAll("%price%", Methods.getPrice(i, true)).replaceAll("%Time%", Methods.convertToTime(data.getLong("OutOfTime/Cancelled." + i + ".Full-Time"))).replaceAll("%time%", Methods.convertToTime(data.getLong("OutOfTime/Cancelled." + i + ".Full-Time")))); + lore.add(l.replace("%Price%", Methods.getPrice(i, true)).replace("%price%", Methods.getPrice(i, true)).replace("%Time%", Methods.convertToTime(data.getLong("OutOfTime/Cancelled." + i + ".Full-Time"))).replace("%time%", Methods.convertToTime(data.getLong("OutOfTime/Cancelled." + i + ".Full-Time")))); } items.add(Methods.addLore(data.getItemStack("OutOfTime/Cancelled." + i + ".Item").clone(), lore)); ID.add(data.getInt("OutOfTime/Cancelled." + i + ".StoreID")); @@ -304,7 +304,7 @@ public class GUI implements Listener { ItemStack item = data.getItemStack("Items." + ID + ".Item"); List lore = new ArrayList<>(); for (String l : config.getStringList("Settings.GUISettings.SellingItemLore")) { - lore.add(l.replaceAll("%Price%", Methods.getPrice(ID, false)).replaceAll("%price%", Methods.getPrice(ID, false)).replaceAll("%Seller%", data.getString("Items." + ID + ".Seller")).replaceAll("%seller%", data.getString("Items." + ID + ".Seller")).replaceAll("%Time%", Methods.convertToTime(data.getLong("Items." + l + ".Time-Till-Expire"))).replaceAll("%time%", Methods.convertToTime(data.getLong("Items." + l + ".Time-Till-Expire")))); + lore.add(l.replace("%Price%", Methods.getPrice(ID, false)).replace("%price%", Methods.getPrice(ID, false)).replace("%Seller%", data.getString("Items." + ID + ".Seller")).replace("%seller%", data.getString("Items." + ID + ".Seller")).replace("%Time%", Methods.convertToTime(data.getLong("Items." + l + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + l + ".Time-Till-Expire")))); } inv.setItem(4, Methods.addLore(item.clone(), lore)); IDs.put(player, ID); @@ -366,11 +366,11 @@ public class GUI implements Listener { String seller = data.getString("Items." + i + ".Seller"); String topbidder = data.getString("Items." + i + ".TopBidder"); for (String l : config.getStringList("Settings.GUISettings.Bidding")) { - lore.add(l.replaceAll("%TopBid%", Methods.getPrice(i, false)).replaceAll("%topbid%", Methods.getPrice(i, false)).replaceAll("%Seller%", seller).replaceAll("%seller%", seller).replaceAll("%TopBidder%", topbidder).replaceAll("%topbidder%", topbidder).replaceAll("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replaceAll("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire")))); + lore.add(l.replace("%TopBid%", Methods.getPrice(i, false)).replace("%topbid%", Methods.getPrice(i, false)).replace("%Seller%", seller).replace("%seller%", seller).replace("%TopBidder%", topbidder).replace("%topbidder%", topbidder).replace("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire")))); } } else { for (String l : config.getStringList("Settings.GUISettings.SellingItemLore")) { - lore.add(l.replaceAll("%Price%", Methods.getPrice(i, false)).replaceAll("%price%", Methods.getPrice(i, false)).replaceAll("%Seller%", data.getString("Items." + i + ".Seller")).replaceAll("%seller%", data.getString("Items." + i + ".Seller")).replaceAll("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replaceAll("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire")))); + lore.add(l.replace("%Price%", Methods.getPrice(i, false)).replace("%price%", Methods.getPrice(i, false)).replace("%Seller%", data.getString("Items." + i + ".Seller")).replace("%seller%", data.getString("Items." + i + ".Seller")).replace("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire")))); } } items.add(Methods.addLore(data.getItemStack("Items." + i + ".Item").clone(), lore)); @@ -415,7 +415,7 @@ public class GUI implements Listener { if (config.contains("Settings.GUISettings.OtherSettings.Bidding.Lore")) { List lore = new ArrayList<>(); for (String l : config.getStringList("Settings.GUISettings.OtherSettings.Bidding.Lore")) { - lore.add(l.replaceAll("%Bid%", bid + "").replaceAll("%bid%", bid + "").replaceAll("%TopBid%", Methods.getPrice(ID, false)).replaceAll("%topbid%", Methods.getPrice(ID, false))); + lore.add(l.replace("%Bid%", bid + "").replace("%bid%", bid + "").replace("%TopBid%", Methods.getPrice(ID, false)).replace("%topbid%", Methods.getPrice(ID, false))); } item = Methods.makeItem(id, 1, name, lore); } else { @@ -432,7 +432,7 @@ public class GUI implements Listener { ItemStack item = data.getItemStack("Items." + ID + ".Item"); List lore = new ArrayList<>(); for (String l : config.getStringList("Settings.GUISettings.Bidding")) { - lore.add(l.replaceAll("%TopBid%", Methods.getPrice(ID, false)).replaceAll("%topbid%", Methods.getPrice(ID, false)).replaceAll("%Seller%", seller).replaceAll("%seller%", seller).replaceAll("%TopBidder%", topbidder).replaceAll("%topbidder%", topbidder).replaceAll("%Time%", Methods.convertToTime(data.getLong("Items." + ID + ".Time-Till-Expire"))).replaceAll("%time%", Methods.convertToTime(data.getLong("Items." + ID + ".Time-Till-Expire")))); + lore.add(l.replace("%TopBid%", Methods.getPrice(ID, false)).replace("%topbid%", Methods.getPrice(ID, false)).replace("%Seller%", seller).replace("%seller%", seller).replace("%TopBidder%", topbidder).replace("%topbidder%", topbidder).replace("%Time%", Methods.convertToTime(data.getLong("Items." + ID + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + ID + ".Time-Till-Expire")))); } return Methods.addLore(item.clone(), lore); }