mirror of
https://github.com/kiranhart/Auction-House.git
synced 2025-01-07 12:47:36 +01:00
Command reworks
This commit is contained in:
parent
405ae278b7
commit
535ce102f7
6
pom.xml
6
pom.xml
@ -98,5 +98,11 @@
|
||||
<artifactId>http-request</artifactId>
|
||||
<version>6.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>LATEST</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -14,6 +14,7 @@ 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 com.zaxxer.hikari.HikariDataSource;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -25,9 +26,6 @@ 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;
|
||||
@ -57,9 +55,7 @@ public final class Core extends JavaPlugin {
|
||||
public List<AuctionItem> auctionItems;
|
||||
|
||||
//Database
|
||||
private Connection connection;
|
||||
public String host, database, username, password;
|
||||
public int port;
|
||||
private HikariDataSource hikari;
|
||||
public boolean dbConnected;
|
||||
|
||||
//Timing
|
||||
@ -95,7 +91,19 @@ public final class Core extends JavaPlugin {
|
||||
initEvents();
|
||||
initStorage();
|
||||
|
||||
if (getConfig().getBoolean("database.enabled")) mysqlSetup();
|
||||
if (getConfig().getBoolean("database.enabled")) {
|
||||
hikari = new HikariDataSource();
|
||||
hikari.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
|
||||
hikari.addDataSourceProperty("serverName", getConfig().getString("database.host"));
|
||||
hikari.addDataSourceProperty("port", getConfig().getInt("database.port"));
|
||||
hikari.addDataSourceProperty("databaseName", getConfig().getString("database.database"));
|
||||
hikari.addDataSourceProperty("user", getConfig().getString("database.username"));
|
||||
hikari.addDataSourceProperty("password", getConfig().getString("database.password"));
|
||||
if(!hikari.isClosed()) {
|
||||
dbConnected = true;
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&aConnected to database"));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
MassiveStats stats = new MassiveStats(this);
|
||||
@ -112,52 +120,8 @@ public final class Core extends JavaPlugin {
|
||||
@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;
|
||||
}
|
||||
|
||||
connect();
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
try {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
setConnection(DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password));
|
||||
} catch (SQLException e) {
|
||||
Debugger.report(e);
|
||||
} 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;
|
||||
if (hikari != null)
|
||||
hikari.close();
|
||||
}
|
||||
|
||||
private void loadAuctions() {
|
||||
@ -338,4 +302,8 @@ public final class Core extends JavaPlugin {
|
||||
public Settings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
public HikariDataSource getHikari() {
|
||||
return hikari;
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,10 @@ public enum Permissions {
|
||||
|
||||
BASE("AuctionHouse"),
|
||||
RELOAD_CMD(BASE.getNode() + ".cmd.reload"),
|
||||
HELP_CMD(BASE.getNode() + ".cmd.help"),
|
||||
SELL_CMD(BASE.getNode() + ".cmd.sell"),
|
||||
EXPIRED_CMD(BASE.getNode() + ".cmd.expired"),
|
||||
LISTINGS_CMD(BASE.getNode() + ".cmd.listings"),
|
||||
MAX_AUCTIONS(BASE.getNode() + ".maxauctions"),
|
||||
;
|
||||
|
||||
|
@ -3,9 +3,12 @@ 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.ExpiredCommand;
|
||||
import com.shadebyte.auctionhouse.cmds.subcmds.ListedCommand;
|
||||
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.inventory.inventories.ListingsGUI;
|
||||
import com.shadebyte.auctionhouse.util.Debugger;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -42,6 +45,8 @@ public class CommandManager implements CommandExecutor {
|
||||
Core.getInstance().getCommand(main).setExecutor(this);
|
||||
this.commands.add(new SellCommand());
|
||||
this.commands.add(new ReloadCommand());
|
||||
this.commands.add(new ListedCommand());
|
||||
this.commands.add(new ExpiredCommand());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,10 +1,45 @@
|
||||
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.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 HelpCommand {
|
||||
public class HelpCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
|
||||
if (!sender.hasPermission(Permissions.HELP_CMD.getNode())) {
|
||||
sender.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.NO_PERMISSION.getNode()));
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i <= 7; i++) {
|
||||
sender.sendMessage(Core.getInstance().getLocale().getMessage("cmd.help." + i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return Core.getInstance().getCommandManager().help;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String info() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] aliases() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,51 @@
|
||||
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 com.shadebyte.auctionhouse.inventory.inventories.ListingsGUI;
|
||||
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 ListedCommand {
|
||||
public class ListedCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
|
||||
if (!sender.hasPermission(Permissions.LISTINGS_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 ListingsGUI(p).getInventory());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return Core.getInstance().getCommandManager().listed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String info() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] aliases() {
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
|
@ -28,13 +28,10 @@ public class ReloadCommand extends SubCommand {
|
||||
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();
|
||||
|
@ -62,21 +62,6 @@ 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).getLimit() - 1 < new AuctionPlayer(p).getTotalActiveAuctions()) {
|
||||
|
@ -7,7 +7,9 @@ import com.shadebyte.auctionhouse.util.Debugger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
@ -18,13 +20,10 @@ import java.sql.PreparedStatement;
|
||||
public class MySQL {
|
||||
|
||||
public void logTransaction(Transaction transaction) {
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(Core.getInstance(), () -> {
|
||||
try {
|
||||
if (Core.getInstance().getConnection().isClosed() || !Core.getInstance().dbConnected || Core.getInstance().getConnection() == null) {
|
||||
Core.getInstance().connect();
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&cDatabase connection is close, attempting re-connect"));
|
||||
}
|
||||
PreparedStatement insert = Core.getInstance().getConnection().prepareStatement("INSERT INTO transactions (buyer, seller, auctiontype, startprice, buynowprice, increment, item, displayname, lore, enchantments, auctionid, timesold, finalprice) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(Core.getInstance(), ()->{
|
||||
try (Connection connection = Core.getInstance().getHikari().getConnection();
|
||||
PreparedStatement insert = connection.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());
|
||||
@ -42,7 +41,8 @@ public class MySQL {
|
||||
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) {
|
||||
|
||||
} catch (SQLException e) {
|
||||
Debugger.report(e);
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&cCould not save the transaction to the database, saved to transactions.yml"));
|
||||
}
|
||||
|
@ -21,15 +21,15 @@ settings:
|
||||
#MySql stuff for databases if you want
|
||||
database:
|
||||
enabled: true
|
||||
host: 162.241.217.18
|
||||
port: 3306
|
||||
host:
|
||||
port:
|
||||
database: "kiranhar_auctionhouse"
|
||||
username: "kiranhar_admin"
|
||||
password: "TweetyHart1."
|
||||
password: ""
|
||||
|
||||
discord:
|
||||
enabled: true
|
||||
webhook: "https://discordapp.com/api/webhooks/470085392901734410/_ls7Ps5GzlKqBJlHLaZt6GZgVTKkuwuIuWK1JU5j_pt-DwWhSYAITlI17ePiIuNTmdua"
|
||||
webhook: ""
|
||||
title: "Auction House"
|
||||
description: "A new item has been listed!"
|
||||
description-complete: "A transaction has been completed!"
|
||||
|
@ -3,6 +3,14 @@ prefix = "&8[&eAuctionHouse&8]"
|
||||
cmd.invalid = "&cThat isn't a valid subcommand!"
|
||||
cmd.sell = "&e/ah sell <buyNowPrice> <startPrice> <bidIncrement>"
|
||||
|
||||
cmd.help.1 = "&e&lAuction House"
|
||||
cmd.help.2 = ""
|
||||
cmd.help.3 = "&f/&eah help"
|
||||
cmd.help.4 = "&f/&eah sell"
|
||||
cmd.help.5 = "&f/&eah listed"
|
||||
cmd.help.6 = "&f/&eah expired"
|
||||
cmd.help.7 = ""
|
||||
|
||||
nopermission = "&cYou do not have permission to do that!"
|
||||
playersonly = "&cOnly player's may use the command!"
|
||||
notanumber = "&CThat isn't a valid number"
|
||||
|
@ -13,6 +13,9 @@ public class ServerTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.out.println(new SimpleDateFormat("MMMM dd yyyy").format(new Date(System.currentTimeMillis())));
|
||||
for (int i = 1; i <= 7; i++) {
|
||||
System.out.println(i);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user