mirror of
https://github.com/Crazy-Crew/CrazyAuctions.git
synced 2025-01-22 21:41:28 +01:00
Current code
This commit is contained in:
parent
023be7ea5e
commit
e13d318720
@ -0,0 +1,86 @@
|
||||
package com.badbones69.crazyauctions.api.auctionhouse.objects;
|
||||
|
||||
import com.badbones69.crazyauctions.utils.ItemUtils;
|
||||
import net.dehya.ruby.items.ItemBuilder;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public class AuctionButtons {
|
||||
|
||||
private ItemBuilder sellingItemsButton;
|
||||
private ItemBuilder sellingInfoButton;
|
||||
private ItemBuilder biddingInfoButton;
|
||||
private ItemBuilder currentListingsInfoButton;
|
||||
private ItemBuilder expiredItemsButton;
|
||||
private ItemBuilder expiredInfoButton;
|
||||
private ItemBuilder categoriesButton;
|
||||
private ItemBuilder categoriesInfoButton;
|
||||
private ItemBuilder nextPageButton;
|
||||
private ItemBuilder refreshPageButton;
|
||||
private ItemBuilder backPageButton;
|
||||
private ItemBuilder switchModeButton;
|
||||
|
||||
public AuctionButtons(FileConfiguration file) {
|
||||
String path = "auction-house.settings.buttons.";
|
||||
sellingItemsButton = ItemUtils.convertString(file.getString(path + "selling-items"));
|
||||
sellingInfoButton = ItemUtils.convertString(file.getString(path + "info.selling-items"));
|
||||
biddingInfoButton = ItemUtils.convertString(file.getString(path + "info.bidding"));
|
||||
currentListingsInfoButton = ItemUtils.convertString(file.getString(path + "info.current-listings"));
|
||||
expiredItemsButton = ItemUtils.convertString(file.getString(path + "expired-items"));
|
||||
expiredInfoButton = ItemUtils.convertString(file.getString(path + "info.expired-items"));
|
||||
categoriesButton = ItemUtils.convertString(file.getString(path + "categories"));
|
||||
categoriesInfoButton = ItemUtils.convertString(file.getString(path + "info.categories"));
|
||||
nextPageButton = ItemUtils.convertString(file.getString(path + "next-page"));
|
||||
refreshPageButton = ItemUtils.convertString(file.getString(path + "refresh-page"));
|
||||
backPageButton = ItemUtils.convertString(file.getString(path + "back-page"));
|
||||
switchModeButton = ItemUtils.convertString(file.getString(path + "switch-mode"));
|
||||
}
|
||||
|
||||
public ItemBuilder getSellingItemsButton() {
|
||||
return sellingItemsButton;
|
||||
}
|
||||
|
||||
public ItemBuilder getSellingInfoButton() {
|
||||
return sellingInfoButton;
|
||||
}
|
||||
|
||||
public ItemBuilder getBiddingInfoButton() {
|
||||
return biddingInfoButton;
|
||||
}
|
||||
|
||||
public ItemBuilder getCurrentListingsInfoButton() {
|
||||
return currentListingsInfoButton;
|
||||
}
|
||||
|
||||
public ItemBuilder getExpiredItemsButton() {
|
||||
return expiredItemsButton;
|
||||
}
|
||||
|
||||
public ItemBuilder getExpiredInfoButton() {
|
||||
return expiredInfoButton;
|
||||
}
|
||||
|
||||
public ItemBuilder getCategoriesButton() {
|
||||
return categoriesButton;
|
||||
}
|
||||
|
||||
public ItemBuilder getCategoriesInfoButton() {
|
||||
return categoriesInfoButton;
|
||||
}
|
||||
|
||||
public ItemBuilder getNextPageButton() {
|
||||
return nextPageButton;
|
||||
}
|
||||
|
||||
public ItemBuilder getRefreshPageButton() {
|
||||
return refreshPageButton;
|
||||
}
|
||||
|
||||
public ItemBuilder getBackPageButton() {
|
||||
return backPageButton;
|
||||
}
|
||||
|
||||
public ItemBuilder getSwitchModeButton() {
|
||||
return switchModeButton;
|
||||
}
|
||||
|
||||
}
|
@ -2,7 +2,11 @@ package com.badbones69.crazyauctions.api.auctionhouse.objects;
|
||||
|
||||
import com.badbones69.crazyauctions.api.auctionhouse.enums.AuctionType;
|
||||
import com.badbones69.crazyauctions.api.auctionhouse.interfaces.AuctionItem;
|
||||
import org.simpleyaml.configuration.file.YamlFile;
|
||||
import com.badbones69.crazyauctions.api.auctionhouse.objects.auctiontype.BiddingAuction;
|
||||
import com.badbones69.crazyauctions.api.auctionhouse.objects.auctiontype.SellingAuction;
|
||||
import com.badbones69.crazyauctions.api.events.AuctionAddEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -11,27 +15,55 @@ import java.util.UUID;
|
||||
public class AuctionHouse {
|
||||
|
||||
private String name;
|
||||
private FileConfiguration auctionFile;
|
||||
private InventorySettings inventorySettings;
|
||||
private List<AuctionItem> auctionItems = new ArrayList<>();
|
||||
|
||||
public AuctionHouse(String name, YamlFile file) {
|
||||
this.name = name;
|
||||
this.inventorySettings = new InventorySettings();
|
||||
inventorySettings.setTitle("Set Title Here with Color");
|
||||
public AuctionHouse(FileConfiguration file) {
|
||||
this.name = file.getString("auction-house.settings.name");
|
||||
this.auctionFile = file;
|
||||
this.inventorySettings = new InventorySettings(file);
|
||||
for (String auctionID : file.getConfigurationSection("auction-house.item-on-auction").getKeys(false)) {
|
||||
String path = "auction-house.item-on-auction" + auctionID + ".";
|
||||
AuctionType auctionType = AuctionType.getTypeFromName(file.getString(path + "auction-type"));
|
||||
if (auctionType == AuctionType.SELL) {
|
||||
auctionItems.add(new BuyingAuction(
|
||||
UUID.fromString(file.getString(path + "UUID")),
|
||||
auctionItems.add(new SellingAuction(
|
||||
UUID.fromString(file.getString(path + "seller-uuid")),
|
||||
file.getLong(path + "price"),
|
||||
file.getLong(path + "expire-time"),
|
||||
file.getI(path + "")
|
||||
));
|
||||
file.getItemStack(path + "selling-item")));
|
||||
} else {
|
||||
|
||||
auctionItems.add(new BiddingAuction(
|
||||
UUID.fromString(file.getString(path + "seller-uuid")),
|
||||
UUID.fromString(file.getString(path + "highest-bidder-uuid")),
|
||||
file.getLong(path + "price"),
|
||||
file.getLong(path + "current-bid"),
|
||||
file.getLong(path + "expire-time"),
|
||||
file.getItemStack(path + "selling-item")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public FileConfiguration getAuctionFile() {
|
||||
return auctionFile;
|
||||
}
|
||||
|
||||
public InventorySettings getInventorySettings() {
|
||||
return inventorySettings;
|
||||
}
|
||||
|
||||
public List<AuctionItem> getAuctionItems() {
|
||||
return auctionItems;
|
||||
}
|
||||
|
||||
public void addAuctionItem(AuctionItem auctionItem) {
|
||||
auctionItems.add(auctionItem);
|
||||
AuctionAddEvent event = new AuctionAddEvent(auctionItem.getSeller(), this, auctionItem);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
|
||||
}
|
@ -1,15 +1,24 @@
|
||||
package com.badbones69.crazyauctions.api.auctionhouse.objects;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public class InventorySettings {
|
||||
|
||||
private String title;
|
||||
private AuctionButtons auctionButtons;
|
||||
|
||||
public InventorySettings(FileConfiguration file) {
|
||||
String path = "auction-house.settings.";
|
||||
this.title = file.getString(path + "inventory-title");
|
||||
this.auctionButtons = new AuctionButtons(file);
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
public AuctionButtons getAuctionButtons() {
|
||||
return auctionButtons;
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.badbones69.crazyauctions.api.auctionhouse.objects;
|
||||
package com.badbones69.crazyauctions.api.auctionhouse.objects.auctiontype;
|
||||
|
||||
import com.badbones69.crazyauctions.api.auctionhouse.enums.AuctionType;
|
||||
import com.badbones69.crazyauctions.api.auctionhouse.interfaces.AuctionItem;
|
||||
@ -6,7 +6,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class SellingAuction implements AuctionItem {
|
||||
public class BiddingAuction implements AuctionItem {
|
||||
|
||||
AuctionType auctionType = AuctionType.BID;
|
||||
UUID seller;
|
||||
@ -16,9 +16,9 @@ public class SellingAuction implements AuctionItem {
|
||||
long expireTime;
|
||||
ItemStack sellingItem;
|
||||
|
||||
public SellingAuction(UUID seller, long price, long expireTime, ItemStack sellingItem) {
|
||||
public BiddingAuction(UUID seller, UUID highestBidder, long price, long currentBid, long expireTime, ItemStack sellingItem) {
|
||||
this.seller = seller;
|
||||
this.highestBidder = null;
|
||||
this.highestBidder = highestBidder;
|
||||
this.price = price;
|
||||
this.currentBid = 0;
|
||||
this.expireTime = expireTime;
|
@ -1,4 +1,4 @@
|
||||
package com.badbones69.crazyauctions.api.auctionhouse.objects;
|
||||
package com.badbones69.crazyauctions.api.auctionhouse.objects.auctiontype;
|
||||
|
||||
import com.badbones69.crazyauctions.api.auctionhouse.enums.AuctionType;
|
||||
import com.badbones69.crazyauctions.api.auctionhouse.interfaces.AuctionItem;
|
||||
@ -6,7 +6,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class BuyingAuction implements AuctionItem {
|
||||
public class SellingAuction implements AuctionItem {
|
||||
|
||||
AuctionType auctionType = AuctionType.SELL;
|
||||
UUID seller;
|
||||
@ -14,7 +14,7 @@ public class BuyingAuction implements AuctionItem {
|
||||
long expireTime;
|
||||
ItemStack sellingItem;
|
||||
|
||||
public BuyingAuction(UUID seller, long price, long expireTime, ItemStack sellingItem) {
|
||||
public SellingAuction(UUID seller, long price, long expireTime, ItemStack sellingItem) {
|
||||
this.seller = seller;
|
||||
this.price = price;
|
||||
this.expireTime = expireTime;
|
@ -0,0 +1,64 @@
|
||||
package com.badbones69.crazyauctions.api.events;
|
||||
|
||||
import com.badbones69.crazyauctions.api.auctionhouse.interfaces.AuctionItem;
|
||||
import com.badbones69.crazyauctions.api.auctionhouse.objects.AuctionHouse;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ryder Belserion
|
||||
*
|
||||
* This event is fired when a item is added to a auction house.
|
||||
*
|
||||
*/
|
||||
public class AuctionAddEvent extends Event {
|
||||
|
||||
private static final HandlerList handlerList = new HandlerList();
|
||||
|
||||
private final UUID uuid;
|
||||
private final Player player;
|
||||
private final AuctionItem auctionItem;
|
||||
private final AuctionHouse auctionHouse;
|
||||
|
||||
/**
|
||||
* A constructor to include values for a bid event.
|
||||
*
|
||||
* @param uuid the uuid of the player who placed the bid.
|
||||
* @param auctionHouse the auction house the item is being added to.
|
||||
* @param auctionItem the auction item being added.
|
||||
*/
|
||||
public AuctionAddEvent(UUID uuid, AuctionHouse auctionHouse, AuctionItem auctionItem) {
|
||||
this.uuid = uuid;
|
||||
this.player = Bukkit.getPlayer(uuid);
|
||||
this.auctionHouse = auctionHouse;
|
||||
this.auctionItem = auctionItem;
|
||||
}
|
||||
|
||||
public AuctionItem getAuctionItem() {
|
||||
return auctionItem;
|
||||
}
|
||||
|
||||
public AuctionHouse getAuctionHouse() {
|
||||
return auctionHouse;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlerList;
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +1,99 @@
|
||||
package com.badbones69.crazyauctions.utils;
|
||||
|
||||
import com.badbones69.crazyauctions.api.enums.ServerVersion;
|
||||
import net.dehya.ruby.items.ItemBuilder;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
import org.bukkit.block.banner.PatternType;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemUtils {
|
||||
|
||||
public static Material getMaterial(String newMaterial, String oldMaterial) {
|
||||
return Material.matchMaterial(ServerVersion.isAtLeast(ServerVersion.v1_12) ? newMaterial : oldMaterial);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string to an ItemBuilder with a placeholder for errors.
|
||||
*
|
||||
* @param itemString The String you wish to convert.
|
||||
* @return The String as an ItemBuilder.
|
||||
*/
|
||||
public static ItemBuilder convertString(String itemString) {
|
||||
ItemBuilder itemBuilder = new ItemBuilder();
|
||||
|
||||
try {
|
||||
for (String optionString : itemString.split(", ")) {
|
||||
String option = optionString.split(":")[0];
|
||||
String value = optionString.replace(option + ":", "").replace(option, "");
|
||||
|
||||
switch (option.toLowerCase()) {
|
||||
case "item":
|
||||
itemBuilder.setValue(value);
|
||||
break;
|
||||
case "name":
|
||||
itemBuilder.setDisplayName(value);
|
||||
break;
|
||||
case "amount":
|
||||
try {
|
||||
itemBuilder.setAmount(Integer.parseInt(value));
|
||||
} catch (NumberFormatException e) {
|
||||
itemBuilder.setAmount(1);
|
||||
}
|
||||
break;
|
||||
case "lore":
|
||||
itemBuilder.setLore(Arrays.asList(value.split(",")));
|
||||
break;
|
||||
case "player":
|
||||
//itemBuilder.setp(value);
|
||||
break;
|
||||
case "unbreakable-item":
|
||||
//if (value.isEmpty() || value.equalsIgnoreCase("true")) itemBuilder.setUnbreakable(true);
|
||||
break;
|
||||
default:
|
||||
// Enchantment enchantment = getEnchantment(option);
|
||||
//
|
||||
// if (enchantment != null && enchantment.getName() != null) {
|
||||
// try {
|
||||
// itemBuilder.addEnchantments(enchantment, Integer.parseInt(value));
|
||||
// } catch (NumberFormatException e) {
|
||||
// itemBuilder.addEnchantments(enchantment, 1);
|
||||
// }
|
||||
//
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// for (ItemFlag itemFlag : ItemFlag.values()) {
|
||||
// if (itemFlag.name().equalsIgnoreCase(option)) {
|
||||
// itemBuilder.addItemFlags(Arrays.asList(itemFlag.name()));
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// for (PatternType pattern : PatternType.values()) {
|
||||
// if (option.equalsIgnoreCase(pattern.name()) || value.equalsIgnoreCase(pattern.getIdentifier())) {
|
||||
// DyeColor color = getDyeColor(value);
|
||||
// if (color != null) itemBuilder.addPattern(new Pattern(color, pattern));
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception ignored) {
|
||||
// }
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
itemBuilder.setMaterial(Material.RED_TERRACOTTA).setDisplayName("&c&lERROR").setLore(Arrays.asList("&cThere is an error", "&cFor : &c" + (placeHolder != null ? placeHolder : "")));
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return itemBuilder;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user