mirror of
https://github.com/kiranhart/Auction-House.git
synced 2025-01-21 15:01:19 +01:00
Work for July 10 2018, added checks and cases for when auctions end, assigning items correctly.
This commit is contained in:
parent
86930efb15
commit
4fdb61d53f
13
.idea/libraries/Maven__com_zaxxer_HikariCP_3_2_0.xml
Normal file
13
.idea/libraries/Maven__com_zaxxer_HikariCP_3_2_0.xml
Normal 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>
|
@ -1,13 +1,13 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Maven: net.md-5:bungeecord-chat:1.12-SNAPSHOT">
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
</library>
|
||||
</component>
|
13
.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml
Normal file
13
.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml
Normal 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>
|
@ -1,13 +1,13 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Maven: org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT">
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
</library>
|
||||
</component>
|
@ -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.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" 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>
|
||||
</module>
|
6
pom.xml
6
pom.xml
@ -87,5 +87,11 @@
|
||||
<version>1.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>LATEST</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.shadebyte.auctionhouse;
|
||||
|
||||
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.auction.AuctionItem;
|
||||
import com.shadebyte.auctionhouse.cmds.CommandManager;
|
||||
@ -10,7 +12,10 @@ 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.ChatColor;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.HorseInventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
@ -18,6 +23,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public final class Core extends JavaPlugin {
|
||||
@ -43,22 +49,27 @@ public final class Core extends JavaPlugin {
|
||||
//Storage
|
||||
public List<AuctionItem> auctionItems;
|
||||
|
||||
//Timing
|
||||
private Long startTime;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
instance = this;
|
||||
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&bStarted to load Auction Items from data file."));
|
||||
startTime = System.currentTimeMillis();
|
||||
|
||||
setupEconomy();
|
||||
initDataFiles();
|
||||
|
||||
//Locales
|
||||
Locale.init(this);
|
||||
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();
|
||||
|
||||
initDataFiles();
|
||||
|
||||
commandManager = new CommandManager();
|
||||
commandManager.initialize();
|
||||
|
||||
@ -73,10 +84,9 @@ public final class Core extends JavaPlugin {
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
ConfigurationSection section = data.getConfig().getConfigurationSection("active");
|
||||
if (section.getKeys(false).size() != 0) {
|
||||
|
||||
int size = section.getKeys(false).size();
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(this, () -> {
|
||||
for (String node : section.getKeys(false)) {
|
||||
int xNode = Integer.parseInt(node);
|
||||
@ -88,18 +98,23 @@ public final class Core extends JavaPlugin {
|
||||
int currentPrice = data.getConfig().getInt("active." + xNode + ".currentprice");
|
||||
int time = data.getConfig().getInt("active." + xNode + ".time");
|
||||
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);
|
||||
data.getConfig().set("active." + xNode, null);
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&eLoaded Auction Item with key&f: &b" + item.getKey()));
|
||||
}
|
||||
data.saveConfig();
|
||||
});
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&eLoaded a total of &f: &b" + size + "&e items"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Debugger.report(e);
|
||||
}
|
||||
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&bAuction House finished loading, took " + (System.currentTimeMillis() - startTime) + " ms"));
|
||||
|
||||
try {
|
||||
Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(this, () -> {
|
||||
if (auctionItems.size() != 0) {
|
||||
@ -109,12 +124,34 @@ public final class Core extends JavaPlugin {
|
||||
AuctionEndEvent auctionEndEvent = new AuctionEndEvent(auctionItem);
|
||||
getServer().getPluginManager().callEvent(auctionEndEvent);
|
||||
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.saveConfig();
|
||||
auctionItems.remove(auctionItem);
|
||||
} 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;
|
||||
for (AuctionItem auctionItem : auctionItems) {
|
||||
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 + ".bidincrement", auctionItem.getBidIncrement());
|
||||
data.getConfig().set("active." + node + ".currentprice", auctionItem.getCurrentPrice());
|
||||
@ -145,7 +183,6 @@ public final class Core extends JavaPlugin {
|
||||
}
|
||||
|
||||
data.saveConfig();
|
||||
|
||||
}
|
||||
|
||||
private boolean setupEconomy() {
|
||||
|
@ -63,7 +63,7 @@ public class AuctionAPI {
|
||||
|
||||
public boolean isNumeric(String number) {
|
||||
try {
|
||||
Double.parseDouble(number);
|
||||
Integer.parseInt(number);
|
||||
} catch (NumberFormatException nfe) {
|
||||
Debugger.report(nfe);
|
||||
return false;
|
||||
@ -98,7 +98,7 @@ public class AuctionAPI {
|
||||
|
||||
public String friendlyNumber(double value) {
|
||||
int power;
|
||||
String suffix = " kmbt";
|
||||
String suffix = " KMBT";
|
||||
String formattedNumber = "";
|
||||
|
||||
NumberFormat formatter = new DecimalFormat("#,###.#");
|
||||
|
@ -13,6 +13,8 @@ public enum Lang {
|
||||
PLAYERS_ONLY("playersonly"),
|
||||
NOT_A_NUMBER("notanumber"),
|
||||
NOT_ENOUGH_MONEY("notenoughmoney"),
|
||||
CANNOT_BUY_OWN("cantbuyown"),
|
||||
CANNOT_BID_OWN("cantbidonown"),
|
||||
|
||||
AUCTION_LISTED("auction.listed"),
|
||||
AUCTION_BUY("auction.buy"),
|
||||
|
@ -2,12 +2,11 @@ package com.shadebyte.auctionhouse.auction;
|
||||
|
||||
import com.shadebyte.auctionhouse.api.AuctionAPI;
|
||||
import com.shadebyte.auctionhouse.util.NBTEditor;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -32,7 +31,7 @@ public class AuctionItem {
|
||||
private int time;
|
||||
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.item = item;
|
||||
this.startPrice = startPrice;
|
||||
@ -41,7 +40,7 @@ public class AuctionItem {
|
||||
this.time = time;
|
||||
this.currentPrice = currentPrice;
|
||||
this.key = key;
|
||||
this.highestBidder = owner;
|
||||
this.highestBidder = highestBidder;
|
||||
}
|
||||
|
||||
public AuctionItem(String owner, ItemStack item, int time, int startPrice, int bidIncrement, int buyNowPrice) {
|
||||
@ -124,6 +123,19 @@ public class AuctionItem {
|
||||
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) {
|
||||
if (time - removeAmount <= 0) {
|
||||
time = 0;
|
||||
|
@ -5,6 +5,7 @@ import com.shadebyte.auctionhouse.api.AuctionAPI;
|
||||
import com.shadebyte.auctionhouse.api.enums.Lang;
|
||||
import com.shadebyte.auctionhouse.api.enums.Permissions;
|
||||
import com.shadebyte.auctionhouse.auction.AuctionItem;
|
||||
import com.shadebyte.auctionhouse.auction.AuctionPlayer;
|
||||
import com.shadebyte.auctionhouse.cmds.SubCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -37,11 +38,38 @@ public class SellCommand extends SubCommand {
|
||||
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) {
|
||||
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.getUniqueId().toString(), AuctionAPI.getItemInHand(p), 3600, startPrice, increment, buyNow));
|
||||
if (AuctionAPI.getInstance().isNumeric(args[1]) && AuctionAPI.getInstance().isNumeric(args[2]) && AuctionAPI.getInstance().isNumeric(args[3])) {
|
||||
if (new AuctionPlayer(p).hasMaximumAuctionsActive()) {
|
||||
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.AUCTION_MAX.getNode()));
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package com.shadebyte.auctionhouse.inventory.inventories;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.shadebyte.auctionhouse.Core;
|
||||
import com.shadebyte.auctionhouse.api.AuctionAPI;
|
||||
import com.shadebyte.auctionhouse.api.enums.Lang;
|
||||
import com.shadebyte.auctionhouse.auction.AuctionItem;
|
||||
import com.shadebyte.auctionhouse.auction.AuctionPlayer;
|
||||
import com.shadebyte.auctionhouse.inventory.AGUI;
|
||||
@ -76,17 +77,28 @@ public class AuctionGUI implements AGUI {
|
||||
|
||||
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(), () -> {
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(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()));
|
||||
}, 20);
|
||||
return;
|
||||
}
|
||||
|
||||
item.setCurrentPrice(item.getCurrentPrice() + item.getBidIncrement());
|
||||
item.setHighestBidder(p.getUniqueId().toString());
|
||||
if (item.getOwner().equalsIgnoreCase(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.openInventory(AuctionGUI.getInstance(p).getInventory());
|
||||
}
|
||||
@ -97,14 +109,26 @@ public class AuctionGUI implements AGUI {
|
||||
if (auctionItem.getKey().equalsIgnoreCase(key)) item = auctionItem;
|
||||
}
|
||||
|
||||
p.closeInventory();
|
||||
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());
|
||||
if (Core.getEconomy().getBalance(p) < item.getBuyNowPrice()) {
|
||||
e.getClickedInventory().setItem(slot, AuctionAPI.getInstance().createConfigItem("gui.auction.items.not-enough-money", 0, 0));
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(Core.getInstance(), () -> {
|
||||
p.closeInventory();
|
||||
p.openInventory(AuctionGUI.getInstance(p).getInventory());
|
||||
}, 20);
|
||||
return;
|
||||
} 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,16 +2,18 @@ package com.shadebyte.auctionhouse.inventory.inventories;
|
||||
|
||||
import com.shadebyte.auctionhouse.Core;
|
||||
import com.shadebyte.auctionhouse.api.AuctionAPI;
|
||||
import com.shadebyte.auctionhouse.api.enums.Lang;
|
||||
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.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
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;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
@ -38,16 +40,40 @@ public class ConfirmationGUI implements AGUI {
|
||||
@Override
|
||||
public void click(InventoryClickEvent e, ItemStack clicked, int slot) {
|
||||
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
|
||||
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
|
||||
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++) {
|
||||
inventory.setItem(i, AuctionAPI.getInstance().fill("&a&lYes", 5));
|
||||
}
|
||||
|
@ -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:
|
||||
default-auction-time: 3600 # 60 Minutes by default
|
||||
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:
|
||||
confirm:
|
||||
|
@ -7,6 +7,8 @@ nopermission = "&cYou do not have permission to do that!"
|
||||
playersonly = "&cOnly player's may use the command!"
|
||||
notanumber = "&CThat isn't a valid number"
|
||||
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.max = "&cYou cannot auction more items, please upgrade to do so."
|
||||
|
Loading…
Reference in New Issue
Block a user