mirror of
https://github.com/kiranhart/Auction-House.git
synced 2025-01-06 12:37:56 +01:00
A lot of changes and additions...
This commit is contained in:
parent
736ccba204
commit
53cfee31eb
9
.idea/artifacts/AuctionHouse_jar.xml
Normal file
9
.idea/artifacts/AuctionHouse_jar.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="AuctionHouse:jar">
|
||||
<output-path />
|
||||
<root id="archive" name="auctionhouse.jar">
|
||||
<element id="module-output" name="auctionhouse" />
|
||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/github/kevinsawicki/http-request/6.0/http-request-6.0.jar" path-in-jar="/" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
@ -1,8 +0,0 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="Auction House:jar">
|
||||
<output-path>$USER_HOME$/Desktop/Plugin Testing/Pepper API/plugins</output-path>
|
||||
<root id="archive" name="Auction House.jar">
|
||||
<element id="module-output" name="Auction House" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
@ -6,11 +6,12 @@
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="Auction House" />
|
||||
<module name="auctionhouse" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
<bytecodeTargetLevel>
|
||||
<module name="Auction House" target="1.8" />
|
||||
<module name="auctionhouse" target="1.8" />
|
||||
</bytecodeTargetLevel>
|
||||
</component>
|
||||
</project>
|
7
.idea/inspectionProfiles/Project_Default.xml
Normal file
7
.idea/inspectionProfiles/Project_Default.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="DuplicateThrows" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="Duplicates" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||
</profile>
|
||||
</component>
|
@ -0,0 +1,13 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Maven: com.github.kevinsawicki:http-request:6.0">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/com/github/kevinsawicki/http-request/6.0/http-request-6.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/com/github/kevinsawicki/http-request/6.0/http-request-6.0-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/com/github/kevinsawicki/http-request/6.0/http-request-6.0-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
@ -1,13 +0,0 @@
|
||||
<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-20180709.025335-94.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180712.114550-97.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180709.025335-94-javadoc.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180712.114550-97-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180709.025335-94-sources.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180712.114550-97-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
13
.idea/libraries/Maven__org_projectlombok_lombok_1_16_12.xml
Normal file
13
.idea/libraries/Maven__org_projectlombok_lombok_1_16_12.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Maven: org.projectlombok:lombok:1.16.12">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.16.12/lombok-1.16.12.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.16.12/lombok-1.16.12-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.16.12/lombok-1.16.12-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
@ -1,13 +0,0 @@
|
||||
<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-20180710.022400-153.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/spigotmc/spigot-api/1.12.2-R0.1-SNAPSHOT/spigot-api-1.12.2-R0.1-20180712.012057-156.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-20180710.022400-153-javadoc.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/spigotmc/spigot-api/1.12.2-R0.1-SNAPSHOT/spigot-api-1.12.2-R0.1-20180712.012057-156-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-20180710.022400-153-sources.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/spigotmc/spigot-api/1.12.2-R0.1-SNAPSHOT/spigot-api-1.12.2-R0.1-20180712.012057-156-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
@ -2,7 +2,7 @@
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Auction House.iml" filepath="$PROJECT_DIR$/Auction House.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/auctionhouse.iml" filepath="$PROJECT_DIR$/auctionhouse.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -36,6 +36,6 @@
|
||||
<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" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
|
||||
</component>
|
||||
</module>
|
41
auctionhouse.iml
Normal file
41
auctionhouse.iml
Normal file
@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>SPIGOT</platformType>
|
||||
</autoDetectTypes>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: junit:junit:4.10" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:21.0" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.19" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.12-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-io:commons-io:2.4" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: net.milkbowl.vault:VaultAPI:1.6" 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: javax.persistence:persistence-api:1.0" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.16.12" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.kevinsawicki:http-request:6.0" level="project" />
|
||||
</component>
|
||||
</module>
|
13
pom.xml
13
pom.xml
@ -88,10 +88,15 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>LATEST</version>
|
||||
<scope>compile</scope>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.12</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.kevinsawicki</groupId>
|
||||
<artifactId>http-request</artifactId>
|
||||
<version>6.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -4,24 +4,30 @@ 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.AuctionStartEvent;
|
||||
import com.shadebyte.auctionhouse.api.event.TransactionCompleteEvent;
|
||||
import com.shadebyte.auctionhouse.auction.AuctionItem;
|
||||
import com.shadebyte.auctionhouse.auction.Transaction;
|
||||
import com.shadebyte.auctionhouse.cmds.CommandManager;
|
||||
import com.shadebyte.auctionhouse.events.AGUIListener;
|
||||
import com.shadebyte.auctionhouse.util.ConfigWrapper;
|
||||
import com.shadebyte.auctionhouse.events.TransactionListener;
|
||||
import com.shadebyte.auctionhouse.util.Debugger;
|
||||
import com.shadebyte.auctionhouse.util.Locale;
|
||||
import com.shadebyte.auctionhouse.util.storage.ConfigWrapper;
|
||||
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;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
@ -42,6 +48,7 @@ public final class Core extends JavaPlugin {
|
||||
|
||||
//Data config instance from the config wrapper
|
||||
private ConfigWrapper data;
|
||||
private ConfigWrapper transactions;
|
||||
|
||||
//Language system instance
|
||||
private Locale locale;
|
||||
@ -49,6 +56,12 @@ public final class Core extends JavaPlugin {
|
||||
//Storage
|
||||
public List<AuctionItem> auctionItems;
|
||||
|
||||
//Database
|
||||
private Connection connection;
|
||||
public String host, database, username, password;
|
||||
public int port;
|
||||
public boolean dbConnected;
|
||||
|
||||
//Timing
|
||||
private Long startTime;
|
||||
|
||||
@ -56,11 +69,17 @@ public final class Core extends JavaPlugin {
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
instance = this;
|
||||
dbConnected = false;
|
||||
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&bStarted to load Auction Items from data file."));
|
||||
startTime = System.currentTimeMillis();
|
||||
|
||||
setupEconomy();
|
||||
if (!setupEconomy()) {
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&cVault could not be loaded/was found. Disabling Auction House!"));
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
initDataFiles();
|
||||
|
||||
//Locales
|
||||
@ -76,6 +95,8 @@ public final class Core extends JavaPlugin {
|
||||
initEvents();
|
||||
initStorage();
|
||||
|
||||
if (getConfig().getBoolean("database.enabled")) mysqlSetup();
|
||||
|
||||
try {
|
||||
MassiveStats stats = new MassiveStats(this);
|
||||
stats.setListenerDisabled(false);
|
||||
@ -83,6 +104,54 @@ public final class Core extends JavaPlugin {
|
||||
Debugger.report(e);
|
||||
}
|
||||
|
||||
loadAuctions();
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&bAuction House finished loading, took " + (System.currentTimeMillis() - startTime) + " ms"));
|
||||
tickAuctions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
saveAuctions();
|
||||
}
|
||||
|
||||
|
||||
private void mysqlSetup() {
|
||||
host = this.getConfig().getString("database.host");
|
||||
port = this.getConfig().getInt("database.port");
|
||||
database = this.getConfig().getString("database.database");
|
||||
username = this.getConfig().getString("database.username");
|
||||
password = this.getConfig().getString("database.password");
|
||||
|
||||
try {
|
||||
|
||||
synchronized (this) {
|
||||
if (getConnection() != null && !getConnection().isClosed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
setConnection(DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password));
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&aSuccessfully Connected to MySQL"));
|
||||
dbConnected = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Debugger.report(e);
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&cCould not connect to MySQL"));
|
||||
} catch (ClassNotFoundException e) {
|
||||
Debugger.report(e);
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&cCould not connect to MySQL"));
|
||||
}
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
public void setConnection(Connection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
private void loadAuctions() {
|
||||
try {
|
||||
ConfigurationSection section = data.getConfig().getConfigurationSection("active");
|
||||
if (section.getKeys(false).size() != 0) {
|
||||
@ -103,6 +172,8 @@ public final class Core extends JavaPlugin {
|
||||
AuctionItem item = new AuctionItem(owner, highestBidder, stack, startPrice, bidIncrement, buyNowPrice, currentPrice, time, key);
|
||||
auctionItems.add(item);
|
||||
data.getConfig().set("active." + xNode, null);
|
||||
AuctionStartEvent auctionStartEvent = new AuctionStartEvent(item);
|
||||
getServer().getPluginManager().callEvent(auctionStartEvent);
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&eLoaded Auction Item with key&f: &b" + item.getKey()));
|
||||
}
|
||||
data.saveConfig();
|
||||
@ -112,9 +183,9 @@ public final class Core extends JavaPlugin {
|
||||
} catch (Exception e) {
|
||||
Debugger.report(e);
|
||||
}
|
||||
}
|
||||
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&bAuction House finished loading, took " + (System.currentTimeMillis() - startTime) + " ms"));
|
||||
|
||||
private void tickAuctions() {
|
||||
try {
|
||||
Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(this, () -> {
|
||||
if (auctionItems.size() != 0) {
|
||||
@ -125,7 +196,8 @@ public final class Core extends JavaPlugin {
|
||||
getServer().getPluginManager().callEvent(auctionEndEvent);
|
||||
if (!auctionEndEvent.isCancelled()) {
|
||||
if (auctionItem.getHighestBidder().equalsIgnoreCase(auctionItem.getOwner())) {
|
||||
data.getConfig().set("expired." + auctionItem.getOwner() + "." + System.currentTimeMillis() + System.nanoTime(), auctionItem.getItem());
|
||||
data.getConfig().set("expired." + auctionItem.getOwner() + "." + auctionItem.getKey() + ".item", auctionItem.getItem());
|
||||
data.getConfig().set("expired." + auctionItem.getOwner() + "." + auctionItem.getKey() + ".display", AuctionAPI.getInstance().expiredAuctionItem(auctionItem));
|
||||
data.saveConfig();
|
||||
auctionItems.remove(auctionItem);
|
||||
} else {
|
||||
@ -133,21 +205,30 @@ public final class Core extends JavaPlugin {
|
||||
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());
|
||||
data.getConfig().set("expired." + auctionItem.getOwner() + "." + auctionItem.getKey() + ".item", auctionItem.getItem());
|
||||
data.getConfig().set("expired." + auctionItem.getOwner() + "." + auctionItem.getKey() + ".display", AuctionAPI.getInstance().expiredAuctionItem(auctionItem));
|
||||
} 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());
|
||||
Transaction transaction = new Transaction(Transaction.TransactionType.AUCTION_WON, auctionItem, highestBidder.getUniqueId().toString(), System.currentTimeMillis());
|
||||
transaction.saveTransaction();
|
||||
getServer().getPluginManager().callEvent(new TransactionCompleteEvent(transaction));
|
||||
}
|
||||
data.saveConfig();
|
||||
auctionItems.remove(auctionItem);
|
||||
} else {
|
||||
if (getEconomy().getBalance(highestBidder) < auctionItem.getCurrentPrice()) {
|
||||
data.getConfig().set("expired." + auctionItem.getOwner() + "." + System.currentTimeMillis() + System.nanoTime(), auctionItem.getItem());
|
||||
data.getConfig().set("expired." + auctionItem.getOwner() + "." + auctionItem.getKey() + ".item", auctionItem.getItem());
|
||||
data.getConfig().set("expired." + auctionItem.getOwner() + "." + auctionItem.getKey() + ".display", AuctionAPI.getInstance().expiredAuctionItem(auctionItem));
|
||||
} else {
|
||||
data.getConfig().set("expired." + auctionItem.getHighestBidder() + "." + System.currentTimeMillis() + System.nanoTime(), auctionItem.getItem());
|
||||
data.getConfig().set("expired." + auctionItem.getHighestBidder() + "." + auctionItem.getKey() + ".item", auctionItem.getItem());
|
||||
data.getConfig().set("expired." + auctionItem.getHighestBidder() + "." + auctionItem.getKey() + ".display", AuctionAPI.getInstance().expiredAuctionItem(auctionItem));
|
||||
Transaction transaction = new Transaction(Transaction.TransactionType.AUCTION_WON, auctionItem, highestBidder.getUniqueId().toString(), System.currentTimeMillis());
|
||||
transaction.saveTransaction();
|
||||
getServer().getPluginManager().callEvent(new TransactionCompleteEvent(transaction));
|
||||
}
|
||||
data.saveConfig();
|
||||
auctionItems.remove(auctionItem);
|
||||
@ -159,14 +240,10 @@ public final class Core extends JavaPlugin {
|
||||
}
|
||||
}, 0, 20 * 5);
|
||||
} catch (Exception e) {
|
||||
//Debugger.report(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
|
||||
private void saveAuctions() {
|
||||
//Save Auctions to file.
|
||||
int node = 1;
|
||||
for (AuctionItem auctionItem : auctionItems) {
|
||||
@ -181,7 +258,6 @@ public final class Core extends JavaPlugin {
|
||||
data.getConfig().set("active." + node + ".item", auctionItem.getItem());
|
||||
node++;
|
||||
}
|
||||
|
||||
data.saveConfig();
|
||||
}
|
||||
|
||||
@ -201,15 +277,21 @@ public final class Core extends JavaPlugin {
|
||||
getConfig().options().copyDefaults(true);
|
||||
saveDefaultConfig();
|
||||
data = new ConfigWrapper(this, "", "data.yml");
|
||||
transactions = new ConfigWrapper(this, "", "transactions.yml");
|
||||
if (!new File(this.getDataFolder(), "data.yml").exists()) {
|
||||
data.getConfig().createSection("active");
|
||||
}
|
||||
if (!new File(this.getDataFolder(), "transactions.yml").exists()) {
|
||||
transactions.getConfig().createSection("transactions");
|
||||
}
|
||||
data.saveConfig();
|
||||
transactions.saveConfig();
|
||||
}
|
||||
|
||||
private void initEvents() {
|
||||
PluginManager pm = Bukkit.getPluginManager();
|
||||
pm.registerEvents(new AGUIListener(), this);
|
||||
pm.registerEvents(new TransactionListener(), this);
|
||||
}
|
||||
|
||||
private void initStorage() {
|
||||
@ -232,6 +314,10 @@ public final class Core extends JavaPlugin {
|
||||
return data;
|
||||
}
|
||||
|
||||
public ConfigWrapper getTransactions() {
|
||||
return transactions;
|
||||
}
|
||||
|
||||
public static Economy getEconomy() {
|
||||
return economy;
|
||||
}
|
||||
|
@ -2,9 +2,13 @@ package com.shadebyte.auctionhouse.api;
|
||||
|
||||
import com.shadebyte.auctionhouse.Core;
|
||||
import com.shadebyte.auctionhouse.api.enums.Version;
|
||||
import com.shadebyte.auctionhouse.auction.AuctionItem;
|
||||
import com.shadebyte.auctionhouse.util.Debugger;
|
||||
import com.shadebyte.auctionhouse.util.NBTEditor;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
@ -12,8 +16,11 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
@ -24,6 +31,7 @@ import java.util.List;
|
||||
public class AuctionAPI {
|
||||
|
||||
private static char[] c = new char[]{'k', 'm', 'b', 't'};
|
||||
private final static TreeMap<Integer, String> map = new TreeMap<Integer, String>();
|
||||
|
||||
private static AuctionAPI instance;
|
||||
|
||||
@ -37,6 +45,50 @@ public class AuctionAPI {
|
||||
return instance;
|
||||
}
|
||||
|
||||
static {
|
||||
|
||||
map.put(1000, "M");
|
||||
map.put(900, "CM");
|
||||
map.put(500, "D");
|
||||
map.put(400, "CD");
|
||||
map.put(100, "C");
|
||||
map.put(90, "XC");
|
||||
map.put(50, "L");
|
||||
map.put(40, "XL");
|
||||
map.put(10, "X");
|
||||
map.put(9, "IX");
|
||||
map.put(5, "V");
|
||||
map.put(4, "IV");
|
||||
map.put(1, "I");
|
||||
|
||||
}
|
||||
|
||||
public String toRoman(int number) {
|
||||
int l = map.floorKey(number);
|
||||
if (number == l) {
|
||||
return map.get(number);
|
||||
}
|
||||
return map.get(l) + toRoman(number - l);
|
||||
}
|
||||
|
||||
public ItemStack expiredAuctionItem(AuctionItem stack) {
|
||||
ItemStack item = stack.getItem();
|
||||
item = NBTEditor.setItemTag(item, stack.getKey(), "ExpiredAuctionItem");
|
||||
return item;
|
||||
}
|
||||
|
||||
public List<ItemStack> getAllExpiredItems(Player p) {
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
if (Core.getInstance().getData().getConfig().getConfigurationSection("expired." + p.getUniqueId().toString()) != null) {
|
||||
if (Core.getInstance().getData().getConfig().getConfigurationSection("expired." + p.getUniqueId().toString()).getKeys(false).size() >= 1) {
|
||||
for (String s : Core.getInstance().getData().getConfig().getConfigurationSection("expired." + p.getUniqueId().toString()).getKeys(false)) {
|
||||
items.add(Core.getInstance().getData().getConfig().getItemStack("expired." + p.getUniqueId().toString() + "." + s + ".display"));
|
||||
}
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
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]));
|
||||
@ -44,8 +96,8 @@ public class AuctionAPI {
|
||||
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
|
||||
.replace("{active_player_auctions}", String.valueOf(activeAuctions))
|
||||
.replace("{expired_player_auctions}", String.valueOf(expiredAuctions)))));
|
||||
.replace("{active_player_auctions}", String.valueOf(activeAuctions))
|
||||
.replace("{expired_player_auctions}", String.valueOf(expiredAuctions)))));
|
||||
meta.setLore(lore);
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
@ -96,6 +148,12 @@ public class AuctionAPI {
|
||||
return String.format("%02d:%02d:%02d", hours, minutes, seconds);
|
||||
}
|
||||
|
||||
public String getDate(long milli) {
|
||||
Date date = new Date(milli);
|
||||
SimpleDateFormat df2 = new SimpleDateFormat("dd/MM/yy");
|
||||
return df2.format(date);
|
||||
}
|
||||
|
||||
public String friendlyNumber(double value) {
|
||||
int power;
|
||||
String suffix = " KMBT";
|
||||
@ -124,4 +182,49 @@ public class AuctionAPI {
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public String getSQLDisplayName(ItemStack item) {
|
||||
String name;
|
||||
if (item.hasItemMeta()) {
|
||||
name = (item.getItemMeta().hasDisplayName()) ? item.getItemMeta().getDisplayName() : StringUtils.capitalize(item.getType().name().toLowerCase().replace("_", " "));
|
||||
} else {
|
||||
name = StringUtils.capitalize(item.getType().name().toLowerCase().replace("_", " "));
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getSQLLore(ItemStack item) {
|
||||
String lore = "";
|
||||
if (item.hasItemMeta()) {
|
||||
if (!item.getItemMeta().hasLore()) {
|
||||
lore = "No Lore";
|
||||
} else {
|
||||
for (String s : item.getItemMeta().getLore()) {
|
||||
lore += ChatColor.stripColor(s) + ";";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lore = "No Lore";
|
||||
}
|
||||
return lore;
|
||||
}
|
||||
|
||||
public String getSQLEnchantments(ItemStack item) {
|
||||
String lore = "";
|
||||
if (item.hasItemMeta()) {
|
||||
if (!item.getItemMeta().hasEnchants()) {
|
||||
lore = "No Enchantments";
|
||||
} else {
|
||||
for (Enchantment enchantment : item.getItemMeta().getEnchants().keySet()) {
|
||||
String name = enchantment.getName().replace("_", " ").toLowerCase();
|
||||
String level = toRoman(item.getItemMeta().getEnchantLevel(enchantment));
|
||||
String e = StringUtils.capitalize(name) + "," + level;
|
||||
lore += e + ";";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lore = "No Enchantments";
|
||||
}
|
||||
return lore;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,78 @@
|
||||
package com.shadebyte.auctionhouse.api.discordwebhook;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/21/2018
|
||||
* Time Created: 12:20 PM
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
|
||||
import com.shadebyte.auctionhouse.api.discordwebhook.embed.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A discord embed
|
||||
*
|
||||
* @author MrPowerGamerBR
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class DiscordEmbed {
|
||||
String title;
|
||||
String type;
|
||||
String description;
|
||||
String url;
|
||||
String timestamp;
|
||||
int color;
|
||||
ImageEmbed image;
|
||||
ThumbnailEmbed thumbnail;
|
||||
ProviderEmbed provider;
|
||||
AuthorEmbed author;
|
||||
List<FieldEmbed> fields = new ArrayList<FieldEmbed>();
|
||||
|
||||
public DiscordEmbed() {
|
||||
|
||||
}
|
||||
|
||||
public DiscordEmbed(String title, String description) {
|
||||
this(title, description, null);
|
||||
}
|
||||
|
||||
public DiscordEmbed(String title, String description, String url) {
|
||||
setTitle(title);
|
||||
setDescription(description);
|
||||
setUrl(url);
|
||||
}
|
||||
|
||||
public static DiscordMessage toDiscordMessage(DiscordEmbed embed, String username, String avatarUrl) {
|
||||
DiscordMessage dm = DiscordMessage.builder()
|
||||
.username(username)
|
||||
.avatarUrl(avatarUrl)
|
||||
.content("")
|
||||
.embed(embed)
|
||||
.build();
|
||||
|
||||
return dm;
|
||||
}
|
||||
|
||||
public DiscordMessage toDiscordMessage(String username, String avatarUrl) {
|
||||
return DiscordEmbed.toDiscordMessage(this, username, avatarUrl);
|
||||
}
|
||||
|
||||
public static class DiscordEmbedBuilder {
|
||||
List<FieldEmbed> fields = new ArrayList<FieldEmbed>();
|
||||
|
||||
public DiscordEmbedBuilder field(FieldEmbed field) {
|
||||
fields.add(field);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.shadebyte.auctionhouse.api.discordwebhook;
|
||||
|
||||
import com.github.kevinsawicki.http.HttpRequest;
|
||||
import com.google.gson.Gson;
|
||||
import com.shadebyte.auctionhouse.Core;
|
||||
import com.shadebyte.auctionhouse.util.Debugger;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/21/2018
|
||||
* Time Created: 12:28 PM
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
public class DiscordHook {
|
||||
|
||||
public static final Gson gson = new Gson();
|
||||
public String url;
|
||||
|
||||
public DiscordHook(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public void send(DiscordMessage dm) {
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(Core.getInstance(), ()-> {
|
||||
String strResponse = HttpRequest.post(url).acceptJson().contentType("application/json").header("User-Agent", "Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11").send(gson.toJson(dm)).body();
|
||||
if(!strResponse.isEmpty()) {
|
||||
Response response = gson.fromJson(strResponse, Response.class);
|
||||
try {
|
||||
if (response.getMessage().equals("You are being rate limited.")) {
|
||||
Bukkit.getConsoleSender().sendMessage("Error");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Debugger.report(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.shadebyte.auctionhouse.api.discordwebhook;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/21/2018
|
||||
* Time Created: 12:26 PM
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* A discord message
|
||||
*
|
||||
* @author MrPowerGamerBR
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class DiscordMessage {
|
||||
String username;
|
||||
String content;
|
||||
@SerializedName("avatar_url")
|
||||
String avatarUrl;
|
||||
@SerializedName("tts")
|
||||
boolean textToSpeech;
|
||||
List<DiscordEmbed> embeds = new ArrayList<DiscordEmbed>();
|
||||
|
||||
public DiscordMessage() {
|
||||
|
||||
}
|
||||
|
||||
public DiscordMessage(String username, String content, String avatar_url) {
|
||||
this(username, content, avatar_url, false);
|
||||
}
|
||||
|
||||
public DiscordMessage(String username, String content, String avatar_url, boolean tts) {
|
||||
setUsername(username);
|
||||
setContent(content);
|
||||
setAvatarUrl(avatar_url);
|
||||
setTextToSpeech(tts);
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
if (username != null) {
|
||||
this.username = username.substring(0, Math.min(31, username.length()));
|
||||
} else {
|
||||
this.username = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DiscordMessageBuilder {
|
||||
List<DiscordEmbed> embeds = new ArrayList<DiscordEmbed>();
|
||||
|
||||
public DiscordMessageBuilder embed(DiscordEmbed embed) {
|
||||
embeds.add(embed);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.shadebyte.auctionhouse.api.discordwebhook;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Discord response
|
||||
*
|
||||
* @author MrPowerGamerBR
|
||||
*/
|
||||
@Getter
|
||||
public class Response {
|
||||
boolean global;
|
||||
String message;
|
||||
@SerializedName("retry_after")
|
||||
int retryAfter;
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.shadebyte.auctionhouse.api.discordwebhook.embed;
|
||||
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
|
||||
public class AuthorEmbed {
|
||||
String name;
|
||||
String url;
|
||||
String icon_url;
|
||||
String proxy_icon_url;
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.shadebyte.auctionhouse.api.discordwebhook.embed;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class FieldEmbed {
|
||||
String name;
|
||||
String value;
|
||||
boolean inline;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.shadebyte.auctionhouse.api.discordwebhook.embed;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ImageEmbed {
|
||||
String url;
|
||||
String proxy_url;
|
||||
int height;
|
||||
int width;
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.shadebyte.auctionhouse.api.discordwebhook.embed;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ProviderEmbed {
|
||||
String name;
|
||||
String url;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.shadebyte.auctionhouse.api.discordwebhook.embed;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ThumbnailEmbed {
|
||||
String url;
|
||||
String proxy_url;
|
||||
int height;
|
||||
int width;
|
||||
}
|
@ -21,6 +21,14 @@ public enum Lang {
|
||||
AUCTION_MAX("auction.max"),
|
||||
AUCTION_SOLD("auction.sold"),
|
||||
|
||||
MAX_START_PRICE("price.max.start"),
|
||||
MAX_AUCTION_PRICE("price.max.auction"),
|
||||
MAX_INCREMENT_PRICE("price.max.increment"),
|
||||
|
||||
MIN_START_PRICE("price.min.start"),
|
||||
MIN_AUCTION_PRICE("price.min.auction"),
|
||||
MIN_INCREMENT_PRICE("price.min.increment"),
|
||||
|
||||
INVALID_SUBCOMMAND("cmd.invalid"),
|
||||
CMD_SELL("cmd.sell"),
|
||||
|
||||
|
@ -9,6 +9,9 @@ package com.shadebyte.auctionhouse.api.enums;
|
||||
public enum Permissions {
|
||||
|
||||
BASE("AuctionHouse"),
|
||||
RELOAD_CMD(BASE.getNode() + ".cmd.reload"),
|
||||
SELL_CMD(BASE.getNode() + ".cmd.sell"),
|
||||
EXPIRED_CMD(BASE.getNode() + ".cmd.expired"),
|
||||
MAX_AUCTIONS(BASE.getNode() + ".maxauctions"),
|
||||
;
|
||||
|
||||
|
@ -1,10 +0,0 @@
|
||||
package com.shadebyte.auctionhouse.api.event;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/6/2018
|
||||
* Time Created: 11:55 AM
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
public class AuctionCancelEvent {
|
||||
}
|
@ -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 AuctionStartEvent {
|
||||
public class AuctionStartEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
|
||||
private AuctionItem auctionItem;
|
||||
|
||||
public AuctionStartEvent(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;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
package com.shadebyte.auctionhouse.api.event;
|
||||
|
||||
import com.shadebyte.auctionhouse.auction.Transaction;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/13/2018
|
||||
* Time Created: 11:44 AM
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
public class TransactionCompleteEvent extends Event {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private Transaction transaction;
|
||||
|
||||
public TransactionCompleteEvent(Transaction transaction) {
|
||||
this.transaction = transaction;
|
||||
}
|
||||
|
||||
public Transaction getTransaction() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
public void setAuctionItem(Transaction transaction) {
|
||||
this.transaction = transaction;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -148,12 +148,7 @@ public class AuctionItem {
|
||||
ItemStack stack = item.clone();
|
||||
stack.setAmount((stack.getAmount() > 1) ? stack.getAmount() : 1);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
List<String> lore = null;
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.getLore();
|
||||
} else {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
List<String> lore = (meta.hasLore() ? meta.getLore() : new ArrayList<>());
|
||||
lore.add(translateAlternateColorCodes('&', "&7-------------------------"));
|
||||
if (owner == null)
|
||||
lore.add(translateAlternateColorCodes('&', "&eSeller&f: &bSample User"));
|
||||
@ -175,4 +170,21 @@ public class AuctionItem {
|
||||
return stack;
|
||||
}
|
||||
|
||||
public ItemStack listingStack() {
|
||||
ItemStack stack = item.clone();
|
||||
stack.setAmount((stack.getAmount() > 1) ? stack.getAmount() : 1);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
List<String> lore = (meta.hasLore() ? meta.getLore() : new ArrayList<>());
|
||||
lore.add(translateAlternateColorCodes('&', "&7-------------------------"));
|
||||
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-------------------------"));
|
||||
meta.setLore(lore);
|
||||
stack.setItemMeta(meta);
|
||||
stack = NBTEditor.setItemTag(stack, getKey(), "AuctionItemKey");
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
@ -23,13 +23,7 @@ public class AuctionPlayer {
|
||||
}
|
||||
|
||||
public int getTotalActiveAuctions() {
|
||||
int total = 0;
|
||||
for (AuctionItem item : Core.getInstance().auctionItems) {
|
||||
if (item.getOwner().equals(player.getUniqueId().toString())) {
|
||||
total++;
|
||||
}
|
||||
}
|
||||
return total;
|
||||
return getAuctionItems().size();
|
||||
}
|
||||
|
||||
public List<AuctionItem> getAuctionItems() {
|
||||
@ -49,12 +43,17 @@ public class AuctionPlayer {
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasMaximumAuctionsActive() {
|
||||
if (!player.hasPermission(Permissions.MAX_AUCTIONS.getNode() + "." + getTotalActiveAuctions())) {
|
||||
return true;
|
||||
public int getLimit() {
|
||||
if (player.hasPermission(Permissions.MAX_AUCTIONS.getNode() + ".*")) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
return false;
|
||||
|
||||
for (int i = 1001; i > 0; i--) {
|
||||
if (player.hasPermission(Permissions.MAX_AUCTIONS.getNode() + "." + i)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
|
@ -0,0 +1,68 @@
|
||||
package com.shadebyte.auctionhouse.auction;
|
||||
|
||||
import com.shadebyte.auctionhouse.Core;
|
||||
import com.shadebyte.auctionhouse.util.NBTEditor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import javax.swing.text.NumberFormatter;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/25/2018
|
||||
* Time Created: 11:32 PM
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
public class Receipt {
|
||||
|
||||
private int total;
|
||||
private String seller, buyer, date, time;
|
||||
private Transaction transaction;
|
||||
|
||||
public Receipt(Transaction transaction) {
|
||||
this.transaction = transaction;
|
||||
this.total = (transaction.getTransactionType() == Transaction.TransactionType.BOUGHT) ? transaction.getAuctionItem().getBuyNowPrice() : transaction.getAuctionItem().getCurrentPrice();
|
||||
this.seller = transaction.getAuctionItem().getOwner();
|
||||
this.buyer = transaction.getBuyer();
|
||||
this.date = new SimpleDateFormat("MMMM dd yyyy").format(new Date(transaction.getTimeCompleted()));
|
||||
this.time = new SimpleDateFormat("h:mm a").format(new Date());
|
||||
}
|
||||
|
||||
public ItemStack getReceipt() {
|
||||
String[] item = Core.getInstance().getConfig().getString("receipt.item").split(":");
|
||||
ItemStack stack = new ItemStack(Material.valueOf(item[0].toUpperCase()), 1, Short.parseShort(item[1]));
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', Core.getInstance().getConfig().getString("receipt.name")));
|
||||
List<String> lore = Core.getInstance().getConfig().getStringList("receipt.lore").stream().map(node -> ChatColor.translateAlternateColorCodes('&', node.replace("{time}", time).replace("{date}", date).replace("{price}", NumberFormat.getInstance().format(total)).replace("{seller}", Bukkit.getOfflinePlayer(UUID.fromString(seller)).getName()))).collect(Collectors.toList());
|
||||
meta.setLore(lore);
|
||||
stack.setItemMeta(meta);
|
||||
stack = NBTEditor.setItemTag(stack, transaction.getTimeCompleted() + transaction.getAuctionItem().getKey(), "AuctionReceipt");
|
||||
return stack;
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public String getSeller() {
|
||||
return seller;
|
||||
}
|
||||
|
||||
public String getBuyer() {
|
||||
return buyer;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
return date;
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package com.shadebyte.auctionhouse.auction;
|
||||
|
||||
import com.shadebyte.auctionhouse.Core;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/11/2018
|
||||
* Time Created: 3:06 PM
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
public class Transaction {
|
||||
|
||||
public enum TransactionType {
|
||||
|
||||
AUCTION_WON("Won Auction"),
|
||||
BOUGHT("Bought Immediately");
|
||||
|
||||
private String transactionType;
|
||||
|
||||
TransactionType(String transactionType) {
|
||||
this.transactionType = transactionType;
|
||||
}
|
||||
|
||||
public String getTransactionType() {
|
||||
return transactionType;
|
||||
}
|
||||
}
|
||||
|
||||
private TransactionType transactionType;
|
||||
private AuctionItem auctionItem;
|
||||
private String buyer;
|
||||
private long timeCompleted;
|
||||
|
||||
public Transaction(TransactionType transactionType, AuctionItem auctionItem, String buyer, long timeCompleted) {
|
||||
this.transactionType = transactionType;
|
||||
this.auctionItem = auctionItem;
|
||||
this.buyer = buyer;
|
||||
this.timeCompleted = timeCompleted;
|
||||
}
|
||||
|
||||
public void saveTransaction() {
|
||||
Core.getInstance().getTransactions().getConfig().set("transactions." + timeCompleted + auctionItem.getKey() + ".transaction-type", transactionType.name());
|
||||
Core.getInstance().getTransactions().getConfig().set("transactions." + timeCompleted + auctionItem.getKey() + ".seller", auctionItem.getOwner());
|
||||
Core.getInstance().getTransactions().getConfig().set("transactions." + timeCompleted + auctionItem.getKey() + ".buyer", buyer);
|
||||
Core.getInstance().getTransactions().getConfig().set("transactions." + timeCompleted + auctionItem.getKey() + ".start-price", auctionItem.getStartPrice());
|
||||
Core.getInstance().getTransactions().getConfig().set("transactions." + timeCompleted + auctionItem.getKey() + ".bid-increment", auctionItem.getBidIncrement());
|
||||
Core.getInstance().getTransactions().getConfig().set("transactions." + timeCompleted + auctionItem.getKey() + ".current-price", auctionItem.getCurrentPrice());
|
||||
Core.getInstance().getTransactions().getConfig().set("transactions." + timeCompleted + auctionItem.getKey() + ".buy-now-price", auctionItem.getBuyNowPrice());
|
||||
Core.getInstance().getTransactions().getConfig().set("transactions." + timeCompleted + auctionItem.getKey() + ".time-left", auctionItem.getTime());
|
||||
Core.getInstance().getTransactions().getConfig().set("transactions." + timeCompleted + auctionItem.getKey() + ".auction-id", auctionItem.getKey());
|
||||
Core.getInstance().getTransactions().getConfig().set("transactions." + timeCompleted + auctionItem.getKey() + ".time-completed", timeCompleted);
|
||||
Core.getInstance().getTransactions().getConfig().set("transactions." + timeCompleted + auctionItem.getKey() + ".item", auctionItem.getItem());
|
||||
Core.getInstance().getTransactions().saveConfig();
|
||||
}
|
||||
|
||||
public TransactionType getTransactionType() {
|
||||
return transactionType;
|
||||
}
|
||||
|
||||
public void setTransactionType(TransactionType transactionType) {
|
||||
this.transactionType = transactionType;
|
||||
}
|
||||
|
||||
public AuctionItem getAuctionItem() {
|
||||
return auctionItem;
|
||||
}
|
||||
|
||||
public void setAuctionItem(AuctionItem auctionItem) {
|
||||
this.auctionItem = auctionItem;
|
||||
}
|
||||
|
||||
public String getBuyer() {
|
||||
return buyer;
|
||||
}
|
||||
|
||||
public void setBuyer(String buyer) {
|
||||
this.buyer = buyer;
|
||||
}
|
||||
|
||||
public long getTimeCompleted() {
|
||||
return timeCompleted;
|
||||
}
|
||||
|
||||
public void setTimeCompleted(long timeCompleted) {
|
||||
this.timeCompleted = timeCompleted;
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package com.shadebyte.auctionhouse.cmds;
|
||||
import com.shadebyte.auctionhouse.Core;
|
||||
import com.shadebyte.auctionhouse.api.enums.Lang;
|
||||
import com.shadebyte.auctionhouse.api.enums.Permissions;
|
||||
import com.shadebyte.auctionhouse.cmds.subcmds.ReloadCommand;
|
||||
import com.shadebyte.auctionhouse.cmds.subcmds.SellCommand;
|
||||
import com.shadebyte.auctionhouse.inventory.inventories.AuctionGUI;
|
||||
import com.shadebyte.auctionhouse.util.Debugger;
|
||||
@ -40,6 +41,7 @@ public class CommandManager implements CommandExecutor {
|
||||
public void initialize() {
|
||||
Core.getInstance().getCommand(main).setExecutor(this);
|
||||
this.commands.add(new SellCommand());
|
||||
this.commands.add(new ReloadCommand());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -55,7 +57,7 @@ public class CommandManager implements CommandExecutor {
|
||||
if (args.length == 0) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
p.openInventory(AuctionGUI.getInstance(p).getInventory());
|
||||
p.openInventory(new AuctionGUI(p).getInventory());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1,10 +1,50 @@
|
||||
package com.shadebyte.auctionhouse.cmds.subcmds;
|
||||
|
||||
import com.shadebyte.auctionhouse.Core;
|
||||
import com.shadebyte.auctionhouse.api.enums.Lang;
|
||||
import com.shadebyte.auctionhouse.api.enums.Permissions;
|
||||
import com.shadebyte.auctionhouse.cmds.SubCommand;
|
||||
import com.shadebyte.auctionhouse.inventory.inventories.ExpiredGUI;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/6/2018
|
||||
* Time Created: 11:51 AM
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
public class ExpiredCommand {
|
||||
public class ExpiredCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
|
||||
if (!sender.hasPermission(Permissions.EXPIRED_CMD.getNode())) {
|
||||
sender.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.NO_PERMISSION.getNode()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.PLAYERS_ONLY.getNode()));
|
||||
return;
|
||||
}
|
||||
|
||||
Player p = (Player) sender;
|
||||
p.openInventory(new ExpiredGUI(p).getInventory());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return Core.getInstance().getCommandManager().expired;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String info() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] aliases() {
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,58 @@
|
||||
package com.shadebyte.auctionhouse.cmds.subcmds;
|
||||
|
||||
import com.shadebyte.auctionhouse.Core;
|
||||
import com.shadebyte.auctionhouse.api.enums.Lang;
|
||||
import com.shadebyte.auctionhouse.api.enums.Permissions;
|
||||
import com.shadebyte.auctionhouse.cmds.SubCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/6/2018
|
||||
* Time Created: 11:51 AM
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
public class ReloadCommand {
|
||||
public class ReloadCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
|
||||
if (!sender.hasPermission(Permissions.RELOAD_CMD.getNode())) {
|
||||
sender.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.NO_PERMISSION.getNode()));
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&cStarting reload process"));
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&bReloading config.yml"));
|
||||
Core.getInstance().saveConfig();
|
||||
Core.getInstance().reloadConfig();
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&bReloading transactions.yml"));
|
||||
Core.getInstance().getTransactions().saveConfig();
|
||||
Core.getInstance().getTransactions().reloadConfig();
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&bReloading data.yml"));
|
||||
Core.getInstance().getData().saveConfig();
|
||||
Core.getInstance().getData().reloadConfig();
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&bReloading language file."));
|
||||
Core.getInstance().getLocale().reloadMessages();
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&eAuction House reloaded, took &a" + (System.currentTimeMillis() - start) + "ms"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return Core.getInstance().getCommandManager().reload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String info() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] aliases() {
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
|
@ -2,14 +2,22 @@ package com.shadebyte.auctionhouse.cmds.subcmds;
|
||||
|
||||
import com.shadebyte.auctionhouse.Core;
|
||||
import com.shadebyte.auctionhouse.api.AuctionAPI;
|
||||
import com.shadebyte.auctionhouse.api.discordwebhook.DiscordEmbed;
|
||||
import com.shadebyte.auctionhouse.api.discordwebhook.DiscordHook;
|
||||
import com.shadebyte.auctionhouse.api.discordwebhook.DiscordMessage;
|
||||
import com.shadebyte.auctionhouse.api.discordwebhook.embed.FieldEmbed;
|
||||
import com.shadebyte.auctionhouse.api.enums.Lang;
|
||||
import com.shadebyte.auctionhouse.api.enums.Permissions;
|
||||
import com.shadebyte.auctionhouse.api.event.AuctionStartEvent;
|
||||
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;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/6/2018
|
||||
@ -21,7 +29,7 @@ public class SellCommand extends SubCommand {
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
|
||||
if (!sender.hasPermission(Permissions.BASE.getNode())) {
|
||||
if (!sender.hasPermission(Permissions.SELL_CMD.getNode())) {
|
||||
sender.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.NO_PERMISSION.getNode()));
|
||||
return;
|
||||
}
|
||||
@ -54,9 +62,24 @@ public class SellCommand extends SubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length == 5) {
|
||||
int buyNow = ThreadLocalRandom.current().nextInt(2, 100000);
|
||||
int startPrice = ThreadLocalRandom.current().nextInt(2, 10000);
|
||||
int increment = ThreadLocalRandom.current().nextInt(2, 10000);
|
||||
|
||||
AuctionItem auctionItem = new AuctionItem(p.getUniqueId().toString(), AuctionAPI.getItemInHand(p), Core.getInstance().getConfig().getInt("settings.default-auction-time"), startPrice, increment, buyNow);
|
||||
Core.getInstance().auctionItems.add(0, auctionItem);
|
||||
|
||||
if (AuctionAPI.getItemInHand(p).getAmount() >= 2) {
|
||||
AuctionAPI.getItemInHand(p).setAmount(AuctionAPI.getItemInHand(p).getAmount() - 1);
|
||||
} else {
|
||||
AuctionAPI.setItemInHand(p, null);
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length == 4) {
|
||||
if (AuctionAPI.getInstance().isNumeric(args[1]) && AuctionAPI.getInstance().isNumeric(args[2]) && AuctionAPI.getInstance().isNumeric(args[3])) {
|
||||
if (new AuctionPlayer(p).hasMaximumAuctionsActive()) {
|
||||
if (new AuctionPlayer(p).getLimit() - 1 < new AuctionPlayer(p).getTotalActiveAuctions()) {
|
||||
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.AUCTION_MAX.getNode()));
|
||||
return;
|
||||
}
|
||||
@ -64,9 +87,73 @@ public class SellCommand extends SubCommand {
|
||||
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)));
|
||||
|
||||
//Max Prices
|
||||
if (buyNow > Core.getInstance().getConfig().getInt("settings.max-auction-price")) {
|
||||
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.MAX_AUCTION_PRICE.getNode()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (startPrice > Core.getInstance().getConfig().getInt("settings.max-auction-start")) {
|
||||
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.MAX_START_PRICE.getNode()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (increment > Core.getInstance().getConfig().getInt("settings.max-auction-increment")) {
|
||||
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.MAX_INCREMENT_PRICE.getNode()));
|
||||
return;
|
||||
}
|
||||
|
||||
//Min Prices
|
||||
if (buyNow < Core.getInstance().getConfig().getInt("settings.min-auction-price")) {
|
||||
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.MIN_AUCTION_PRICE.getNode()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (startPrice < Core.getInstance().getConfig().getInt("settings.min-auction-start")) {
|
||||
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.MIN_START_PRICE.getNode()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (increment < Core.getInstance().getConfig().getInt("settings.min-auction-increment")) {
|
||||
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.MIN_INCREMENT_PRICE.getNode()));
|
||||
return;
|
||||
}
|
||||
|
||||
AuctionItem auctionItem = new AuctionItem(p.getUniqueId().toString(), AuctionAPI.getItemInHand(p), Core.getInstance().getConfig().getInt("settings.default-auction-time"), startPrice, increment, buyNow);
|
||||
AuctionStartEvent auctionStartEvent = new AuctionStartEvent(auctionItem);
|
||||
Core.getInstance().getServer().getPluginManager().callEvent(auctionStartEvent);
|
||||
|
||||
if (!auctionStartEvent.isCancelled()) {
|
||||
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)));
|
||||
|
||||
//Discord Hook
|
||||
if (Core.getInstance().getConfig().getBoolean("discord.enabled")) {
|
||||
DiscordHook discordHook = new DiscordHook(Core.getInstance().getConfig().getString("discord.webhook"));
|
||||
DiscordEmbed de = DiscordEmbed.builder()
|
||||
.title(Core.getInstance().getConfig().getString("discord.title"))
|
||||
.description(Core.getInstance().getConfig().getString("discord.description"))
|
||||
.color(1)
|
||||
.fields(Arrays.asList(
|
||||
FieldEmbed.builder().name("Seller").value(p.getName()).inline(true).build(),
|
||||
FieldEmbed.builder().name("Start Price").value(AuctionAPI.getInstance().friendlyNumber(startPrice)).build(),
|
||||
FieldEmbed.builder().name("Increment").value(AuctionAPI.getInstance().friendlyNumber(increment)).build(),
|
||||
FieldEmbed.builder().name("Buy Now").value(AuctionAPI.getInstance().friendlyNumber(buyNow)).build(),
|
||||
FieldEmbed.builder().name("Item").value(auctionItem.getItem().getType().name() + ":" + auctionItem.getItem().getDurability()).build()
|
||||
))
|
||||
.build();
|
||||
|
||||
DiscordMessage dm = DiscordMessage.builder().username(Core.getInstance().getConfig().getString("discord.username")).content("").avatarUrl(Core.getInstance().getConfig().getString("discord.profilepicture")).embeds(Arrays.asList(de)).build();
|
||||
discordHook.send(dm);
|
||||
}
|
||||
|
||||
if (AuctionAPI.getItemInHand(p).getAmount() >= 2) {
|
||||
AuctionAPI.getItemInHand(p).setAmount(AuctionAPI.getItemInHand(p).getAmount() - 1);
|
||||
} else {
|
||||
AuctionAPI.setItemInHand(p, null);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.NOT_A_NUMBER.getNode()));
|
||||
}
|
||||
|
@ -0,0 +1,73 @@
|
||||
package com.shadebyte.auctionhouse.events;
|
||||
|
||||
import com.shadebyte.auctionhouse.Core;
|
||||
import com.shadebyte.auctionhouse.api.AuctionAPI;
|
||||
import com.shadebyte.auctionhouse.api.discordwebhook.DiscordEmbed;
|
||||
import com.shadebyte.auctionhouse.api.discordwebhook.DiscordHook;
|
||||
import com.shadebyte.auctionhouse.api.discordwebhook.DiscordMessage;
|
||||
import com.shadebyte.auctionhouse.api.discordwebhook.embed.FieldEmbed;
|
||||
import com.shadebyte.auctionhouse.api.event.TransactionCompleteEvent;
|
||||
import com.shadebyte.auctionhouse.auction.Receipt;
|
||||
import com.shadebyte.auctionhouse.auction.Transaction;
|
||||
import com.shadebyte.auctionhouse.util.Debugger;
|
||||
import com.shadebyte.auctionhouse.util.storage.MySQL;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/24/2018
|
||||
* Time Created: 12:08 PM
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
public class TransactionListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onTransactionComplete(TransactionCompleteEvent e) {
|
||||
|
||||
if (Core.getInstance().getConfig().getBoolean("receipt.give-on-transaction")) {
|
||||
Player buyer = Bukkit.getPlayer(UUID.fromString(e.getTransaction().getBuyer()));
|
||||
Player seller = Bukkit.getPlayer(UUID.fromString(e.getTransaction().getAuctionItem().getOwner()));
|
||||
|
||||
if (buyer != null) {
|
||||
buyer.getInventory().addItem(new Receipt(e.getTransaction()).getReceipt());
|
||||
}
|
||||
|
||||
if (seller != null) {
|
||||
seller.getInventory().addItem(new Receipt(e.getTransaction()).getReceipt());
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (Core.getInstance().getConfig().getBoolean("database.enabled") && Core.getInstance().dbConnected) {
|
||||
new MySQL().logTransaction(e.getTransaction());
|
||||
}
|
||||
|
||||
if (Core.getInstance().getConfig().getBoolean("discord.enabled")) {
|
||||
DiscordHook discordHook = new DiscordHook(Core.getInstance().getConfig().getString("discord.webhook"));
|
||||
DiscordEmbed de = DiscordEmbed.builder()
|
||||
.title(Core.getInstance().getConfig().getString("discord.title"))
|
||||
.description(Core.getInstance().getConfig().getString("discord.description-complete"))
|
||||
.color(1)
|
||||
.fields(Arrays.asList(
|
||||
FieldEmbed.builder().name("Seller").value(Bukkit.getOfflinePlayer(UUID.fromString(e.getTransaction().getAuctionItem().getOwner())).getName()).inline(true).build(),
|
||||
FieldEmbed.builder().name("Buyer").value(Bukkit.getOfflinePlayer(UUID.fromString(e.getTransaction().getBuyer())).getName()).build(),
|
||||
FieldEmbed.builder().name("Transaction Type").value(e.getTransaction().getTransactionType().getTransactionType()).build(),
|
||||
FieldEmbed.builder().name("Price").value(AuctionAPI.getInstance().friendlyNumber((e.getTransaction().getTransactionType() == Transaction.TransactionType.BOUGHT) ? e.getTransaction().getAuctionItem().getBuyNowPrice() : e.getTransaction().getAuctionItem().getCurrentPrice())).build(),
|
||||
FieldEmbed.builder().name("Item").value(e.getTransaction().getAuctionItem().getItem().getType().name() + ":" + e.getTransaction().getAuctionItem().getItem().getDurability()).build()
|
||||
))
|
||||
.build();
|
||||
|
||||
DiscordMessage dm = DiscordMessage.builder().username(Core.getInstance().getConfig().getString("discord.username")).content("").avatarUrl(Core.getInstance().getConfig().getString("discord.profilepicture")).embeds(Arrays.asList(de)).build();
|
||||
discordHook.send(dm);
|
||||
}
|
||||
} catch (Exception e1) {
|
||||
Debugger.report(e1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -28,18 +28,12 @@ import java.util.List;
|
||||
*/
|
||||
public class AuctionGUI implements AGUI {
|
||||
|
||||
private static AuctionGUI instance;
|
||||
private Player p;
|
||||
private List<List<AuctionItem>> chunks;
|
||||
|
||||
private AuctionGUI(Player p) {
|
||||
public AuctionGUI(Player p) {
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
public static AuctionGUI getInstance(Player p) {
|
||||
if (instance == null) {
|
||||
instance = new AuctionGUI(p);
|
||||
}
|
||||
return instance;
|
||||
chunks = Lists.partition(Core.getInstance().auctionItems, 45);
|
||||
}
|
||||
|
||||
private int page = 1;
|
||||
@ -59,7 +53,17 @@ public class AuctionGUI implements AGUI {
|
||||
|
||||
if (slot == 49) {
|
||||
p.closeInventory();
|
||||
p.openInventory(AuctionGUI.getInstance(p).getInventory());
|
||||
p.openInventory(new AuctionGUI(p).getInventory());
|
||||
}
|
||||
|
||||
if (slot == 45) {
|
||||
p.closeInventory();
|
||||
p.openInventory(new ListingsGUI(p).getInventory());
|
||||
}
|
||||
|
||||
if (slot == 46) {
|
||||
p.closeInventory();
|
||||
p.openInventory(new ExpiredGUI(p).getInventory());
|
||||
}
|
||||
|
||||
if (slot >= 0 & slot <= 44) {
|
||||
@ -79,7 +83,7 @@ public class AuctionGUI implements AGUI {
|
||||
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());
|
||||
p.openInventory(new AuctionGUI(p).getInventory());
|
||||
}, 20);
|
||||
return;
|
||||
}
|
||||
@ -100,7 +104,7 @@ public class AuctionGUI implements AGUI {
|
||||
item.setTime(item.getTime() + Core.getInstance().getConfig().getInt("settings.bid.increase-amount"));
|
||||
|
||||
p.closeInventory();
|
||||
p.openInventory(AuctionGUI.getInstance(p).getInventory());
|
||||
p.openInventory(new AuctionGUI(p).getInventory());
|
||||
}
|
||||
|
||||
if (e.getClick() == ClickType.RIGHT) {
|
||||
@ -113,20 +117,20 @@ public class AuctionGUI implements AGUI {
|
||||
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());
|
||||
p.openInventory(new AuctionGUI(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());
|
||||
p.openInventory(new ConfirmationGUI(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());
|
||||
p.openInventory(new ConfirmationGUI(item).getInventory());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -152,11 +156,10 @@ public class AuctionGUI implements AGUI {
|
||||
inventory.setItem(53, AuctionAPI.getInstance().createConfigItem("gui.auction.items.guide", 0, 0));
|
||||
|
||||
//Pagination
|
||||
List<List<AuctionItem>> chunks = Lists.partition(Core.getInstance().auctionItems, 45);
|
||||
|
||||
|
||||
if (chunks.size() != 0)
|
||||
chunks.get(getPage() - 1).forEach(item -> inventory.setItem(inventory.firstEmpty(), item.auctionStack()));
|
||||
|
||||
return inventory;
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,9 @@ 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.api.event.TransactionCompleteEvent;
|
||||
import com.shadebyte.auctionhouse.auction.AuctionItem;
|
||||
import com.shadebyte.auctionhouse.auction.Transaction;
|
||||
import com.shadebyte.auctionhouse.inventory.AGUI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -23,20 +25,12 @@ import java.util.UUID;
|
||||
*/
|
||||
public class ConfirmationGUI implements AGUI {
|
||||
|
||||
private static ConfirmationGUI instance;
|
||||
private AuctionItem auctionItem;
|
||||
|
||||
private ConfirmationGUI(AuctionItem auctionItem) {
|
||||
public 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);
|
||||
@ -47,6 +41,7 @@ public class ConfirmationGUI implements AGUI {
|
||||
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.NOT_ENOUGH_MONEY.getNode()));
|
||||
} else {
|
||||
Core.getEconomy().withdrawPlayer(p, auctionItem.getBuyNowPrice());
|
||||
Core.getEconomy().depositPlayer(Bukkit.getOfflinePlayer(UUID.fromString(auctionItem.getOwner())), 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()));
|
||||
@ -55,14 +50,20 @@ public class ConfirmationGUI implements AGUI {
|
||||
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())));
|
||||
}
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
Transaction transaction = new Transaction(Transaction.TransactionType.BOUGHT, auctionItem, p.getUniqueId().toString(), time);
|
||||
transaction.saveTransaction();
|
||||
auctionItem.setTime(0);
|
||||
Core.getInstance().auctionItems.remove(auctionItem);
|
||||
p.closeInventory();
|
||||
TransactionCompleteEvent completeEvent = new TransactionCompleteEvent(transaction);
|
||||
Core.getInstance().getServer().getPluginManager().callEvent(completeEvent);
|
||||
p.openInventory(new AuctionGUI(p).getInventory());
|
||||
}
|
||||
}
|
||||
} else if (clicked.isSimilar(AuctionAPI.getInstance().fill("&c&lNo", 14))) {
|
||||
p.closeInventory();
|
||||
p.openInventory(AuctionGUI.getInstance(p).getInventory());
|
||||
p.openInventory(new AuctionGUI(p).getInventory());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,129 @@
|
||||
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.auction.AuctionPlayer;
|
||||
import com.shadebyte.auctionhouse.inventory.AGUI;
|
||||
import com.shadebyte.auctionhouse.util.NBTEditor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
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.List;
|
||||
|
||||
/**
|
||||
* 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 ExpiredGUI {
|
||||
public class ExpiredGUI implements AGUI {
|
||||
|
||||
private Player p;
|
||||
private List<List<ItemStack>> chunks;
|
||||
private int page = 1;
|
||||
|
||||
public ExpiredGUI(Player p) {
|
||||
this.p = p;
|
||||
chunks = Lists.partition(AuctionAPI.getInstance().getAllExpiredItems(p), 45);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click(InventoryClickEvent e, ItemStack clicked, int slot) {
|
||||
e.setCancelled(true);
|
||||
|
||||
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 e1) {
|
||||
}
|
||||
|
||||
if (slot >= 0 & slot <= 44) {
|
||||
|
||||
if (clicked == null || clicked.getType() == Material.AIR) {
|
||||
return;
|
||||
}
|
||||
|
||||
String key = (String) NBTEditor.getItemTag(clicked, "ExpiredAuctionItem");
|
||||
ItemStack stack = Core.getInstance().getData().getConfig().getItemStack("expired." + p.getUniqueId().toString() + "." + key + ".item");
|
||||
Core.getInstance().getData().getConfig().set("expired." + p.getUniqueId().toString() + "." + key, null);
|
||||
Core.getInstance().getData().saveConfig();
|
||||
if (AuctionAPI.getInstance().availableSlots(p.getInventory()) >= 1) {
|
||||
p.getInventory().addItem(stack);
|
||||
} else {
|
||||
p.getWorld().dropItemNaturally(p.getLocation(), stack);
|
||||
}
|
||||
p.closeInventory();
|
||||
p.openInventory(new ExpiredGUI(p).getInventory());
|
||||
}
|
||||
|
||||
if (slot == 49) {
|
||||
if (Core.getInstance().getData().getConfig().getConfigurationSection("expired." + p.getUniqueId().toString()) != null) {
|
||||
if (Core.getInstance().getData().getConfig().getConfigurationSection("expired." + p.getUniqueId().toString()).getKeys(false).size() >= 1) {
|
||||
Core.getInstance().getData().getConfig().getConfigurationSection("expired." + p.getUniqueId().toString()).getKeys(false).forEach(node -> {
|
||||
ItemStack stack = Core.getInstance().getData().getConfig().getItemStack("expired." + p.getUniqueId().toString() + "." + node + ".item");
|
||||
Core.getInstance().getData().getConfig().set("expired." + p.getUniqueId().toString() + "." + node, null);
|
||||
Core.getInstance().getData().saveConfig();
|
||||
if (AuctionAPI.getInstance().availableSlots(p.getInventory()) >= 1) {
|
||||
p.getInventory().addItem(stack);
|
||||
} else {
|
||||
p.getWorld().dropItemNaturally(p.getLocation(), stack);
|
||||
}
|
||||
});
|
||||
|
||||
p.closeInventory();
|
||||
p.openInventory(new ExpiredGUI(p).getInventory());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (slot == 45) {
|
||||
p.closeInventory();
|
||||
p.openInventory(new AuctionGUI(p).getInventory());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(InventoryCloseEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
Inventory inventory = Bukkit.createInventory(this, 54, ChatColor.translateAlternateColorCodes('&', Core.getInstance().getConfig().getString("gui.collection.title")));
|
||||
|
||||
//Bottom Row
|
||||
inventory.setItem(45, AuctionAPI.getInstance().createConfigItem("gui.collection.items.return", 0, 0));
|
||||
inventory.setItem(48, AuctionAPI.getInstance().createConfigItem("gui.collection.items.previouspage", 0, 0));
|
||||
inventory.setItem(49, AuctionAPI.getInstance().createConfigItem("gui.collection.items.claimall", 0, 0));
|
||||
inventory.setItem(50, AuctionAPI.getInstance().createConfigItem("gui.collection.items.nextpage", 0, 0));
|
||||
inventory.setItem(53, AuctionAPI.getInstance().createConfigItem("gui.collection.items.tutorial", 0, 0));
|
||||
|
||||
if (new AuctionPlayer(p).getTotalExpiredAuctions() == 0) {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
if (chunks.size() != 0)
|
||||
chunks.get(getPage() - 1).forEach(item -> inventory.setItem(inventory.firstEmpty(), item));
|
||||
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public ExpiredGUI setPage(int page) {
|
||||
if (page <= 0)
|
||||
this.page = 1;
|
||||
else
|
||||
this.page = page;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getPage() {
|
||||
return page;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,107 @@
|
||||
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.auction.AuctionItem;
|
||||
import com.shadebyte.auctionhouse.auction.AuctionPlayer;
|
||||
import com.shadebyte.auctionhouse.inventory.AGUI;
|
||||
import com.shadebyte.auctionhouse.util.NBTEditor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
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.List;
|
||||
|
||||
/**
|
||||
* 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 ListingsGUI {
|
||||
public class ListingsGUI implements AGUI {
|
||||
|
||||
private Player p;
|
||||
private List<List<AuctionItem>> chunks;
|
||||
private int page = 1;
|
||||
|
||||
public ListingsGUI(Player p) {
|
||||
this.p = p;
|
||||
chunks = Lists.partition(new AuctionPlayer(p).getAuctionItems(), 45);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void click(InventoryClickEvent e, ItemStack clicked, int slot) {
|
||||
e.setCancelled(true);
|
||||
|
||||
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 e1) {
|
||||
}
|
||||
|
||||
if (slot >= 0 & slot <= 44) {
|
||||
if (clicked == null || clicked.getType() == Material.AIR) {
|
||||
return;
|
||||
}
|
||||
|
||||
AuctionItem item = null;
|
||||
if (e.getClick() == ClickType.LEFT) {
|
||||
String key = (String) NBTEditor.getItemTag(clicked, "AuctionItemKey");
|
||||
for (AuctionItem auctionItem : Core.getInstance().auctionItems) {
|
||||
if (auctionItem.getKey().equalsIgnoreCase(key)) item = auctionItem;
|
||||
}
|
||||
|
||||
item.setTime(0);
|
||||
Core.getInstance().getData().getConfig().set("expired." + item.getOwner() + "." + item.getKey() + ".item", item.getItem());
|
||||
Core.getInstance().getData().getConfig().set("expired." + item.getOwner() + "." + item.getKey() + ".display", AuctionAPI.getInstance().expiredAuctionItem(item));
|
||||
Core.getInstance().getData().saveConfig();
|
||||
Core.getInstance().auctionItems.remove(item);
|
||||
p.closeInventory();
|
||||
p.openInventory(new ListingsGUI(p).getInventory());
|
||||
}
|
||||
}
|
||||
|
||||
if (slot == 45) {
|
||||
p.closeInventory();
|
||||
p.openInventory(new AuctionGUI(p).getInventory());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(InventoryCloseEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
Inventory inventory = Bukkit.createInventory(this, 54, Core.getInstance().getConfig().getString("gui.active.title"));
|
||||
inventory.setItem(45, AuctionAPI.getInstance().createConfigItem("gui.active.items.return", 0, 0));
|
||||
inventory.setItem(48, AuctionAPI.getInstance().createConfigItem("gui.active.items.previouspage", 0, 0));
|
||||
inventory.setItem(50, AuctionAPI.getInstance().createConfigItem("gui.active.items.nextpage", 0, 0));
|
||||
inventory.setItem(53, AuctionAPI.getInstance().createConfigItem("gui.active.items.tutorial", 0, 0));
|
||||
|
||||
if (chunks.size() != 0)
|
||||
chunks.get(getPage() - 1).forEach(item -> inventory.setItem(inventory.firstEmpty(), item.listingStack()));
|
||||
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public ListingsGUI setPage(int page) {
|
||||
if (page <= 0)
|
||||
this.page = 1;
|
||||
else
|
||||
this.page = page;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getPage() {
|
||||
return page;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.shadebyte.auctionhouse.util;
|
||||
package com.shadebyte.auctionhouse.util.storage;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
@ -0,0 +1,45 @@
|
||||
package com.shadebyte.auctionhouse.util.storage;
|
||||
|
||||
import com.shadebyte.auctionhouse.Core;
|
||||
import com.shadebyte.auctionhouse.api.AuctionAPI;
|
||||
import com.shadebyte.auctionhouse.auction.Transaction;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/23/2018
|
||||
* Time Created: 9:49 PM
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
public class MySQL {
|
||||
|
||||
public void logTransaction(Transaction transaction) {
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(Core.getInstance(), () -> {
|
||||
try {
|
||||
PreparedStatement insert = Core.getInstance().getConnection().prepareStatement("INSERT INTO transactions (buyer, seller, auctiontype, startprice, buynowprice, increment, item, displayname, lore, enchantments, auctionid, timesold, finalprice) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
|
||||
insert.setString(1, transaction.getBuyer());
|
||||
insert.setString(2, transaction.getAuctionItem().getOwner());
|
||||
insert.setString(3, transaction.getTransactionType().getTransactionType());
|
||||
insert.setInt(4, transaction.getAuctionItem().getStartPrice());
|
||||
insert.setInt(5, transaction.getAuctionItem().getBuyNowPrice());
|
||||
insert.setInt(6, transaction.getAuctionItem().getBidIncrement());
|
||||
insert.setString(7, transaction.getAuctionItem().getItem().getTypeId() + "-" + transaction.getAuctionItem().getItem().getDurability());
|
||||
|
||||
insert.setString(8, AuctionAPI.getInstance().getSQLDisplayName(transaction.getAuctionItem().getItem()));
|
||||
insert.setString(9, AuctionAPI.getInstance().getSQLLore(transaction.getAuctionItem().getItem()));
|
||||
insert.setString(10, AuctionAPI.getInstance().getSQLEnchantments(transaction.getAuctionItem().getItem()));
|
||||
|
||||
insert.setString(11, transaction.getAuctionItem().getKey());
|
||||
insert.setString(12, AuctionAPI.getInstance().getDate(System.currentTimeMillis()));
|
||||
insert.setInt(13, (transaction.getTransactionType() == Transaction.TransactionType.BOUGHT) ? transaction.getAuctionItem().getBuyNowPrice() : transaction.getAuctionItem().getCurrentPrice());
|
||||
insert.executeUpdate();
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&aRecorded transaction id: &b" + transaction.getAuctionItem().getKey() + "&a to database."));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -5,12 +5,12 @@
|
||||
lang: "en_US"
|
||||
|
||||
settings:
|
||||
default-auction-time: 3600 # 60 Minutes by default
|
||||
default-auction-time: 15 # 15 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-price: 1
|
||||
min-auction-start: 1
|
||||
min-auction-increment: 1
|
||||
owner-can-purchase-own: false
|
||||
owner-can-bid-own: false
|
||||
@ -18,20 +18,103 @@ settings:
|
||||
increase-on-bid: true
|
||||
increase-amount: 10 #10 Seconds by default
|
||||
|
||||
#MySql stuff for databases if you want
|
||||
database:
|
||||
enabled: true
|
||||
host: 162.241.217.18
|
||||
port: 3306
|
||||
database: "kiranhar_auctionhouse"
|
||||
username: "kiranhar_admin"
|
||||
password: "TweetyHart1."
|
||||
|
||||
discord:
|
||||
enabled: true
|
||||
webhook: "https://discordapp.com/api/webhooks/470085392901734410/_ls7Ps5GzlKqBJlHLaZt6GZgVTKkuwuIuWK1JU5j_pt-DwWhSYAITlI17ePiIuNTmdua"
|
||||
title: "Auction House"
|
||||
description: "A new item has been listed!"
|
||||
description-complete: "A transaction has been completed!"
|
||||
username: "Auction House"
|
||||
profilepicture: "https://vignette.wikia.nocookie.net/minecraftuniverse/images/2/2c/Gold_Chest_%28M2%29.png/revision/latest?cb=20130121082341"
|
||||
|
||||
receipt:
|
||||
give-on-transaction: true
|
||||
item: "PAPER:0"
|
||||
name: "&E&LReceipt &7(Right-Click)"
|
||||
lore:
|
||||
- "&7Purchase proof of the purchased item."
|
||||
- ""
|
||||
- "&bSeller&f: &E{seller}"
|
||||
- "&bPrice&f: &a${price}"
|
||||
- "&ePurchased on&f: &a{date} &fat &A{time}"
|
||||
|
||||
gui:
|
||||
active:
|
||||
title: "&7Your Current Listings"
|
||||
items:
|
||||
return:
|
||||
item: "CHEST:0"
|
||||
name: "&e&lReturn to Auction House"
|
||||
lore:
|
||||
- "&7Click here to return to the"
|
||||
- "&7auction house main menu."
|
||||
previouspage:
|
||||
item: "PAPER:0"
|
||||
name: "&e&l<- Previous Page"
|
||||
lore:
|
||||
- "&7Go back"
|
||||
nextpage:
|
||||
item: "PAPER:0"
|
||||
name: "&e&lPrevious Page ->"
|
||||
lore:
|
||||
- "&7Next Page"
|
||||
tutorial:
|
||||
item: "BOOK:0"
|
||||
name: "&e&lTutorial"
|
||||
lore:
|
||||
- "&7These are your current listings, all of"
|
||||
- "&7the items you currently have listed on"
|
||||
- "&7the auction house are displayed here."
|
||||
- ""
|
||||
- "&7You can cancel and view your listing's"
|
||||
- "&7expire time here."
|
||||
collection:
|
||||
title: "&7Cancelled / Expired Listings"
|
||||
items:
|
||||
return:
|
||||
item: "CHEST:0"
|
||||
name: "&e&lReturn to Auction House"
|
||||
lore:
|
||||
- "&7Click here to return to the"
|
||||
- "&7auction house main menu."
|
||||
previouspage:
|
||||
item: "PAPER:0"
|
||||
name: "&e&l<- Previous Page"
|
||||
lore:
|
||||
- "&7Go back"
|
||||
nextpage:
|
||||
item: "PAPER:0"
|
||||
name: "&e&lPrevious Page ->"
|
||||
lore:
|
||||
- "&7Next Page"
|
||||
claimall:
|
||||
item: "ENDER_CHEST:0"
|
||||
name: "&e&lClaim All"
|
||||
lore:
|
||||
- "&7Click here to claim all"
|
||||
- "&7your Collection Bin items."
|
||||
tutorial:
|
||||
item: "BOOK:0"
|
||||
name: "&e&lTutorial"
|
||||
lore:
|
||||
- "&7This page houses all of your cancelled and"
|
||||
- "&7expired items, when a listing is cancelled"
|
||||
- "&7or expires you will be able to return that"
|
||||
- "&7item back to you from this menu."
|
||||
- ""
|
||||
- "&7Just click on the item and if you have enough"
|
||||
- "&7inventory space you will receive the item."
|
||||
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:
|
||||
|
@ -10,6 +10,13 @@ notenoughmoney = "&CYou do not have enough money!"
|
||||
cantbidonown = "&cYou cannot bid on your own item!"
|
||||
cantbuyown = "&cYou cannot buy your own item!"
|
||||
|
||||
price.max.start = "&cPlease start auction with a lower price."
|
||||
price.max.auction = "&cPlease start with a lower bid price."
|
||||
price.max.increment = "&cPlease decrease the bid increment"
|
||||
price.min.start = "&cPlease start auction with a higher price."
|
||||
price.min.auction = "&cPlease start with a higher bid price."
|
||||
price.min.increment = "&cPlease increase the bid increment"
|
||||
|
||||
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}"
|
||||
|
18
src/test/java/com/shadebyte/server/ServerTest.java
Normal file
18
src/test/java/com/shadebyte/server/ServerTest.java
Normal file
@ -0,0 +1,18 @@
|
||||
package com.shadebyte.server;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/23/2018
|
||||
* Time Created: 9:00 PM
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
public class ServerTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.out.println(new SimpleDateFormat("MMMM dd yyyy").format(new Date(System.currentTimeMillis())));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user