Start the process of switching to uuids

This commit is contained in:
Ryder Belserion 2024-06-15 00:47:56 -04:00
parent 22250d5328
commit df6bcd4136
No known key found for this signature in database
16 changed files with 213 additions and 95 deletions

View File

@ -7,10 +7,8 @@ import com.badbones69.crazyauctions.api.events.AuctionWinBidEvent;
import org.bukkit.*;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -74,13 +72,13 @@ public class Methods {
public static Player getPlayer(String name) {
try {
return Bukkit.getServer().getPlayer(name);
return Bukkit.getServer().getPlayer(UUID.fromString(name));
} catch (Exception e) {
return null;
}
}
public static OfflinePlayer getOfflinePlayer(String name) {
public static OfflinePlayer getOfflinePlayer(String name) { //todo () move off the thread.
return Bukkit.getServer().getOfflinePlayer(name);
}
@ -102,6 +100,7 @@ public class Methods {
}
p.sendMessage(Messages.NOT_ONLINE.getMessage());
return false;
}
@ -116,12 +115,7 @@ public class Methods {
public static boolean hasPermission(CommandSender sender, String perm) {
if (sender instanceof Player player) {
if (!player.hasPermission("crazyauctions." + perm)) {
player.sendMessage(Messages.NO_PERMISSION.getMessage());
return false;
}
return true;
return hasPermission(player, perm);
}
return true;
@ -137,7 +131,7 @@ public class Methods {
if (index < list.size()) items.add(list.get(index));
}
for (; items.size() == 0; page--) {
for (; items.isEmpty(); page--) {
if (page <= 0) break;
index = page * max - max;
endIndex = index >= list.size() ? list.size() - 1 : index + max;
@ -160,7 +154,7 @@ public class Methods {
if (index < list.size()) items.add(list.get(index));
}
for (; items.size() == 0; page--) {
for (; items.isEmpty(); page--) {
if (page <= 0) break;
index = page * max - max;
endIndex = index >= list.size() ? list.size() - 1 : index + max;

View File

@ -36,7 +36,7 @@ public class CrazyManager {
if (data.contains("Items")) {
for (String i : data.getConfigurationSection("Items").getKeys(false)) {
if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getName())) {
if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getUniqueId().toString())) {
if (data.getBoolean("Items." + i + ".Biddable")) {
if (type == ShopType.BID) {
items.add(data.getItemStack("Items." + i + ".Item").clone());

View File

@ -36,7 +36,6 @@ import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@ -1414,6 +1413,7 @@ public class ItemBuilder {
private static Map<String, Color> createMap() {
Map<String, Color> map = new HashMap<>();
map.put("AQUA", Color.AQUA);
map.put("BLACK", Color.BLACK);
map.put("BLUE", Color.BLUE);
@ -1431,12 +1431,14 @@ public class ItemBuilder {
map.put("TEAL", Color.TEAL);
map.put("WHITE", Color.WHITE);
map.put("YELLOW", Color.YELLOW);
return map;
}
public static Color getColor(String color) {
if (color != null && !color.isBlank()) {
Color mappedColor = (Color)colors.get(color.toUpperCase());
Color mappedColor = colors.get(color.toUpperCase());
if (mappedColor != null) {
return mappedColor;
} else {

View File

@ -20,7 +20,7 @@ public enum Category {
/**
* @param name Name of the Shop Type.
*/
private Category(String name, ArrayList<Material> items) {
Category(String name, ArrayList<Material> items) {
this.name = name;
this.items = items;
}

View File

@ -57,12 +57,12 @@ public enum Messages {
private String defaultMessage;
private List<String> defaultListMessage;
private Messages(String path, String defaultMessage) {
Messages(String path, String defaultMessage) {
this.path = path;
this.defaultMessage = defaultMessage;
}
private Messages(String path, List<String> defaultListMessage) {
Messages(String path, List<String> defaultListMessage) {
this.path = path;
this.defaultListMessage = defaultListMessage;
}
@ -76,13 +76,12 @@ public enum Messages {
}
public static String convertList(List<String> list, HashMap<String, String> placeholders) {
String message = "";
for (String m : list) {
message += Methods.color(m) + "\n";
}
String message = convertList(list);
for (String ph : placeholders.keySet()) {
message = Methods.color(message.replace(ph, placeholders.get(ph))).replace(ph, placeholders.get(ph).toLowerCase());
}
return message;
}
@ -99,6 +98,7 @@ public enum Messages {
}
}
}
if (saveFile) {
Files.MESSAGES.saveFile();
}
@ -122,6 +122,7 @@ public enum Messages {
public String getMessage(HashMap<String, String> placeholders) {
String message;
if (isList()) {
if (exists()) {
message = Methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path), placeholders));
@ -134,12 +135,14 @@ public enum Messages {
} else {
message = Methods.getPrefix(getDefaultMessage());
}
for (String ph : placeholders.keySet()) {
if (message.contains(ph)) {
message = message.replace(ph, placeholders.get(ph)).replace(ph, placeholders.get(ph).toLowerCase());
}
}
}
return message;
}
@ -161,6 +164,7 @@ public enum Messages {
public String getMessageNoPrefix(HashMap<String, String> placeholders) {
String message;
if (isList()) {
if (exists()) {
message = Methods.color(convertList(Files.MESSAGES.getFile().getStringList("Messages." + path), placeholders));
@ -173,12 +177,14 @@ public enum Messages {
} else {
message = Methods.color(getDefaultMessage());
}
for (String ph : placeholders.keySet()) {
if (message.contains(ph)) {
message = message.replace(ph, placeholders.get(ph)).replace(ph, placeholders.get(ph).toLowerCase());
}
}
}
return message;
}
@ -205,5 +211,4 @@ public enum Messages {
private List<String> getDefaultListMessage() {
return defaultListMessage;
}
}

View File

@ -1,6 +1,6 @@
package com.badbones69.crazyauctions.api.enums;
public enum Reaons {
public enum Reasons {
/**
* Cancelled by an administrator.

View File

@ -33,5 +33,4 @@ public enum ShopType {
public String getName() {
return name;
}
}

View File

@ -4,6 +4,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
/**
*
@ -36,7 +37,7 @@ public class AuctionBuyEvent extends Event {
return handlers;
}
public HandlerList getHandlers() {
public @NotNull HandlerList getHandlers() {
return handlers;
}
@ -51,5 +52,4 @@ public class AuctionBuyEvent extends Event {
public long getPrice() {
return price;
}
}

View File

@ -1,11 +1,12 @@
package com.badbones69.crazyauctions.api.events;
import com.badbones69.crazyauctions.api.enums.Reaons;
import com.badbones69.crazyauctions.api.enums.Reasons;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
/**
*
@ -20,7 +21,7 @@ public class AuctionCancelledEvent extends Event {
private final boolean isOnline;
private final ItemStack item;
private final Reaons reason;
private final Reasons reason;
private OfflinePlayer offlinePlayer;
private Player onlinePlayer;
@ -30,7 +31,7 @@ public class AuctionCancelledEvent extends Event {
* @param offlinePlayer The player whose item is cancelled.
* @param item The item that is cancelled.
*/
public AuctionCancelledEvent(OfflinePlayer offlinePlayer, ItemStack item, Reaons reason) {
public AuctionCancelledEvent(OfflinePlayer offlinePlayer, ItemStack item, Reasons reason) {
this.offlinePlayer = offlinePlayer;
this.item = item;
this.isOnline = false;
@ -42,7 +43,7 @@ public class AuctionCancelledEvent extends Event {
* @param onlinePlayer The player whose item is cancelled.
* @param item The item that is cancelled.
*/
public AuctionCancelledEvent(Player onlinePlayer, ItemStack item, Reaons reason) {
public AuctionCancelledEvent(Player onlinePlayer, ItemStack item, Reasons reason) {
this.onlinePlayer = onlinePlayer;
this.item = item;
this.isOnline = true;
@ -53,7 +54,7 @@ public class AuctionCancelledEvent extends Event {
return handlers;
}
public HandlerList getHandlers() {
public @NotNull HandlerList getHandlers() {
return handlers;
}
@ -73,8 +74,7 @@ public class AuctionCancelledEvent extends Event {
return item;
}
public Reaons getReason() {
public Reasons getReason() {
return reason;
}
}

View File

@ -5,6 +5,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
/**
*
@ -49,7 +50,7 @@ public class AuctionExpireEvent extends Event {
return handlers;
}
public HandlerList getHandlers() {
public @NotNull HandlerList getHandlers() {
return handlers;
}
@ -68,5 +69,4 @@ public class AuctionExpireEvent extends Event {
public ItemStack getItem() {
return item;
}
}

View File

@ -5,6 +5,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
/**
*
@ -39,7 +40,7 @@ public class AuctionListEvent extends Event {
return handlers;
}
public HandlerList getHandlers() {
public @NotNull HandlerList getHandlers() {
return handlers;
}
@ -58,5 +59,4 @@ public class AuctionListEvent extends Event {
public long getPrice() {
return price;
}
}

View File

@ -4,6 +4,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
/**
*
@ -32,7 +33,7 @@ public class AuctionNewBidEvent extends Event {
return handlers;
}
public HandlerList getHandlers() {
public @NotNull HandlerList getHandlers() {
return handlers;
}
@ -47,5 +48,4 @@ public class AuctionNewBidEvent extends Event {
public long getBid() {
return bid;
}
}

View File

@ -4,6 +4,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
/**
*
@ -35,7 +36,7 @@ public class AuctionWinBidEvent extends Event {
return handlers;
}
public HandlerList getHandlers() {
public @NotNull HandlerList getHandlers() {
return handlers;
}
@ -50,5 +51,4 @@ public class AuctionWinBidEvent extends Event {
public long getBid() {
return bid;
}
}

View File

@ -25,6 +25,7 @@ import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
import java.util.Random;
import java.util.UUID;
import java.util.logging.Level;
public class AuctionCommand implements CommandExecutor {
@ -100,7 +101,7 @@ public class AuctionCommand implements CommandExecutor {
if (item != null && item.getType() != Material.AIR) {
// For testing as another player
String seller = "Test-Account";
String seller = UUID.randomUUID().toString();
for (int it = 1; it <= times; it++) {
int num = 1;
@ -113,12 +114,12 @@ public class AuctionCommand implements CommandExecutor {
data.set("Items." + num + ".Seller", seller);
if (args[0].equalsIgnoreCase("bid")) {
data.set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(config.getString("Settings.Bid-Time")));
data.set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(config.getString("Settings.Bid-Time", "2m 30s")));
} else {
data.set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(config.getString("Settings.Sell-Time")));
data.set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(config.getString("Settings.Sell-Time", "2d")));
}
data.set("Items." + num + ".Full-Time", Methods.convertToMill(config.getString("Settings.Full-Expire-Time")));
data.set("Items." + num + ".Full-Time", Methods.convertToMill(config.getString("Settings.Full-Expire-Time", "10d")));
int id = random.nextInt(Integer.MAX_VALUE);
for (String i : data.getConfigurationSection("Items").getKeys(false))
@ -271,21 +272,21 @@ public class AuctionCommand implements CommandExecutor {
long price = Long.parseLong(args[1]);
if (args[0].equalsIgnoreCase("bid")) {
if (price < config.getLong("Settings.Minimum-Bid-Price")) {
if (price < config.getLong("Settings.Minimum-Bid-Price", 100)) {
player.sendMessage(Messages.BID_PRICE_TO_LOW.getMessage());
return true;
}
if (price > config.getLong("Settings.Max-Beginning-Bid-Price")) {
if (price > config.getLong("Settings.Max-Beginning-Bid-Price", 1000000)) {
player.sendMessage(Messages.BID_PRICE_TO_HIGH.getMessage());
return true;
}
} else {
if (price < config.getLong("Settings.Minimum-Sell-Price")) {
if (price < config.getLong("Settings.Minimum-Sell-Price", 10)) {
player.sendMessage(Messages.SELL_PRICE_TO_LOW.getMessage());
return true;
}
if (price > config.getLong("Settings.Max-Beginning-Sell-Price")) {
if (price > config.getLong("Settings.Max-Beginning-Sell-Price", 1000000)) {
player.sendMessage(Messages.SELL_PRICE_TO_HIGH.getMessage());
return true;
}
@ -352,7 +353,7 @@ public class AuctionCommand implements CommandExecutor {
return true;
}
if (!config.getBoolean("Settings.Allow-Damaged-Items")) {
if (!config.getBoolean("Settings.Allow-Damaged-Items", false)) {
for (Material i : getDamageableItems()) {
if (item.getType() == i) {
if (item.getDurability() > 0) {
@ -368,7 +369,7 @@ public class AuctionCommand implements CommandExecutor {
return true;
}
String seller = player.getName();
String seller = player.getUniqueId().toString();
int num = 1;
Random random = new Random();
@ -378,12 +379,12 @@ public class AuctionCommand implements CommandExecutor {
data.set("Items." + num + ".Seller", seller);
if (args[0].equalsIgnoreCase("bid")) {
data.set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(config.getString("Settings.Bid-Time")));
data.set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(config.getString("Settings.Bid-Time", "2m 30s")));
} else {
data.set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(config.getString("Settings.Sell-Time")));
data.set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(config.getString("Settings.Sell-Time", "2d")));
}
data.set("Items." + num + ".Full-Time", Methods.convertToMill(config.getString("Settings.Full-Expire-Time")));
data.set("Items." + num + ".Full-Time", Methods.convertToMill(config.getString("Settings.Full-Expire-Time", "10d")));
int id = random.nextInt(999999);
// Runs 3x to check for same ID.
for (String i : data.getConfigurationSection("Items").getKeys(false))

View File

@ -6,7 +6,7 @@ import com.badbones69.crazyauctions.api.*;
import com.badbones69.crazyauctions.api.FileManager.Files;
import com.badbones69.crazyauctions.api.builders.ItemBuilder;
import com.badbones69.crazyauctions.api.enums.Category;
import com.badbones69.crazyauctions.api.enums.Reaons;
import com.badbones69.crazyauctions.api.enums.Reasons;
import com.badbones69.crazyauctions.api.enums.Messages;
import com.badbones69.crazyauctions.api.enums.ShopType;
import com.badbones69.crazyauctions.api.events.AuctionBuyEvent;
@ -75,7 +75,12 @@ public class GuiListener 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.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"))));
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"))));
}
itemBuilder.setLore(lore);
@ -87,7 +92,11 @@ public class GuiListener implements Listener {
} else {
if (sell == ShopType.SELL) {
for (String l : config.getStringList("Settings.GUISettings.SellingItemLore")) {
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"))));
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"))));
}
itemBuilder.setLore(lore);
@ -248,10 +257,13 @@ public class GuiListener implements Listener {
if (data.contains("Items")) {
for (String i : data.getConfigurationSection("Items").getKeys(false)) {
if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getName())) {
if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getUniqueId().toString())) {
List<String> lore = new ArrayList<>();
for (String l : config.getStringList("Settings.GUISettings.CurrentLore")) {
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"))));
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"))));
}
ItemBuilder itemBuilder = ItemBuilder.convertItemStack(ItemStack.deserializeBytes(Base64.getDecoder().decode(data.getString("Items." + i + ".Item"))));
@ -285,10 +297,13 @@ public class GuiListener implements Listener {
if (data.contains("OutOfTime/Cancelled")) {
for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) {
if (data.getString("OutOfTime/Cancelled." + i + ".Seller") != null) {
if (data.getString("OutOfTime/Cancelled." + i + ".Seller").equalsIgnoreCase(player.getName())) {
if (data.getString("OutOfTime/Cancelled." + i + ".Seller").equalsIgnoreCase(player.getUniqueId().toString())) {
List<String> lore = new ArrayList<>();
for (String l : config.getStringList("Settings.GUISettings.Cancelled/ExpiredLore")) {
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"))));
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"))));
}
ItemBuilder itemBuilder = ItemBuilder.convertItemStack(ItemStack.deserializeBytes(Base64.getDecoder().decode(data.getString("OutOfTime/Cancelled." + i + ".Item"))));
@ -393,8 +408,25 @@ public class GuiListener implements Listener {
ItemStack item = ItemStack.deserializeBytes(Base64.getDecoder().decode(data.getString("Items." + ID + ".Item")));
List<String> lore = new ArrayList<>();
for (String l : config.getStringList("Settings.GUISettings.SellingItemLore")) {
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"))));
final String price = Methods.getPrice(ID, false);
for (String key : config.getStringList("Settings.GUISettings.SellingItemLore")) {
String line = key.replace("%Price%", price).replace("%price%", price);
String uuid = data.getString("Items." + ID + ".Seller");
if (uuid != null) {
Player person = plugin.getServer().getPlayer(UUID.fromString(uuid));
if (person != null) {
line = line.replace("%Seller%", person.getName()).replace("%seller%", person.getName());
}
}
final String time = Methods.convertToTime(data.getLong("Items." + key + ".Time-Till-Expire"));
lore.add(line.replace("%Time%", time).replace("%time%", time));
}
ItemBuilder itemBuilder = ItemBuilder.convertItemStack(item);
@ -415,6 +447,7 @@ public class GuiListener implements Listener {
if (!data.contains("Items." + ID)) {
openShop(player, ShopType.BID, shopCategory.get(player.getUniqueId()), 1);
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage());
return;
}
@ -449,32 +482,76 @@ public class GuiListener implements Listener {
if (!data.contains("Items")) {
data.set("Items.Clear", null);
Files.DATA.saveFile();
}
Player otherPlayer = plugin.getServer().getPlayer(UUID.fromString(other));
if (data.contains("Items")) {
for (String i : data.getConfigurationSection("Items").getKeys(false)) {
if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(other)) {
final String tag = data.getString("Items." + i + ".Seller");
if (tag != null) {
List<String> lore = new ArrayList<>();
if (data.getBoolean("Items." + i + ".Biddable")) {
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.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.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"))));
if (otherPlayer != null && tag.equalsIgnoreCase(otherPlayer.getUniqueId().toString())) {
final String time = Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"));
final String price = Methods.getPrice(i, false);
if (data.getBoolean("Items." + i + ".Biddable")) {
String uuid = data.getString("Items." + i + ".Seller");
String topbidder = data.getString("Items." + i + ".TopBidder");
for (String key : config.getStringList("Settings.GUISettings.Bidding")) {
String line = key.replace("%Price%", price).replace("%price%", price);
if (uuid != null) {
Player person = plugin.getServer().getPlayer(UUID.fromString(uuid));
if (person != null) {
line = line.replace("%Seller%", person.getName()).replace("%seller%", person.getName());
}
}
if (topbidder != null) {
Player person = plugin.getServer().getPlayer(UUID.fromString(topbidder));
if (person != null) {
line = line.replace("%TopBidder%", person.getName()).replace("%topbidder%", person.getName());
}
}
lore.add(line.replace("%Time%", time).replace("%time%", time).replace("%TopBid%", price).replace("%topbid%", price));
}
} else {
for (String key : config.getStringList("Settings.GUISettings.SellingItemLore")) {
String line = key.replace("%Price%", price).replace("%price%", price);
String uuid = data.getString("Items." + i + ".Seller");
if (uuid != null) {
Player person = plugin.getServer().getPlayer(UUID.fromString(uuid));
if (person != null) {
line = line.replace("%Seller%", person.getName()).replace("%seller%", person.getName());
}
}
lore.add(line.replace("%Price%", price).replace("%price%", price).replace("%Time%", time).replace("%time%", time));
}
}
ItemBuilder itemBuilder = ItemBuilder.convertItemStack(ItemStack.deserializeBytes(Base64.getDecoder().decode(data.getString("Items." + ID + ".Item"))));
itemBuilder.setLore(lore);
items.add(itemBuilder.build());
ID.add(data.getInt("Items." + i + ".StoreID"));
}
ItemBuilder itemBuilder = ItemBuilder.convertItemStack(ItemStack.deserializeBytes(Base64.getDecoder().decode(data.getString("Items." + ID + ".Item"))));
itemBuilder.setLore(lore);
items.add(itemBuilder.build());
ID.add(data.getInt("Items." + i + ".StoreID"));
}
}
}
@ -528,8 +605,11 @@ public class GuiListener implements Listener {
if (config.contains("Settings.GUISettings.OtherSettings.Bidding.Lore")) {
List<String> lore = new ArrayList<>();
for (String l : config.getStringList("Settings.GUISettings.OtherSettings.Bidding.Lore")) {
lore.add(l.replace("%Bid%", bid + "").replace("%bid%", bid + "").replace("%TopBid%", Methods.getPrice(ID, false)).replace("%topbid%", Methods.getPrice(ID, false)));
final String price = Methods.getPrice(ID, false);
for (String line : config.getStringList("Settings.GUISettings.OtherSettings.Bidding.Lore")) {
lore.add(line.replace("%Bid%", String.valueOf(bid)).replace("%bid%", String.valueOf(bid)).replace("%TopBid%", price).replace("%topbid%", price));
}
itemBuilder.setLore(lore);
@ -541,13 +621,42 @@ public class GuiListener implements Listener {
private static ItemStack getBiddingItem(String ID) {
FileConfiguration config = Files.CONFIG.getFile();
FileConfiguration data = Files.DATA.getFile();
String seller = data.getString("Items." + ID + ".Seller");
Player player = null;
if (seller != null) {
player = plugin.getServer().getPlayer(UUID.fromString(seller));
}
String topbidder = data.getString("Items." + ID + ".TopBidder");
Player bidder = null;
if (topbidder != null) {
bidder = plugin.getServer().getPlayer(UUID.fromString(topbidder));
}
ItemStack item = ItemStack.deserializeBytes(Base64.getDecoder().decode(data.getString("Items." + ID + ".Item")));
List<String> lore = new ArrayList<>();
for (String l : config.getStringList("Settings.GUISettings.Bidding")) {
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"))));
final String price = Methods.getPrice(ID, false);
final String time = Methods.convertToTime(data.getLong("Items." + ID + ".Time-Till-Expire"));
for (String key : config.getStringList("Settings.GUISettings.Bidding")) {
String line = key.replace("%TopBid%", time).replace("%topbid%", time);
if (player != null) {
line = line.replace("%Seller%", player.getName()).replace("%seller%", player.getName());
}
if (bidder != null) {
line = line.replace("%TopBidder%", bidder.getName()).replace("%topbidder%", bidder.getName());
}
lore.add(line.replace("%TopBid%", price).replace("%topbid%", price).replace("%time%", time).replace("%Time%", time));
}
ItemBuilder itemBuilder = ItemBuilder.convertItemStack(item);
@ -573,7 +682,9 @@ public class GuiListener implements Listener {
private void playSoldSound(@NotNull Player player) {
FileConfiguration config = Files.CONFIG.getFile();
String sound = config.getString("Settings.Sold-Item-Sound", "");
String sound = config.getString("Settings.Sold-Item-Sound", "UI_BUTTON_CLICK");
if (sound.isEmpty()) return;
try {
@ -661,7 +772,7 @@ public class GuiListener implements Listener {
Bukkit.getPluginManager().callEvent(new AuctionNewBidEvent(player, ItemStack.deserializeBytes(Base64.getDecoder().decode(data.getString("Items." + ID + ".Item"))), bid));
data.set("Items." + ID + ".Price", bid);
data.set("Items." + ID + ".TopBidder", player.getName());
data.set("Items." + ID + ".TopBidder", player.getUniqueId().toString());
HashMap<String, String> placeholders = new HashMap<>();
placeholders.put("%Bid%", bid + "");
player.sendMessage(Messages.BID_MESSAGE.getMessage(placeholders));
@ -808,8 +919,9 @@ public class GuiListener implements Listener {
sellerPlayer.sendMessage(Messages.ADMIN_FORCE_CANCELLED_TO_PLAYER.getMessage());
}
AuctionCancelledEvent event = new AuctionCancelledEvent((sellerPlayer != null ? sellerPlayer : Bukkit.getOfflinePlayer(seller)), ItemStack.deserializeBytes(Base64.getDecoder().decode(data.getString("Items." + ID + ".Item"))), Reaons.ADMIN_FORCE_CANCEL);
Bukkit.getPluginManager().callEvent(event);
AuctionCancelledEvent event = new AuctionCancelledEvent((sellerPlayer != null ? sellerPlayer : Methods.getOfflinePlayer(seller)), ItemStack.deserializeBytes(Base64.getDecoder().decode(data.getString("Items." + ID + ".Item"))), Reasons.ADMIN_FORCE_CANCEL);
plugin.getServer().getPluginManager().callEvent(event);
data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller"));
data.set("OutOfTime/Cancelled." + num + ".Full-Time", data.getLong("Items." + i + ".Full-Time"));
data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID"));
@ -857,11 +969,12 @@ public class GuiListener implements Listener {
inv.setItem(slot, itemBuilder.build());
playClick(player);
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20);
return;
}
if (data.getBoolean("Items." + i + ".Biddable")) {
if (player.getName().equalsIgnoreCase(data.getString("Items." + i + ".TopBidder"))) {
if (player.getUniqueId().toString().equalsIgnoreCase(data.getString("Items." + i + ".TopBidder"))) {
String itemName = config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Item");
String name = config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Name");
@ -874,6 +987,7 @@ public class GuiListener implements Listener {
inv.setItem(slot, itemBuilder.build());
playClick(player);
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20);
return;
}
@ -894,6 +1008,7 @@ public class GuiListener implements Listener {
playClick(player);
openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), 1);
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage());
return;
}
}
@ -947,6 +1062,7 @@ public class GuiListener implements Listener {
plugin.getServer().getPluginManager().callEvent(new AuctionBuyEvent(player, i, cost));
plugin.getSupport().removeMoney(player, cost);
plugin.getSupport().addMoney(Methods.getOfflinePlayer(seller), cost);
HashMap<String, String> placeholders = new HashMap<>();
placeholders.put("%Price%", Methods.getPrice(ID, false));
placeholders.put("%price%", Methods.getPrice(ID, false));
@ -954,6 +1070,7 @@ public class GuiListener implements Listener {
placeholders.put("%player%", player.getName());
player.sendMessage(Messages.BOUGHT_ITEM.getMessage(placeholders));
if (Methods.isOnline(seller) && Methods.getPlayer(seller) != null) {
Player sell = Methods.getPlayer(seller);
sell.sendMessage(Messages.PLAYER_BOUGHT_ITEM.getMessage(placeholders));
@ -1005,7 +1122,7 @@ public class GuiListener implements Listener {
int ID = data.getInt("Items." + i + ".StoreID");
if (id == ID) {
player.sendMessage(Messages.CANCELLED_ITEM.getMessage());
AuctionCancelledEvent event = new AuctionCancelledEvent(player, ItemStack.deserializeBytes(Base64.getDecoder().decode(data.getString("Items." + i + ".Item"))), Reaons.PLAYER_FORCE_CANCEL);
AuctionCancelledEvent event = new AuctionCancelledEvent(player, ItemStack.deserializeBytes(Base64.getDecoder().decode(data.getString("Items." + i + ".Item"))), Reasons.PLAYER_FORCE_CANCEL);
Bukkit.getPluginManager().callEvent(event);
int num = 1;
for (; data.contains("OutOfTime/Cancelled." + num); num++) ;
@ -1128,4 +1245,4 @@ public class GuiListener implements Listener {
}
}
}
}
}

View File

@ -23,8 +23,8 @@ Settings:
Macro-Dupe: true #Turn to false if you have an issue, but it should patch the bug.
Sounds:
Toggle: false #Disable the clicking sound.
Sound: 'CLICK' #Make sure if you use 1.8 or lower you use the 1.8 sound and 1.9 and up use 1.9 sounds. The default sound is 1.8.
Sold-Item-Sound: 'CLICK'
Sound: 'UI_BUTTON_CLICK' #Make sure if you use 1.8 or lower you use the 1.8 sound and 1.9 and up use 1.9 sounds. The default sound is 1.8.
Sold-Item-Sound: 'UI_BUTTON_CLICK'
#Sounds are found here: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Sound.html
GUISettings: #Settings for things in the gui.
SellingItemLore: #The lore on items that are being sold.