Skip to content

Commit

Permalink
修复mysql连接问题,修复GUI在无商品数据时出错的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
EnderTheCoder committed Jan 22, 2022
1 parent c662e42 commit 71f75a9
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
7 changes: 7 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/main/java/com/ender/globalmarket/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ public void onEnable() {

Mysql m = new Mysql();

if (!MysqlInit.checkTable("market_log")) MysqlInit.init_market_log();
if (!MysqlInit.checkTable("market_item_data")) MysqlInit.init_market_item_data();

if (!m.mysqlInit()) {
getLogger().warning(ChatColor.RED + "Failed to connect to mysql. Check your config.yml to fix this. Plugin is shutting down.");
getServer().getPluginManager().disablePlugin(this);
} else {
if (!MysqlInit.checkTable("market_log")) MysqlInit.init_market_log();
if (!MysqlInit.checkTable("market_item_data")) MysqlInit.init_market_item_data();

getLogger().info(ChatColor.GREEN + "Mysql connected.");
}
getLogger().info(ChatColor.GREEN + "欢迎使用Ender's Global Market插件,加载成功");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return true;
}

marketItem.x = Integer.parseInt(args[1]);
marketItem.k = Integer.parseInt(args[2]);
marketItem.b = Integer.parseInt(args[3]);
if (marketItem.b > 4 || marketItem.b < 1) {
sender.sendMessage(ChatColor.YELLOW + "[GlobalMarket]你输入的市场稳定指数不合法,我们建议在1-4之间");
return true;
}

marketItem.x = Integer.parseInt(args[1]);
marketItem.k = Integer.parseInt(args[2]);
marketItem.b = Integer.parseInt(args[3]);
MarketData.putMarketItem(marketItem);
sender.sendMessage(ChatColor.GREEN + "[GlobalMarketAdmin]成功设置新的可贸易物品" + marketItem.item.name());
break;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/ender/globalmarket/gui/MarketGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public static List<Inventory> create(Player player) {

int item_counter = 0;

if (pages == 0) pages = 1;

for (int i = 0; i < pages; i++) {
inv.add(Bukkit.createInventory(player, 6 * 9, String.format("全球市场%s/%s", i + 1, pages)));
// int singlePageLim = (i == pages - 1) ? (marketItems.size() % (5 * 9)) : (5 * 9);
Expand Down
12 changes: 3 additions & 9 deletions src/main/java/com/ender/globalmarket/storage/Mysql.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,30 @@ public boolean mysqlInit() {



public Boolean prepareSql(String sql) {
public void prepareSql(String sql) {
try {
statement = getConnection().prepareStatement(sql);
return true;
} catch (SQLException e) {
getLogger().warning(ChatColor.RED + "An error in mysql occurred while preparing sql.");
e.printStackTrace();
return false;
}
}

public Boolean setData(Integer number,String data) {
public void setData(Integer number,String data) {
try {
statement.setString(number, data);
return true;
} catch (SQLException e) {
getLogger().warning(ChatColor.RED + "An error in mysql occurred while binding data for sql.");
e.printStackTrace();
return false;
}
}

public Boolean execute() {
public void execute() {
try {
statement.execute();
return true;
} catch (SQLException e) {
getLogger().warning(ChatColor.RED + "An error in mysql occurred while executing sql.");
e.printStackTrace();
return false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static boolean checkTable(String tableName) {
m.execute();
ResultSet resultSet = m.getResult();
try {
return resultSet.getRow() > 0;
return resultSet.getFetchSize() > 0;
} catch (SQLException exception) {
exception.printStackTrace();
return false;
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ Mysql.DataBaseName: database

#贸易税率,收税上交给经济第一的人
TaxRate: 0.005
EnableNoTax: true
#启用VIP免税功能,需要插件ECS-LOGIN
EnableNoTax: false
#贸易超时时间,即玩家在GUI界面点击贸易时超时时间,单位是秒
TimeOut.Trade: 10

0 comments on commit 71f75a9

Please sign in to comment.