Work for July 10 2018, added checks and cases for when auctions end, assigning items correctly.

This commit is contained in:
Kiran Hart 2018-07-10 20:41:36 -04:00
parent 86930efb15
commit 4fdb61d53f
15 changed files with 224 additions and 45 deletions

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: com.zaxxer:HikariCP:3.2.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/zaxxer/HikariCP/3.2.0/HikariCP-3.2.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/zaxxer/HikariCP/3.2.0/HikariCP-3.2.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/zaxxer/HikariCP/3.2.0/HikariCP-3.2.0-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +1,13 @@
<component name="libraryTable"> <component name="libraryTable">
<library name="Maven: net.md-5:bungeecord-chat:1.12-SNAPSHOT"> <library name="Maven: net.md-5:bungeecord-chat:1.12-SNAPSHOT">
<CLASSES> <CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180621.025251-89.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180709.025335-94.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC> <JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180621.025251-89-javadoc.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180709.025335-94-javadoc.jar!/" />
</JAVADOC> </JAVADOC>
<SOURCES> <SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180621.025251-89-sources.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180709.025335-94-sources.jar!/" />
</SOURCES> </SOURCES>
</library> </library>
</component> </component>

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.slf4j:slf4j-api:1.7.25">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +1,13 @@
<component name="libraryTable"> <component name="libraryTable">
<library name="Maven: org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT"> <library name="Maven: org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT">
<CLASSES> <CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/spigotmc/spigot-api/1.12.2-R0.1-SNAPSHOT/spigot-api-1.12.2-R0.1-20180627.103100-150.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/org/spigotmc/spigot-api/1.12.2-R0.1-SNAPSHOT/spigot-api-1.12.2-R0.1-20180710.022400-153.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC> <JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/spigotmc/spigot-api/1.12.2-R0.1-SNAPSHOT/spigot-api-1.12.2-R0.1-20180627.103100-150-javadoc.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/org/spigotmc/spigot-api/1.12.2-R0.1-SNAPSHOT/spigot-api-1.12.2-R0.1-20180710.022400-153-javadoc.jar!/" />
</JAVADOC> </JAVADOC>
<SOURCES> <SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/spigotmc/spigot-api/1.12.2-R0.1-SNAPSHOT/spigot-api-1.12.2-R0.1-20180627.103100-150-sources.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/org/spigotmc/spigot-api/1.12.2-R0.1-SNAPSHOT/spigot-api-1.12.2-R0.1-20180710.022400-153-sources.jar!/" />
</SOURCES> </SOURCES>
</library> </library>
</component> </component>

View File

@ -35,5 +35,7 @@
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.9-R0.1-SNAPSHOT" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.9-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.avaje:ebean:2.8.1" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: org.avaje:ebean:2.8.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.persistence:persistence-api:1.0" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: javax.persistence:persistence-api:1.0" level="project" />
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:3.2.0" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
</component> </component>
</module> </module>

View File

