mirror of
https://github.com/kiranhart/Auction-House.git
synced 2024-11-25 05:55:13 +01:00
Lots and lots of changes, along with bugs, not even close to finished
This commit is contained in:
parent
f0ba148672
commit
86930efb15
@ -1,6 +1,7 @@
|
||||
package com.shadebyte.auctionhouse;
|
||||
|
||||
import com.massivestats.MassiveStats;
|
||||
import com.shadebyte.auctionhouse.api.event.AuctionEndEvent;
|
||||
import com.shadebyte.auctionhouse.auction.AuctionItem;
|
||||
import com.shadebyte.auctionhouse.cmds.CommandManager;
|
||||
import com.shadebyte.auctionhouse.events.AGUIListener;
|
||||
@ -9,13 +10,15 @@ import com.shadebyte.auctionhouse.util.Debugger;
|
||||
import com.shadebyte.auctionhouse.util.Locale;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public final class Core extends JavaPlugin {
|
||||
|
||||
@ -45,6 +48,8 @@ public final class Core extends JavaPlugin {
|
||||
// Plugin startup logic
|
||||
instance = this;
|
||||
|
||||
setupEconomy();
|
||||
|
||||
//Locales
|
||||
Locale.init(this);
|
||||
Locale.saveDefaultLocale("en_US");
|
||||
@ -68,11 +73,53 @@ public final class Core extends JavaPlugin {
|
||||
}
|
||||
|
||||
try {
|
||||
Bukkit.getServer().getScheduler().runTaskTimer(this, () -> {
|
||||
auctionItems.forEach(auctionItem -> auctionItem.updateTime(5));
|
||||
auctionItems.forEach(auctionItem -> {
|
||||
if (auctionItem.getTime() <= 0) auctionItems.remove(auctionItem);
|
||||
|
||||
ConfigurationSection section = data.getConfig().getConfigurationSection("active");
|
||||
if (section.getKeys(false).size() != 0) {
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(this, () -> {
|
||||
for (String node : section.getKeys(false)) {
|
||||
int xNode = Integer.parseInt(node);
|
||||
String owner = data.getConfig().getString("active." + xNode + ".owner");
|
||||
ItemStack stack = data.getConfig().getItemStack("active." + xNode + ".item");
|
||||
int startPrice = data.getConfig().getInt("active." + xNode + ".startprice");
|
||||
int bidIncrement = data.getConfig().getInt("active." + xNode + ".bidincrement");
|
||||
int buyNowPrice = data.getConfig().getInt("active." + xNode + ".buynowprice");
|
||||
int currentPrice = data.getConfig().getInt("active." + xNode + ".currentprice");
|
||||
int time = data.getConfig().getInt("active." + xNode + ".time");
|
||||
String key = data.getConfig().getString("active." + xNode + ".key");
|
||||
|
||||
AuctionItem item = new AuctionItem(owner, stack, startPrice, bidIncrement, buyNowPrice, currentPrice, time, key);
|
||||
auctionItems.add(item);
|
||||
data.getConfig().set("active." + xNode, null);
|
||||
}
|
||||
data.saveConfig();
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Debugger.report(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(this, () -> {
|
||||
if (auctionItems.size() != 0) {
|
||||
auctionItems.forEach(auctionItem -> auctionItem.updateTime(5));
|
||||
for (AuctionItem auctionItem : auctionItems) {
|
||||
if (auctionItem.getTime() <= 0) {
|
||||
AuctionEndEvent auctionEndEvent = new AuctionEndEvent(auctionItem);
|
||||
getServer().getPluginManager().callEvent(auctionEndEvent);
|
||||
if (!auctionEndEvent.isCancelled()) {
|
||||
if (auctionItem.getHighestBidder().equalsIgnoreCase("")) {
|
||||
data.getConfig().set("expired." + auctionItem.getOwner() + "." + System.currentTimeMillis() + System.nanoTime(), auctionItem.getItem());
|
||||
data.saveConfig();
|
||||
auctionItems.remove(auctionItem);
|
||||
} else {
|
||||
//TODO give highest bidder item
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 0, 20 * 5);
|
||||
} catch (Exception e) {
|
||||
//Debugger.report(e);
|
||||
@ -82,7 +129,23 @@ public final class Core extends JavaPlugin {
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
instance = null;
|
||||
|
||||
//Save Auctions to file.
|
||||
int node = 1;
|
||||
for (AuctionItem auctionItem : auctionItems) {
|
||||
data.getConfig().set("active." + node + ".owner", auctionItem.getOwner());
|
||||
data.getConfig().set("active." + node + ".startprice", auctionItem.getStartPrice());
|
||||
data.getConfig().set("active." + node + ".bidincrement", auctionItem.getBidIncrement());
|
||||
data.getConfig().set("active." + node + ".currentprice", auctionItem.getCurrentPrice());
|
||||
data.getConfig().set("active." + node + ".buynowprice", auctionItem.getBuyNowPrice());
|
||||
data.getConfig().set("active." + node + ".key", auctionItem.getKey());
|
||||
data.getConfig().set("active." + node + ".time", auctionItem.getTime());
|
||||
data.getConfig().set("active." + node + ".item", auctionItem.getItem());
|
||||
node++;
|
||||
}
|
||||
|
||||
data.saveConfig();
|
||||
|
||||
}
|
||||
|
||||
private boolean setupEconomy() {
|
||||
@ -102,7 +165,7 @@ public final class Core extends JavaPlugin {
|
||||
saveDefaultConfig();
|
||||
data = new ConfigWrapper(this, "", "data.yml");
|
||||
if (!new File(this.getDataFolder(), "data.yml").exists()) {
|
||||
data.getConfig().createSection("data");
|
||||
data.getConfig().createSection("active");
|
||||
}
|
||||
data.saveConfig();
|
||||
}
|
||||
@ -113,7 +176,7 @@ public final class Core extends JavaPlugin {
|
||||
}
|
||||
|
||||
private void initStorage() {
|
||||
auctionItems = new ArrayList<>();
|
||||
auctionItems = new CopyOnWriteArrayList<>();
|
||||
}
|
||||
|
||||
public static Core getInstance() {
|
||||
|
@ -2,6 +2,7 @@ package com.shadebyte.auctionhouse.api;
|
||||
|
||||
import com.shadebyte.auctionhouse.Core;
|
||||
import com.shadebyte.auctionhouse.api.enums.Version;
|
||||
import com.shadebyte.auctionhouse.util.Debugger;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -9,6 +10,8 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -20,6 +23,8 @@ import java.util.List;
|
||||
*/
|
||||
public class AuctionAPI {
|
||||
|
||||
private static char[] c = new char[]{'k', 'm', 'b', 't'};
|
||||
|
||||
private static AuctionAPI instance;
|
||||
|
||||
private AuctionAPI() {
|
||||
@ -32,13 +37,15 @@ public class AuctionAPI {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ItemStack createConfigItem(String node) {
|
||||
public ItemStack createConfigItem(String node, int activeAuctions, int expiredAuctions) {
|
||||
String[] rawItem = Core.getInstance().getConfig().getString(node + ".item").split(":");
|
||||
ItemStack stack = new ItemStack(Material.valueOf(rawItem[0].toUpperCase()), 1, Short.parseShort(rawItem[1]));
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', Core.getInstance().getConfig().getString(node + ".name")));
|
||||
List<String> lore = new ArrayList<>();
|
||||
Core.getInstance().getConfig().getStringList(node + ".lore").forEach(s -> lore.add(ChatColor.translateAlternateColorCodes('&', s)));
|
||||
Core.getInstance().getConfig().getStringList(node + ".lore").forEach(s -> lore.add(ChatColor.translateAlternateColorCodes('&', s
|
||||
.replace("{active_player_auctions}", String.valueOf(activeAuctions))
|
||||
.replace("{expired_player_auctions}", String.valueOf(expiredAuctions)))));
|
||||
meta.setLore(lore);
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
@ -54,6 +61,16 @@ public class AuctionAPI {
|
||||
return count;
|
||||
}
|
||||
|
||||
public boolean isNumeric(String number) {
|
||||
try {
|
||||
Double.parseDouble(number);
|
||||
} catch (NumberFormatException nfe) {
|
||||
Debugger.report(nfe);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static ItemStack getItemInHand(Player player) {
|
||||
if (Version.getCurrentVersion().getCurrentVersionInteger() >= Version.v1_9_R1.getCurrentVersionInteger()) {
|
||||
@ -79,6 +96,19 @@ public class AuctionAPI {
|
||||
return String.format("%02d:%02d:%02d", hours, minutes, seconds);
|
||||
}
|
||||
|
||||
public String friendlyNumber(double value) {
|
||||
int power;
|
||||
String suffix = " kmbt";
|
||||
String formattedNumber = "";
|
||||
|
||||
NumberFormat formatter = new DecimalFormat("#,###.#");
|
||||
power = (int) StrictMath.log10(value);
|
||||
value = value / (Math.pow(10, (power / 3) * 3));
|
||||
formattedNumber = formatter.format(value);
|
||||
formattedNumber = formattedNumber + suffix.charAt(power / 3);
|
||||
return formattedNumber.length() > 4 ? formattedNumber.replaceAll("\\.[0-9]+", "") : formattedNumber;
|
||||
}
|
||||
|
||||
public ItemStack fill(String name) {
|
||||
ItemStack stack = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 1);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
@ -86,4 +116,12 @@ public class AuctionAPI {
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public ItemStack fill(String name, int color) {
|
||||
ItemStack stack = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) color);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&6&l" + name));
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,13 @@ public enum Lang {
|
||||
PREFIX("prefix"),
|
||||
NO_PERMISSION("nopermission"),
|
||||
PLAYERS_ONLY("playersonly"),
|
||||
NOT_A_NUMBER("notanumber"),
|
||||
NOT_ENOUGH_MONEY("notenoughmoney"),
|
||||
|
||||
AUCTION_LISTED("auction.listed"),
|
||||
AUCTION_BUY("auction.buy"),
|
||||
AUCTION_MAX("auction.max"),
|
||||
AUCTION_SOLD("auction.sold"),
|
||||
|
||||
INVALID_SUBCOMMAND("cmd.invalid"),
|
||||
CMD_SELL("cmd.sell"),
|
||||
|
@ -1,10 +1,48 @@
|
||||
package com.shadebyte.auctionhouse.api.event;
|
||||
|
||||
import com.shadebyte.auctionhouse.auction.AuctionItem;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/6/2018
|
||||
* Time Created: 11:54 AM
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
public class AuctionEndEvent {
|
||||
public class AuctionEndEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
|
||||
private AuctionItem auctionItem;
|
||||
|
||||
public AuctionEndEvent(AuctionItem auctionItem) {
|
||||
this.auctionItem = auctionItem;
|
||||
}
|
||||
|
||||
public AuctionItem getAuctionItem() {
|
||||
return auctionItem;
|
||||
}
|
||||
|
||||
public void setAuctionItem(AuctionItem auctionItem) {
|
||||
this.auctionItem = auctionItem;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
public void setCancelled(boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.shadebyte.auctionhouse.auction;
|
||||
|
||||
import com.shadebyte.auctionhouse.api.AuctionAPI;
|
||||
import com.shadebyte.auctionhouse.util.NBTEditor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@ -21,43 +22,45 @@ import static org.bukkit.ChatColor.translateAlternateColorCodes;
|
||||
*/
|
||||
public class AuctionItem {
|
||||
|
||||
private Player owner;
|
||||
private String owner;
|
||||
private String highestBidder;
|
||||
private ItemStack item;
|
||||
private int startPrice;
|
||||
private int bidIncrement;
|
||||
private int buyNowPrice;
|
||||
private int currentPrice;
|
||||
private int time = 0;
|
||||
private int time;
|
||||
private String key;
|
||||
|
||||
public AuctionItem(ItemStack item, int time, int startPrice, int bidIncrement, int buyNowPrice) {
|
||||
this.owner = null;
|
||||
this.item = item.clone();
|
||||
public AuctionItem(String owner, ItemStack item, int startPrice, int bidIncrement, int buyNowPrice, int currentPrice, int time, String key) {
|
||||
this.owner = owner;
|
||||
this.item = item;
|
||||
this.startPrice = startPrice;
|
||||
this.bidIncrement = bidIncrement;
|
||||
this.bidIncrement = bidIncrement;
|
||||
this.buyNowPrice = buyNowPrice;
|
||||
this.time = time;
|
||||
key = UUID.randomUUID().toString();
|
||||
this.currentPrice = currentPrice;
|
||||
this.key = key;
|
||||
this.highestBidder = owner;
|
||||
}
|
||||
|
||||
public AuctionItem(Player owner, ItemStack item, int time, int startPrice, int bidIncrement, int buyNowPrice) {
|
||||
public AuctionItem(String owner, ItemStack item, int time, int startPrice, int bidIncrement, int buyNowPrice) {
|
||||
this.owner = owner;
|
||||
this.item = item.clone();
|
||||
this.startPrice = startPrice;
|
||||
this.bidIncrement = bidIncrement;
|
||||
this.bidIncrement = bidIncrement;
|
||||
this.buyNowPrice = buyNowPrice;
|
||||
this.time = time;
|
||||
this.currentPrice = startPrice;
|
||||
key = UUID.randomUUID().toString();
|
||||
this.highestBidder = owner;
|
||||
}
|
||||
|
||||
public Player getOwner() {
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(Player owner) {
|
||||
public void setOwner(String owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@ -113,6 +116,14 @@ public class AuctionItem {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getHighestBidder() {
|
||||
return highestBidder;
|
||||
}
|
||||
|
||||
public void setHighestBidder(String highestBidder) {
|
||||
this.highestBidder = highestBidder;
|
||||
}
|
||||
|
||||
public void updateTime(int removeAmount) {
|
||||
if (time - removeAmount <= 0) {
|
||||
time = 0;
|
||||
@ -135,11 +146,11 @@ public class AuctionItem {
|
||||
if (owner == null)
|
||||
lore.add(translateAlternateColorCodes('&', "&eSeller&f: &bSample User"));
|
||||
else
|
||||
lore.add(translateAlternateColorCodes('&', "&eSeller&f: &b" + owner.getName()));
|
||||
lore.add(translateAlternateColorCodes('&', "&eSeller&f: &b" + Bukkit.getOfflinePlayer(UUID.fromString(owner)).getName()));
|
||||
lore.add(translateAlternateColorCodes('&', ""));
|
||||
lore.add(translateAlternateColorCodes('&', "&eBuy Now: &a$" + NumberFormat.getInstance().format(buyNowPrice)));
|
||||
lore.add(translateAlternateColorCodes('&', "&eCurrent Price: &a$" + NumberFormat.getInstance().format(currentPrice)));
|
||||
lore.add(translateAlternateColorCodes('&', "&eBid Increment: &a$" + NumberFormat.getInstance().format(bidIncrement)));
|
||||
lore.add(translateAlternateColorCodes('&', "&eBuy Now: &a$" + AuctionAPI.getInstance().friendlyNumber(buyNowPrice)));
|
||||
lore.add(translateAlternateColorCodes('&', "&eCurrent Price: &a$" + AuctionAPI.getInstance().friendlyNumber(currentPrice)));
|
||||
lore.add(translateAlternateColorCodes('&', "&eBid Increment: &a$" + AuctionAPI.getInstance().friendlyNumber(bidIncrement)));
|
||||
lore.add(translateAlternateColorCodes('&', ""));
|
||||
lore.add(translateAlternateColorCodes('&', "&eTime Left: &b" + AuctionAPI.getInstance().timeLeft(getTime())));
|
||||
lore.add(translateAlternateColorCodes('&', "&7-------------------------"));
|
||||
@ -151,4 +162,5 @@ public class AuctionItem {
|
||||
stack = NBTEditor.setItemTag(stack, getKey(), "AuctionItemKey");
|
||||
return stack;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.shadebyte.auctionhouse.auction;
|
||||
|
||||
import com.shadebyte.auctionhouse.Core;
|
||||
import com.shadebyte.auctionhouse.api.enums.Permissions;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -24,7 +25,7 @@ public class AuctionPlayer {
|
||||
public int getTotalActiveAuctions() {
|
||||
int total = 0;
|
||||
for (AuctionItem item : Core.getInstance().auctionItems) {
|
||||
if (item.getOwner().getUniqueId().equals(player.getUniqueId())) {
|
||||
if (item.getOwner().equals(player.getUniqueId().toString())) {
|
||||
total++;
|
||||
}
|
||||
}
|
||||
@ -34,13 +35,21 @@ public class AuctionPlayer {
|
||||
public List<AuctionItem> getAuctionItems() {
|
||||
List<AuctionItem> list = new ArrayList<>();
|
||||
for (AuctionItem item : Core.getInstance().auctionItems) {
|
||||
if (item.getOwner().getUniqueId().equals(player.getUniqueId())) {
|
||||
if (item.getOwner().equals(player.getUniqueId().toString())) {
|
||||
list.add(item);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public int getTotalExpiredAuctions() {
|
||||
int total;
|
||||
ConfigurationSection section = Core.getInstance().getData().getConfig().getConfigurationSection("expired." + player.getUniqueId().toString());
|
||||
total = (section != null) ? section.getKeys(false).size() : 0;
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasMaximumAuctionsActive() {
|
||||
if (!player.hasPermission(Permissions.MAX_AUCTIONS.getNode() + "." + getTotalActiveAuctions())) {
|
||||
return true;
|
||||
|
@ -41,7 +41,7 @@ public class SellCommand extends SubCommand {
|
||||
int buyNow = Integer.parseInt(args[1]);
|
||||
int startPrice = Integer.parseInt(args[2]);
|
||||
int increment = Integer.parseInt(args[3]);
|
||||
Core.getInstance().auctionItems.add(0, new AuctionItem(p, AuctionAPI.getItemInHand(p), 3600, startPrice, increment, buyNow));
|
||||
Core.getInstance().auctionItems.add(0, new AuctionItem(p.getUniqueId().toString(), AuctionAPI.getItemInHand(p), 3600, startPrice, increment, buyNow));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
|
||||
import com.shadebyte.auctionhouse.Core;
|
||||
import com.shadebyte.auctionhouse.api.AuctionAPI;
|
||||
import com.shadebyte.auctionhouse.auction.AuctionItem;
|
||||
import com.shadebyte.auctionhouse.auction.AuctionPlayer;
|
||||
import com.shadebyte.auctionhouse.inventory.AGUI;
|
||||
import com.shadebyte.auctionhouse.util.NBTEditor;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -48,10 +49,12 @@ public class AuctionGUI implements AGUI {
|
||||
e.setCancelled(true);
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
|
||||
|
||||
if (page >= 1 && slot == 48) p.openInventory(this.setPage(this.getPage() - 1).getInventory());
|
||||
if (page >= 1 && slot == 50) p.openInventory(this.setPage(this.getPage() + 1).getInventory());
|
||||
|
||||
try {
|
||||
if (page >= 1 && slot == 48) p.openInventory(this.setPage(this.getPage() - 1).getInventory());
|
||||
if (page >= 1 && slot == 50) p.openInventory(this.setPage(this.getPage() + 1).getInventory());
|
||||
} catch (Exception ex) {
|
||||
//Hide for now
|
||||
}
|
||||
|
||||
if (slot == 49) {
|
||||
p.closeInventory();
|
||||
@ -71,7 +74,19 @@ public class AuctionGUI implements AGUI {
|
||||
if (auctionItem.getKey().equalsIgnoreCase(key)) item = auctionItem;
|
||||
}
|
||||
|
||||
if (Core.getEconomy().getBalance(p) < item.getBidIncrement()) {
|
||||
e.getClickedInventory().setItem(slot, AuctionAPI.getInstance().createConfigItem("gui.auction.items.not-enough-money", 0, 0));
|
||||
Bukkit.getServer().getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||
p.closeInventory();
|
||||
p.openInventory(AuctionGUI.getInstance(p).getInventory());
|
||||
}, 1);
|
||||
|
||||
// p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.NOT_ENOUGH_MONEY.getNode()));
|
||||
return;
|
||||
}
|
||||
|
||||
item.setCurrentPrice(item.getCurrentPrice() + item.getBidIncrement());
|
||||
item.setHighestBidder(p.getUniqueId().toString());
|
||||
p.closeInventory();
|
||||
p.openInventory(AuctionGUI.getInstance(p).getInventory());
|
||||
}
|
||||
@ -82,12 +97,14 @@ public class AuctionGUI implements AGUI {
|
||||
if (auctionItem.getKey().equalsIgnoreCase(key)) item = auctionItem;
|
||||
}
|
||||
|
||||
p.getInventory().addItem(item.getItem());
|
||||
item.setTime(0);
|
||||
Core.getInstance().auctionItems.remove(item);
|
||||
|
||||
p.closeInventory();
|
||||
p.openInventory(AuctionGUI.getInstance(p).getInventory());
|
||||
p.openInventory(ConfirmationGUI.getInstance(item).getInventory());
|
||||
// p.getInventory().addItem(item.getItem());
|
||||
// item.setTime(0);
|
||||
// Core.getInstance().auctionItems.remove(item);
|
||||
//
|
||||
// p.closeInventory();
|
||||
// p.openInventory(AuctionGUI.getInstance(p).getInventory());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -102,13 +119,13 @@ public class AuctionGUI implements AGUI {
|
||||
Inventory inventory = Bukkit.createInventory(this, 54, ChatColor.translateAlternateColorCodes('&', Core.getInstance().getConfig().getString("gui.auction.title")));
|
||||
|
||||
//Bottom Row
|
||||
inventory.setItem(45, AuctionAPI.getInstance().createConfigItem("gui.auction.items.yourauctions"));
|
||||
inventory.setItem(46, AuctionAPI.getInstance().createConfigItem("gui.auction.items.collectionbin"));
|
||||
inventory.setItem(48, AuctionAPI.getInstance().createConfigItem("gui.auction.items.previouspage"));
|
||||
inventory.setItem(49, AuctionAPI.getInstance().createConfigItem("gui.auction.items.refresh"));
|
||||
inventory.setItem(50, AuctionAPI.getInstance().createConfigItem("gui.auction.items.nextpage"));
|
||||
inventory.setItem(52, AuctionAPI.getInstance().createConfigItem("gui.auction.items.howtosell"));
|
||||
inventory.setItem(53, AuctionAPI.getInstance().createConfigItem("gui.auction.items.guide"));
|
||||
inventory.setItem(45, AuctionAPI.getInstance().createConfigItem("gui.auction.items.yourauctions", new AuctionPlayer(p).getTotalActiveAuctions(), 0));
|
||||
inventory.setItem(46, AuctionAPI.getInstance().createConfigItem("gui.auction.items.collectionbin", 0, new AuctionPlayer(p).getTotalExpiredAuctions()));
|
||||
inventory.setItem(48, AuctionAPI.getInstance().createConfigItem("gui.auction.items.previouspage", 0, 0));
|
||||
inventory.setItem(49, AuctionAPI.getInstance().createConfigItem("gui.auction.items.refresh", 0, 0));
|
||||
inventory.setItem(50, AuctionAPI.getInstance().createConfigItem("gui.auction.items.nextpage", 0, 0));
|
||||
inventory.setItem(52, AuctionAPI.getInstance().createConfigItem("gui.auction.items.howtosell", 0, 0));
|
||||
inventory.setItem(53, AuctionAPI.getInstance().createConfigItem("gui.auction.items.guide", 0, 0));
|
||||
|
||||
//Pagination
|
||||
List<List<AuctionItem>> chunks = Lists.partition(Core.getInstance().auctionItems, 45);
|
||||
|
@ -1,10 +1,62 @@
|
||||
package com.shadebyte.auctionhouse.inventory.inventories;
|
||||
|
||||
import com.shadebyte.auctionhouse.Core;
|
||||
import com.shadebyte.auctionhouse.api.AuctionAPI;
|
||||
import com.shadebyte.auctionhouse.auction.AuctionItem;
|
||||
import com.shadebyte.auctionhouse.inventory.AGUI;
|
||||
import org.apache.commons.lang.math.IntRange;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/6/2018
|
||||
* Time Created: 11:56 AM
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
public class ConfirmationGUI {
|
||||
public class ConfirmationGUI implements AGUI {
|
||||
|
||||
private static ConfirmationGUI instance;
|
||||
private AuctionItem auctionItem;
|
||||
|
||||
private ConfirmationGUI(AuctionItem auctionItem) {
|
||||
this.auctionItem = auctionItem;
|
||||
}
|
||||
|
||||
public static ConfirmationGUI getInstance(AuctionItem auctionItem) {
|
||||
if (instance == null) {
|
||||
instance = new ConfirmationGUI(auctionItem);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click(InventoryClickEvent e, ItemStack clicked, int slot) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(InventoryCloseEvent e) {
|
||||
Bukkit.getServer().getScheduler().runTaskLater(Core.getInstance(), () -> e.getPlayer().openInventory(e.getInventory()),1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
Inventory inventory = Bukkit.createInventory(this, 9, Core.getInstance().getConfig().getString("gui.confirm.title"));
|
||||
for (int i = 0; i <= 3; i++) {
|
||||
inventory.setItem(i, AuctionAPI.getInstance().fill("&a&lYes", 5));
|
||||
}
|
||||
|
||||
for (int i = 5; i <= 8; i++) {
|
||||
inventory.setItem(i, AuctionAPI.getInstance().fill("&c&lNo", 14));
|
||||
}
|
||||
|
||||
inventory.setItem(4, auctionItem.getItem());
|
||||
return inventory;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,31 @@
|
||||
settings:
|
||||
default-auction-time: 3600 # 60 Minutes by default
|
||||
max-auction-price: 2000000000
|
||||
|
||||
|
||||
|
||||
gui:
|
||||
confirm:
|
||||
title: "&e&lConfirm Purchase"
|
||||
items:
|
||||
no:
|
||||
item: "STAINED_GLASS_PANE:14"
|
||||
name: "&C&LNo"
|
||||
lore:
|
||||
- "&7Do not purchase this item."
|
||||
yes:
|
||||
item: "STAINED_GLASS_PANE:5"
|
||||
name: "&a&lYes"
|
||||
lore:
|
||||
- "&7Purchase for &a${price}"
|
||||
auction:
|
||||
title: "&7Auction House"
|
||||
items:
|
||||
not-enough-money:
|
||||
item: "STAINED_GLASS_PANE:14"
|
||||
name: "&c&lError"
|
||||
lore:
|
||||
- "&cYou do not have enough money!"
|
||||
guide:
|
||||
item: "BOOK:0"
|
||||
name: "&e&lGuide"
|
||||
|
@ -1,7 +1,14 @@
|
||||
prefix = "&8[eAuctionHouse&8]"
|
||||
prefix = "&8[&eAuctionHouse&8]"
|
||||
|
||||
cmd.invalid = "&cThat isn't a valid subcommand!"
|
||||
cmd.sell = "&e/ah sell <buyNowPrice> <startPrice> <bidIncrement>"
|
||||
|
||||
nopermission = "&cYou do not have permission to do that!"
|
||||
playersonly = "&cOnly player's may use the command!"
|
||||
playersonly = "&cOnly player's may use the command!"
|
||||
notanumber = "&CThat isn't a valid number"
|
||||
notenoughmoney = "&CYou do not have enough money!"
|
||||
|
||||
auction.listed = "&eYou listed &6{itemname} &efor &a${price}"
|
||||
auction.max = "&cYou cannot auction more items, please upgrade to do so."
|
||||
auction.buy = "&eYou purchased &6{itemname} &Efor &A${price}"
|
||||
auction.sold = "&6{player} &Ehas bought your listed item: &6{item} &efor &a${price}"
|
Loading…
Reference in New Issue
Block a user