mirror of
https://github.com/Crazy-Crew/CrazyAuctions.git
synced 2024-11-22 11:55:12 +01:00
[build] caught a few stragglings from the item format change
This commit is contained in:
parent
c761419c78
commit
fe00dca4f3
@ -1,5 +1,2 @@
|
||||
## Changes
|
||||
* Updated the item builder, What does this mean?
|
||||
* Custom Items are finally supported
|
||||
* The item sections in the config.yml have the same capabilities as our other plugins.
|
||||
* All lores, display names have placeholder api support.
|
||||
### Fixed:
|
||||
- Caught a few stragglers in the code not yet updated to the using the methods for the new item format.
|
@ -10,7 +10,7 @@ issues = https://github.com/Crazy-Crew/CrazyAuctions/issues
|
||||
|
||||
group = com.badbones69.crazyauctions
|
||||
description = Auction off items in style.
|
||||
version = 1.4.1
|
||||
version = 1.4.2
|
||||
apiVersion = 1.20
|
||||
|
||||
mcVersion = 1.20.4
|
||||
|
@ -1,11 +1,18 @@
|
||||
[plugins]
|
||||
run-paper = { id = "xyz.jpenilla.run-paper", version = "2.2.3" }
|
||||
minotaur = { id = "com.modrinth.minotaur", version.ref = "minotaur" }
|
||||
hangar = { id = "io.papermc.hangar-publish-plugin", version.ref = "hangar" }
|
||||
shadow = { id = "com.github.johnrengelman.shadow", version = "8.1.1" }
|
||||
|
||||
[versions]
|
||||
kyori = "4.16.0"
|
||||
bundle = "1.20.4-R0.1-SNAPSHOT"
|
||||
cluster = "1.0-SNAPSHOT"
|
||||
minotaur = "2.+"
|
||||
hangar = "0.1.2"
|
||||
|
||||
paper = "1.20.4-R0.1-SNAPSHOT"
|
||||
minecraft = "1.20.4"
|
||||
|
||||
[libraries]
|
||||
simple-yaml = { group = "com.github.Carleslc.Simple-YAML", name = "Simple-Yaml", version = "1.8.4" }
|
||||
|
@ -7,10 +7,10 @@ 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 org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -80,6 +80,14 @@ public class Methods {
|
||||
}
|
||||
}
|
||||
|
||||
public static String toBase64(final ItemStack itemStack) {
|
||||
return Base64.getEncoder().encodeToString(itemStack.serializeAsBytes());
|
||||
}
|
||||
|
||||
public static @NotNull ItemStack fromBase64(final String base64) {
|
||||
return ItemStack.deserializeBytes(Base64.getDecoder().decode(base64));
|
||||
}
|
||||
|
||||
public static OfflinePlayer getOfflinePlayer(String name) {
|
||||
return Bukkit.getServer().getOfflinePlayer(name);
|
||||
}
|
||||
@ -262,7 +270,7 @@ public class Methods {
|
||||
|
||||
if (isOnline(winner) && getPlayer(winner) != null) {
|
||||
Player player = getPlayer(winner);
|
||||
Bukkit.getPluginManager().callEvent(new AuctionWinBidEvent(player, data.getItemStack("Items." + i + ".Item"), price));
|
||||
Bukkit.getPluginManager().callEvent(new AuctionWinBidEvent(player, Methods.fromBase64(data.getString("Items." + i + ".Item")), price));
|
||||
player.sendMessage(Messages.WIN_BIDDING.getMessage(placeholders));
|
||||
}
|
||||
|
||||
@ -274,7 +282,7 @@ public class Methods {
|
||||
data.set("OutOfTime/Cancelled." + num + ".Seller", winner);
|
||||
data.set("OutOfTime/Cancelled." + num + ".Full-Time", fullExpireTime.getTimeInMillis());
|
||||
data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID"));
|
||||
data.set("OutOfTime/Cancelled." + num + ".Item", data.getItemStack("Items." + i + ".Item"));
|
||||
data.set("OutOfTime/Cancelled." + num + ".Item", data.getString("Items." + i + ".Item"));
|
||||
} else {
|
||||
String seller = data.getString("Items." + i + ".Seller");
|
||||
Player player = getPlayer(seller);
|
||||
@ -283,12 +291,12 @@ public class Methods {
|
||||
player.sendMessage(Messages.ITEM_HAS_EXPIRED.getMessage());
|
||||
}
|
||||
|
||||
AuctionExpireEvent event = new AuctionExpireEvent(player, data.getItemStack("Items." + i + ".Item"));
|
||||
AuctionExpireEvent event = new AuctionExpireEvent(player, Methods.fromBase64(data.getString("Items." + i + ".Item")));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller"));
|
||||
data.set("OutOfTime/Cancelled." + num + ".Full-Time", fullExpireTime.getTimeInMillis());
|
||||
data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID"));
|
||||
data.set("OutOfTime/Cancelled." + num + ".Item", data.getItemStack("Items." + i + ".Item"));
|
||||
data.set("OutOfTime/Cancelled." + num + ".Item", data.getString("Items." + i + ".Item"));
|
||||
}
|
||||
|
||||
data.set("Items." + i, null);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.badbones69.crazyauctions.api;
|
||||
|
||||
import com.badbones69.crazyauctions.Methods;
|
||||
import com.badbones69.crazyauctions.api.FileManager.Files;
|
||||
import com.badbones69.crazyauctions.api.enums.ShopType;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@ -39,11 +40,11 @@ public class CrazyManager {
|
||||
if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getName())) {
|
||||
if (data.getBoolean("Items." + i + ".Biddable")) {
|
||||
if (type == ShopType.BID) {
|
||||
items.add(data.getItemStack("Items." + i + ".Item").clone());
|
||||
items.add(Methods.fromBase64(data.getString("Items." + i + ".Item")));
|
||||
}
|
||||
} else {
|
||||
if (type == ShopType.SELL) {
|
||||
items.add(data.getItemStack("Items." + i + ".Item").clone());
|
||||
items.add(Methods.fromBase64(data.getString("Items." + i + ".Item")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1104,6 +1104,12 @@ public class ItemBuilder {
|
||||
return new ItemBuilder(item).setAmount(item.getAmount()).setEnchantments(new HashMap<>(item.getEnchantments()));
|
||||
}
|
||||
|
||||
public static ItemBuilder convertItemStack(String item) {
|
||||
ItemStack itemStack = Methods.fromBase64(item);
|
||||
|
||||
return new ItemBuilder(itemStack).setAmount(itemStack.getAmount()).setEnchantments(new HashMap<>(itemStack.getEnchantments()));
|
||||
}
|
||||
|
||||
public static ItemBuilder convertItemStack(ItemStack item, Player player) {
|
||||
return new ItemBuilder(item).setTarget(player).setAmount(item.getAmount()).setEnchantments(new HashMap<>(item.getEnchantments()));
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ public class AuctionCommand implements CommandExecutor {
|
||||
ItemStack stack = item.clone();
|
||||
stack.setAmount(amount);
|
||||
|
||||
data.set("Items." + num + ".Item", Base64.getEncoder().encodeToString(stack.serializeAsBytes()));
|
||||
data.set("Items." + num + ".Item", Methods.toBase64(stack));
|
||||
}
|
||||
|
||||
Files.DATA.saveFile();
|
||||
@ -407,7 +407,7 @@ public class AuctionCommand implements CommandExecutor {
|
||||
ItemStack stack = item.clone();
|
||||
stack.setAmount(amount);
|
||||
|
||||
data.set("Items." + num + ".Item", Base64.getEncoder().encodeToString(stack.serializeAsBytes()));
|
||||
data.set("Items." + num + ".Item", Methods.toBase64(stack));
|
||||
|
||||
Files.DATA.saveFile();
|
||||
|
||||
|
@ -67,7 +67,7 @@ public class GuiListener implements Listener {
|
||||
for (String i : data.getConfigurationSection("Items").getKeys(false)) {
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
ItemBuilder itemBuilder = ItemBuilder.convertItemStack(ItemStack.deserializeBytes(Base64.getDecoder().decode(data.getString("Items." + i + ".Item"))));
|
||||
ItemBuilder itemBuilder = ItemBuilder.convertItemStack(data.getString("Items." + i + ".Item"));
|
||||
|
||||
if (itemBuilder != null && data.contains("Items." + i + ".Item") && (cat.getItems().contains(itemBuilder.getItemStack().getType()) || cat == Category.NONE)) {
|
||||
if (data.getBoolean("Items." + i + ".Biddable")) {
|
||||
@ -254,7 +254,7 @@ public class GuiListener implements Listener {
|
||||
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"))));
|
||||
ItemBuilder itemBuilder = ItemBuilder.convertItemStack(data.getString("Items." + i + ".Item"));
|
||||
|
||||
itemBuilder.setLore(lore);
|
||||
|
||||
@ -291,7 +291,7 @@ public class GuiListener implements Listener {
|
||||
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"))));
|
||||
ItemBuilder itemBuilder = ItemBuilder.convertItemStack(data.getString("OutOfTime/Cancelled." + i + ".Item"));
|
||||
|
||||
itemBuilder.setLore(lore);
|
||||
|
||||
@ -391,13 +391,12 @@ 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"))));
|
||||
}
|
||||
|
||||
ItemBuilder itemBuilder = ItemBuilder.convertItemStack(item);
|
||||
ItemBuilder itemBuilder = ItemBuilder.convertItemStack(data.getString("Items." + ID + ".Item"));
|
||||
|
||||
itemBuilder.setLore(lore);
|
||||
|
||||
@ -468,7 +467,7 @@ public class GuiListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
ItemBuilder itemBuilder = ItemBuilder.convertItemStack(ItemStack.deserializeBytes(Base64.getDecoder().decode(data.getString("Items." + ID + ".Item"))));
|
||||
ItemBuilder itemBuilder = ItemBuilder.convertItemStack(data.getString("Items." + ID + ".Item"));
|
||||
|
||||
itemBuilder.setLore(lore);
|
||||
|
||||
@ -543,7 +542,7 @@ public class GuiListener implements Listener {
|
||||
FileConfiguration data = Files.DATA.getFile();
|
||||
String seller = data.getString("Items." + ID + ".Seller");
|
||||
String topbidder = data.getString("Items." + ID + ".TopBidder");
|
||||
ItemStack item = ItemStack.deserializeBytes(Base64.getDecoder().decode(data.getString("Items." + ID + ".Item")));
|
||||
ItemStack item = Methods.fromBase64(data.getString("Items." + ID + ".Item"));
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
for (String l : config.getStringList("Settings.GUISettings.Bidding")) {
|
||||
@ -659,7 +658,8 @@ public class GuiListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new AuctionNewBidEvent(player, ItemStack.deserializeBytes(Base64.getDecoder().decode(data.getString("Items." + ID + ".Item"))), bid));
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new AuctionNewBidEvent(player, Methods.fromBase64(data.getString("Items." + ID + ".Item")), bid));
|
||||
data.set("Items." + ID + ".Price", bid);
|
||||
data.set("Items." + ID + ".TopBidder", player.getName());
|
||||
HashMap<String, String> placeholders = new HashMap<>();
|
||||
@ -808,7 +808,7 @@ 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);
|
||||
AuctionCancelledEvent event = new AuctionCancelledEvent((sellerPlayer != null ? sellerPlayer : Bukkit.getOfflinePlayer(seller)), Methods.fromBase64(data.getString("Items." + ID + ".Item")), Reaons.ADMIN_FORCE_CANCEL);
|
||||
Bukkit.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"));
|
||||
@ -942,7 +942,7 @@ public class GuiListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack i = ItemStack.deserializeBytes(Base64.getDecoder().decode(data.getString("Items." + ID + ".Item")));
|
||||
ItemStack i = Methods.fromBase64(data.getString("Items." + ID + ".Item"));
|
||||
|
||||
plugin.getServer().getPluginManager().callEvent(new AuctionBuyEvent(player, i, cost));
|
||||
plugin.getSupport().removeMoney(player, cost);
|
||||
@ -1005,7 +1005,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, Methods.fromBase64(data.getString("Items." + i + ".Item")), Reaons.PLAYER_FORCE_CANCEL);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
int num = 1;
|
||||
for (; data.contains("OutOfTime/Cancelled." + num); num++) ;
|
||||
@ -1069,7 +1069,7 @@ public class GuiListener implements Listener {
|
||||
player.sendMessage(Messages.INVENTORY_FULL.getMessage());
|
||||
break;
|
||||
} else {
|
||||
player.getInventory().addItem(ItemStack.deserializeBytes(Base64.getDecoder().decode(data.getString("OutOfTime/Cancelled." + i + ".Item"))));
|
||||
player.getInventory().addItem(Methods.fromBase64(data.getString("OutOfTime/Cancelled." + i + ".Item")));
|
||||
data.set("OutOfTime/Cancelled." + i, null);
|
||||
}
|
||||
}
|
||||
@ -1102,7 +1102,7 @@ public class GuiListener implements Listener {
|
||||
if (id == ID) {
|
||||
if (!Methods.isInvFull(player)) {
|
||||
player.sendMessage(Messages.GOT_ITEM_BACK.getMessage());
|
||||
player.getInventory().addItem(ItemStack.deserializeBytes(Base64.getDecoder().decode(data.getString("OutOfTime/Cancelled." + i + ".Item"))));
|
||||
player.getInventory().addItem(Methods.fromBase64(data.getString("OutOfTime/Cancelled." + i + ".Item")));
|
||||
data.set("OutOfTime/Cancelled." + i, null);
|
||||
Files.DATA.saveFile();
|
||||
playClick(player);
|
||||
|
Loading…
Reference in New Issue
Block a user