@ -87,5 +87,11 @@
<version>1.6</version> <version>1.6</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>LATEST</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,6 +1,8 @@
package com.shadebyte.auctionhouse; package com.shadebyte.auctionhouse;
import com.massivestats.MassiveStats; import com.massivestats.MassiveStats;
import com.shadebyte.auctionhouse.api.AuctionAPI;
import com.shadebyte.auctionhouse.api.enums.Lang;
import com.shadebyte.auctionhouse.api.event.AuctionEndEvent; import com.shadebyte.auctionhouse.api.event.AuctionEndEvent;
import com.shadebyte.auctionhouse.auction.AuctionItem; import com.shadebyte.auctionhouse.auction.AuctionItem;
import com.shadebyte.auctionhouse.cmds.CommandManager; import com.shadebyte.auctionhouse.cmds.CommandManager;
@ -10,7 +12,10 @@ import com.shadebyte.auctionhouse.util.Debugger;
import com.shadebyte.auctionhouse.util.Locale; import com.shadebyte.auctionhouse.util.Locale;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.HorseInventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
@ -18,6 +23,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
public final class Core extends JavaPlugin { public final class Core extends JavaPlugin {
@ -43,22 +49,27 @@ public final class Core extends JavaPlugin {
//Storage //Storage
public List<AuctionItem> auctionItems; public List<AuctionItem> auctionItems;
//Timing
private Long startTime;
@Override @Override
public void onEnable() { public void onEnable() {
// Plugin startup logic // Plugin startup logic
instance = this; instance = this;
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&bStarted to load Auction Items from data file."));
startTime = System.currentTimeMillis();
setupEconomy(); setupEconomy();
initDataFiles();
//Locales //Locales
Locale.init(this); Locale.init(this);
Locale.saveDefaultLocale("en_US"); Locale.saveDefaultLocale("en_US");
this.locale = Locale.getLocale(this.getConfig().getString("Locale", "en_US")); this.locale = Locale.getLocale(this.getConfig().getString("Locale", getConfig().getString("lang")));
settings = new Settings(); settings = new Settings();
initDataFiles();
commandManager = new CommandManager(); commandManager = new CommandManager();
commandManager.initialize(); commandManager.initialize();
@ -73,10 +84,9 @@ public final class Core extends JavaPlugin {
} }
try { try {
ConfigurationSection section = data.getConfig().getConfigurationSection("active"); ConfigurationSection section = data.getConfig().getConfigurationSection("active");
if (section.getKeys(false).size() != 0) { if (section.getKeys(false).size() != 0) {
int size = section.getKeys(false).size();
Bukkit.getServer().getScheduler().runTaskAsynchronously(this, () -> { Bukkit.getServer().getScheduler().runTaskAsynchronously(this, () -> {
for (String node : section.getKeys(false)) { for (String node : section.getKeys(false)) {
int xNode = Integer.parseInt(node); int xNode = Integer.parseInt(node);
@ -88,18 +98,23 @@ public final class Core extends JavaPlugin {
int currentPrice = data.getConfig().getInt("active." + xNode + ".currentprice"); int currentPrice = data.getConfig().getInt("active." + xNode + ".currentprice");
int time = data.getConfig().getInt("active." + xNode + ".time"); int time = data.getConfig().getInt("active." + xNode + ".time");
String key = data.getConfig().getString("active." + xNode + ".key"); String key = data.getConfig().getString("active." + xNode + ".key");
String highestBidder = data.getConfig().getString("active." + xNode + ".highestbidder");
AuctionItem item = new AuctionItem(owner, stack, startPrice, bidIncrement, buyNowPrice, currentPrice, time, key); AuctionItem item = new AuctionItem(owner, highestBidder, stack, startPrice, bidIncrement, buyNowPrice, currentPrice, time, key);
auctionItems.add(item); auctionItems.add(item);
data.getConfig().set("active." + xNode, null); data.getConfig().set("active." + xNode, null);
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&eLoaded Auction Item with key&f: &b" + item.getKey()));
} }
data.saveConfig(); data.saveConfig();
}); });
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&eLoaded a total of &f: &b" + size + "&e items"));
} }
} catch (Exception e) { } catch (Exception e) {
Debugger.report(e); Debugger.report(e);
} }
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&bAuction House finished loading, took " + (System.currentTimeMillis() - startTime) + " ms"));
try { try {
Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(this, () -> { Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(this, () -> {
if (auctionItems.size() != 0) { if (auctionItems.size() != 0) {
@ -109,12 +124,34 @@ public final class Core extends JavaPlugin {
AuctionEndEvent auctionEndEvent = new AuctionEndEvent(auctionItem); AuctionEndEvent auctionEndEvent = new AuctionEndEvent(auctionItem);
getServer().getPluginManager().callEvent(auctionEndEvent); getServer().getPluginManager().callEvent(auctionEndEvent);
if (!auctionEndEvent.isCancelled()) { if (!auctionEndEvent.isCancelled()) {
if (auctionItem.getHighestBidder().equalsIgnoreCase("")) { if (auctionItem.getHighestBidder().equalsIgnoreCase(auctionItem.getOwner())) {
data.getConfig().set("expired." + auctionItem.getOwner() + "." + System.currentTimeMillis() + System.nanoTime(), auctionItem.getItem()); data.getConfig().set("expired." + auctionItem.getOwner() + "." + System.currentTimeMillis() + System.nanoTime(), auctionItem.getItem());
data.saveConfig(); data.saveConfig();
auctionItems.remove(auctionItem); auctionItems.remove(auctionItem);
} else { } else {
//TODO give highest bidder item Player highestBidder = Bukkit.getPlayer(UUID.fromString(auctionItem.getHighestBidder()));
if (highestBidder != null) {
if (getEconomy().getBalance(highestBidder) < auctionItem.getCurrentPrice()) {
highestBidder.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.NOT_ENOUGH_MONEY.getNode()));
data.getConfig().set("expired." + auctionItem.getOwner() + "." + System.currentTimeMillis() + System.nanoTime(), auctionItem.getItem());
} else {
highestBidder.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.AUCTION_BUY.getNode()).replace("{itemname}", auctionItem.getDisplayName()).replace("{price}", AuctionAPI.getInstance().friendlyNumber(auctionItem.getCurrentPrice())));
if (AuctionAPI.getInstance().availableSlots(highestBidder.getInventory()) < 1)
highestBidder.getWorld().dropItemNaturally(highestBidder.getLocation(), auctionItem.getItem());
else
highestBidder.getInventory().addItem(auctionItem.getItem());
}
data.saveConfig();
auctionItems.remove(auctionItem);
} else {
if (getEconomy().getBalance(highestBidder) < auctionItem.getCurrentPrice()) {
data.getConfig().set("expired." + auctionItem.getOwner() + "." + System.currentTimeMillis() + System.nanoTime(), auctionItem.getItem());
} else {
data.getConfig().set("expired." + auctionItem.getHighestBidder() + "." + System.currentTimeMillis() + System.nanoTime(), auctionItem.getItem());
}
data.saveConfig();
auctionItems.remove(auctionItem);
}
} }
} }
} }
@ -134,6 +171,7 @@ public final class Core extends JavaPlugin {
int node = 1; int node = 1;
for (AuctionItem auctionItem : auctionItems) { for (AuctionItem auctionItem : auctionItems) {
data.getConfig().set("active." + node + ".owner", auctionItem.getOwner()); data.getConfig().set("active." + node + ".owner", auctionItem.getOwner());
data.getConfig().set("active." + node + ".highestbidder", auctionItem.getHighestBidder());
data.getConfig().set("active." + node + ".startprice", auctionItem.getStartPrice()); data.getConfig().set("active." + node + ".startprice", auctionItem.getStartPrice());
data.getConfig().set("active." + node + ".bidincrement", auctionItem.getBidIncrement()); data.getConfig().set("active." + node + ".bidincrement", auctionItem.getBidIncrement());
data.getConfig().set("active." + node + ".currentprice", auctionItem.getCurrentPrice()); data.getConfig().set("active." + node + ".currentprice", auctionItem.getCurrentPrice());
@ -145,7 +183,6 @@ public final class Core extends JavaPlugin {
} }
data.saveConfig(); data.saveConfig();
} }
private boolean setupEconomy() { private boolean setupEconomy() {

View File

@ -63,7 +63,7 @@ public class AuctionAPI {
public boolean isNumeric(String number) { public boolean isNumeric(String number) {
try { try {
Double.parseDouble(number); Integer.parseInt(number);
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
Debugger.report(nfe); Debugger.report(nfe);
return false; return false;
@ -98,7 +98,7 @@ public class AuctionAPI {
public String friendlyNumber(double value) { public String friendlyNumber(double value) {
int power; int power;
String suffix = " kmbt"; String suffix = " KMBT";
String formattedNumber = ""; String formattedNumber = "";
NumberFormat formatter = new DecimalFormat("#,###.#"); NumberFormat formatter = new DecimalFormat("#,###.#");

View File

@ -13,6 +13,8 @@ public enum Lang {
PLAYERS_ONLY("playersonly"), PLAYERS_ONLY("playersonly"),
NOT_A_NUMBER("notanumber"), NOT_A_NUMBER("notanumber"),
NOT_ENOUGH_MONEY("notenoughmoney"), NOT_ENOUGH_MONEY("notenoughmoney"),
CANNOT_BUY_OWN("cantbuyown"),
CANNOT_BID_OWN("cantbidonown"),
AUCTION_LISTED("auction.listed"), AUCTION_LISTED("auction.listed"),
AUCTION_BUY("auction.buy"), AUCTION_BUY("auction.buy"),

View File

@ -2,12 +2,11 @@ package com.shadebyte.auctionhouse.auction;
import com.shadebyte.auctionhouse.api.AuctionAPI; import com.shadebyte.auctionhouse.api.AuctionAPI;
import com.shadebyte.auctionhouse.util.NBTEditor; import com.shadebyte.auctionhouse.util.NBTEditor;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import java.text.NumberFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -32,7 +31,7 @@ public class AuctionItem {
private int time; private int time;
private String key; private String key;
public AuctionItem(String owner, ItemStack item, int startPrice, int bidIncrement, int buyNowPrice, int currentPrice, int time, String key) { public AuctionItem(String owner, String highestBidder, ItemStack item, int startPrice, int bidIncrement, int buyNowPrice, int currentPrice, int time, String key) {
this.owner = owner; this.owner = owner;
this.item = item; this.item = item;
this.startPrice = startPrice; this.startPrice = startPrice;
@ -41,7 +40,7 @@ public class AuctionItem {
this.time = time; this.time = time;
this.currentPrice = currentPrice; this.currentPrice = currentPrice;
this.key = key; this.key = key;
this.highestBidder = owner; this.highestBidder = highestBidder;
} }
public AuctionItem(String 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) {
@ -124,6 +123,19 @@ public class AuctionItem {
this.highestBidder = highestBidder; this.highestBidder = highestBidder;
} }
public String getDisplayName() {
String name = key;
if (item.hasItemMeta()) {
if (item.getItemMeta().hasDisplayName())
name = item.getItemMeta().getDisplayName();
else
name = StringUtils.capitalize(item.getType().name().toLowerCase().replace("_", " "));
} else {
name = StringUtils.capitalize(item.getType().name().toLowerCase().replace("_", " "));
}
return name;
}
public void updateTime(int removeAmount) { public void updateTime(int removeAmount) {
if (time - removeAmount <= 0) { if (time - removeAmount <= 0) {
time = 0; time = 0;

View File

@ -5,6 +5,7 @@ import com.shadebyte.auctionhouse.api.AuctionAPI;
import com.shadebyte.auctionhouse.api.enums.Lang; import com.shadebyte.auctionhouse.api.enums.Lang;
import com.shadebyte.auctionhouse.api.enums.Permissions; import com.shadebyte.auctionhouse.api.enums.Permissions;
import com.shadebyte.auctionhouse.auction.AuctionItem; import com.shadebyte.auctionhouse.auction.AuctionItem;
import com.shadebyte.auctionhouse.auction.AuctionPlayer;
import com.shadebyte.auctionhouse.cmds.SubCommand; import com.shadebyte.auctionhouse.cmds.SubCommand;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -37,11 +38,38 @@ public class SellCommand extends SubCommand {
return; return;
} }
if (args.length == 2) {
if (AuctionAPI.getInstance().isNumeric(args[1])) {
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.CMD_SELL.getNode()));
} else {
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.NOT_A_NUMBER.getNode()));
}
}
if (args.length == 3) {
if (AuctionAPI.getInstance().isNumeric(args[1]) && AuctionAPI.getInstance().isNumeric(args[2])) {
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.CMD_SELL.getNode()));
} else {
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.NOT_A_NUMBER.getNode()));
}
}
if (args.length == 4) { if (args.length == 4) {
int buyNow = Integer.parseInt(args[1]); if (AuctionAPI.getInstance().isNumeric(args[1]) && AuctionAPI.getInstance().isNumeric(args[2]) && AuctionAPI.getInstance().isNumeric(args[3])) {
int startPrice = Integer.parseInt(args[2]); if (new AuctionPlayer(p).hasMaximumAuctionsActive()) {
int increment = Integer.parseInt(args[3]); p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.AUCTION_MAX.getNode()));
Core.getInstance().auctionItems.add(0, new AuctionItem(p.getUniqueId().toString(), AuctionAPI.getItemInHand(p), 3600, startPrice, increment, buyNow)); return;
}
int buyNow = Integer.parseInt(args[1]);
int startPrice = Integer.parseInt(args[2]);
int increment = Integer.parseInt(args[3]);
AuctionItem auctionItem = new AuctionItem(p.getUniqueId().toString(), AuctionAPI.getItemInHand(p), 3600, startPrice, increment, buyNow);
Core.getInstance().auctionItems.add(0, auctionItem);
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.AUCTION_LISTED.getNode()).replace("{itemname}", auctionItem.getDisplayName()).replace("{price}", AuctionAPI.getInstance().friendlyNumber(startPrice)));
} else {
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.NOT_A_NUMBER.getNode()));
}
} }
} }

View File

@ -3,6 +3,7 @@ package com.shadebyte.auctionhouse.inventory.inventories;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.shadebyte.auctionhouse.Core; import com.shadebyte.auctionhouse.Core;
import com.shadebyte.auctionhouse.api.AuctionAPI; import com.shadebyte.auctionhouse.api.AuctionAPI;
import com.shadebyte.auctionhouse.api.enums.Lang;
import com.shadebyte.auctionhouse.auction.AuctionItem; import com.shadebyte.auctionhouse.auction.AuctionItem;
import com.shadebyte.auctionhouse.auction.AuctionPlayer; import com.shadebyte.auctionhouse.auction.AuctionPlayer;
import com.shadebyte.auctionhouse.inventory.AGUI; import com.shadebyte.auctionhouse.inventory.AGUI;
@ -76,17 +77,28 @@ public class AuctionGUI implements AGUI {
if (Core.getEconomy().getBalance(p) < item.getBidIncrement()) { if (Core.getEconomy().getBalance(p) < item.getBidIncrement()) {
e.getClickedInventory().setItem(slot, AuctionAPI.getInstance().createConfigItem("gui.auction.items.not-enough-money", 0, 0)); e.getClickedInventory().setItem(slot, AuctionAPI.getInstance().createConfigItem("gui.auction.items.not-enough-money", 0, 0));
Bukkit.getServer().getScheduler().runTaskLater(Core.getInstance(), () -> { Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(Core.getInstance(), () -> {
p.closeInventory(); p.closeInventory();
p.openInventory(AuctionGUI.getInstance(p).getInventory()); p.openInventory(AuctionGUI.getInstance(p).getInventory());
}, 1); }, 20);
// p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.NOT_ENOUGH_MONEY.getNode()));
return; return;
} }
item.setCurrentPrice(item.getCurrentPrice() + item.getBidIncrement()); if (item.getOwner().equalsIgnoreCase(p.getUniqueId().toString())) {
item.setHighestBidder(p.getUniqueId().toString()); if (Core.getInstance().getConfig().getBoolean("settings.owner-can-bid-own")) {
item.setCurrentPrice(item.getCurrentPrice() + item.getBidIncrement());
item.setHighestBidder(p.getUniqueId().toString());
} else {
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.CANNOT_BID_OWN.getNode()));
}
} else {
item.setCurrentPrice(item.getCurrentPrice() + item.getBidIncrement());
item.setHighestBidder(p.getUniqueId().toString());
}
if (Core.getInstance().getConfig().getBoolean("settings.bid.increase-on-bid"))
item.setTime(item.getTime() + Core.getInstance().getConfig().getInt("settings.bid.increase-amount"));
p.closeInventory(); p.closeInventory();
p.openInventory(AuctionGUI.getInstance(p).getInventory()); p.openInventory(AuctionGUI.getInstance(p).getInventory());
} }
@ -97,14 +109,26 @@ public class AuctionGUI implements AGUI {
if (auctionItem.getKey().equalsIgnoreCase(key)) item = auctionItem; if (auctionItem.getKey().equalsIgnoreCase(key)) item = auctionItem;
} }
p.closeInventory(); if (Core.getEconomy().getBalance(p) < item.getBuyNowPrice()) {
p.openInventory(ConfirmationGUI.getInstance(item).getInventory()); e.getClickedInventory().setItem(slot, AuctionAPI.getInstance().createConfigItem("gui.auction.items.not-enough-money", 0, 0));
// p.getInventory().addItem(item.getItem()); Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(Core.getInstance(), () -> {
// item.setTime(0); p.closeInventory();
// Core.getInstance().auctionItems.remove(item); p.openInventory(AuctionGUI.getInstance(p).getInventory());
// }, 20);
// p.closeInventory(); return;
// p.openInventory(AuctionGUI.getInstance(p).getInventory()); } else {
if (item.getOwner().equalsIgnoreCase(p.getUniqueId().toString())) {
if (Core.getInstance().getConfig().getBoolean("settings.owner-can-purchase-own")) {
p.closeInventory();
p.openInventory(ConfirmationGUI.getInstance(item).getInventory());
} else {
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.CANNOT_BUY_OWN.getNode()));
}
} else {
p.closeInventory();
p.openInventory(ConfirmationGUI.getInstance(item).getInventory());
}
}
} }
} }
} }

View File

@ -2,16 +2,18 @@ package com.shadebyte.auctionhouse.inventory.inventories;
import com.shadebyte.auctionhouse.Core; import com.shadebyte.auctionhouse.Core;
import com.shadebyte.auctionhouse.api.AuctionAPI; import com.shadebyte.auctionhouse.api.AuctionAPI;
import com.shadebyte.auctionhouse.api.enums.Lang;
import com.shadebyte.auctionhouse.auction.AuctionItem; import com.shadebyte.auctionhouse.auction.AuctionItem;
import com.shadebyte.auctionhouse.inventory.AGUI; import com.shadebyte.auctionhouse.inventory.AGUI;
import org.apache.commons.lang.math.IntRange;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.stream.IntStream; import java.util.UUID;
/** /**
* The current file has been created by Kiran Hart * The current file has been created by Kiran Hart
@ -38,16 +40,40 @@ public class ConfirmationGUI implements AGUI {
@Override @Override
public void click(InventoryClickEvent e, ItemStack clicked, int slot) { public void click(InventoryClickEvent e, ItemStack clicked, int slot) {
e.setCancelled(true); e.setCancelled(true);
Player p = (Player) e.getWhoClicked();
if (clicked.isSimilar(AuctionAPI.getInstance().fill("&a&lYes", 5))) {
if (Core.getInstance().auctionItems.contains(auctionItem)) {
if (Core.getEconomy().getBalance(p) < auctionItem.getBuyNowPrice()) {
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.NOT_ENOUGH_MONEY.getNode()));
} else {
Core.getEconomy().withdrawPlayer(p, auctionItem.getBuyNowPrice());
p.getInventory().addItem(auctionItem.getItem());
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.AUCTION_BUY.getNode()).replace("{itemname}", auctionItem.getDisplayName()).replace("{price}", AuctionAPI.getInstance().friendlyNumber(auctionItem.getBuyNowPrice())));
Player owner = Bukkit.getPlayer(UUID.fromString(auctionItem.getOwner()));
if (owner != null) {
owner.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.AUCTION_SOLD.getNode()).replace("{player}", p.getName()).replace("{item}", auctionItem.getDisplayName()).replace("{price}", AuctionAPI.getInstance().friendlyNumber(auctionItem.getBuyNowPrice())));
}
auctionItem.setTime(0);
Core.getInstance().auctionItems.remove(auctionItem);
p.closeInventory();
}
}
} else if (clicked.isSimilar(AuctionAPI.getInstance().fill("&c&lNo", 14))) {
p.closeInventory();
p.openInventory(AuctionGUI.getInstance(p).getInventory());
}
} }
@Override @Override
public void close(InventoryCloseEvent e) { public void close(InventoryCloseEvent e) {
Bukkit.getServer().getScheduler().runTaskLater(Core.getInstance(), () -> e.getPlayer().openInventory(e.getInventory()),1); // Bukkit.getServer().getScheduler().runTaskLater(Core.getInstance(), () -> e.getPlayer().openInventory(e.getInventory()), 1);
} }
@Override @Override
public Inventory getInventory() { public Inventory getInventory() {
Inventory inventory = Bukkit.createInventory(this, 9, Core.getInstance().getConfig().getString("gui.confirm.title")); Inventory inventory = Bukkit.createInventory(this, 9, ChatColor.translateAlternateColorCodes('&', Core.getInstance().getConfig().getString("gui.confirm.title")));
for (int i = 0; i <= 3; i++) { for (int i = 0; i <= 3; i++) {
inventory.setItem(i, AuctionAPI.getInstance().fill("&a&lYes", 5)); inventory.setItem(i, AuctionAPI.getInstance().fill("&a&lYes", 5));
} }

View File

@ -1,8 +1,22 @@
#If this file (en_US.lang) is somehow missing it will load any other valid
#.lang file. It's safer to translate the original file change the name and
#have it in the same locale folder, just set new lang name here.
#Lang name formats: https://www.science.co.il/language/Locale-codes.php
lang: "en_US"
settings: settings:
default-auction-time: 3600 # 60 Minutes by default default-auction-time: 3600 # 60 Minutes by default
max-auction-price: 2000000000 max-auction-price: 2000000000
max-auction-start: 2000000000
max-auction-increment: 2000000000
min-auction-price: 25000
min-auction-start: 25000
min-auction-increment: 1
owner-can-purchase-own: false
owner-can-bid-own: false
bid:
increase-on-bid: true
increase-amount: 10 #10 Seconds by default
gui: gui:
confirm: confirm:

View File

@ -7,6 +7,8 @@ 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" notanumber = "&CThat isn't a valid number"
notenoughmoney = "&CYou do not have enough money!" notenoughmoney = "&CYou do not have enough money!"
cantbidonown = "&cYou cannot bid on your own item!"
cantbuyown = "&cYou cannot buy your own item!"
auction.listed = "&eYou listed &6{itemname} &efor &a${price}" auction.listed = "&eYou listed &6{itemname} &efor &a${price}"
auction.max = "&cYou cannot auction more items, please upgrade to do so." auction.max = "&cYou cannot auction more items, please upgrade to do so."