mirror of
https://e.coding.net/circlecloud/QuickShop.git
synced 2024-11-22 01:58:54 +00:00
fix: 修复部分包未导入
This commit is contained in:
parent
de3fa516e1
commit
a11686a839
@ -4,15 +4,19 @@ import java.sql.Connection;
|
|||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
public class MySQLCore implements DatabaseCore {
|
public class MySQLCore implements DatabaseCore {
|
||||||
private String url;
|
private String url;
|
||||||
/** The connection properties... user, pass, autoReconnect.. */
|
/**
|
||||||
|
* The connection properties... user, pass, autoReconnect..
|
||||||
|
*/
|
||||||
private Properties info;
|
private Properties info;
|
||||||
private static final int MAX_CONNECTIONS = 8;
|
private static final int MAX_CONNECTIONS = 8;
|
||||||
private static final List<Connection> pool = Collections.synchronizedList(new ArrayList<Connection>());
|
private static final List<Connection> POOL = Collections.synchronizedList(new ArrayList<Connection>());
|
||||||
|
|
||||||
public MySQLCore(String host, String user, String pass, String database, String port) {
|
public MySQLCore(String host, String user, String pass, String database, String port) {
|
||||||
info = new Properties();
|
info = new Properties();
|
||||||
@ -22,8 +26,7 @@ public class MySQLCore implements DatabaseCore {
|
|||||||
info.put("useUnicode", "true");
|
info.put("useUnicode", "true");
|
||||||
info.put("characterEncoding", "utf8");
|
info.put("characterEncoding", "utf8");
|
||||||
this.url = "jdbc:mysql://" + host + ":" + port + "/" + database;
|
this.url = "jdbc:mysql://" + host + ":" + port + "/" + database;
|
||||||
for (int i = 0; i < MAX_CONNECTIONS; i++)
|
for (int i = 0; i < MAX_CONNECTIONS; i++) {POOL.add(null);}
|
||||||
pool.add(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,9 +34,10 @@ public class MySQLCore implements DatabaseCore {
|
|||||||
*
|
*
|
||||||
* @return The database connection
|
* @return The database connection
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public Connection getConnection() {
|
public Connection getConnection() {
|
||||||
for (int i = 0; i < MAX_CONNECTIONS; i++) {
|
for (int i = 0; i < MAX_CONNECTIONS; i++) {
|
||||||
Connection connection = pool.get(i);
|
Connection connection = POOL.get(i);
|
||||||
try {
|
try {
|
||||||
// If we have a current connection, fetch it
|
// If we have a current connection, fetch it
|
||||||
if (connection != null && !connection.isClosed()) {
|
if (connection != null && !connection.isClosed()) {
|
||||||
@ -43,7 +47,7 @@ public class MySQLCore implements DatabaseCore {
|
|||||||
// Else, it is invalid, so we return another connection.
|
// Else, it is invalid, so we return another connection.
|
||||||
}
|
}
|
||||||
connection = DriverManager.getConnection(this.url, info);
|
connection = DriverManager.getConnection(this.url, info);
|
||||||
pool.set(i, connection);
|
POOL.set(i, connection);
|
||||||
return connection;
|
return connection;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.maxgamer.QuickShop.Listeners;
|
package org.maxgamer.QuickShop.Listeners;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -7,12 +8,10 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|||||||
import org.maxgamer.QuickShop.QuickShop;
|
import org.maxgamer.QuickShop.QuickShop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Netherfoam
|
* @author Netherfoam
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ChatListener implements Listener {
|
public class ChatListener implements Listener {
|
||||||
QuickShop plugin;
|
private QuickShop plugin;
|
||||||
|
|
||||||
public ChatListener(final QuickShop plugin) {
|
public ChatListener(final QuickShop plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -24,11 +23,6 @@ public class ChatListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
Bukkit.getScheduler().runTask(plugin, () -> plugin.getShopManager().handleChat(e.getPlayer(), e.getMessage()));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
plugin.getShopManager().handleChat(e.getPlayer(), e.getMessage());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,18 @@
|
|||||||
package org.maxgamer.QuickShop.Shop;
|
package org.maxgamer.QuickShop.Shop;
|
||||||
|
|
||||||
import org.bukkit.*;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Chunk;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
@ -14,12 +26,6 @@ import org.maxgamer.QuickShop.QuickShop;
|
|||||||
import org.maxgamer.QuickShop.Util.MsgUtil;
|
import org.maxgamer.QuickShop.Util.MsgUtil;
|
||||||
import org.maxgamer.QuickShop.Util.Util;
|
import org.maxgamer.QuickShop.Util.Util;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
public class ShopManager {
|
public class ShopManager {
|
||||||
|
|
||||||
private final Map<String, Info> actions = new ConcurrentHashMap<String, Info>();
|
private final Map<String, Info> actions = new ConcurrentHashMap<String, Info>();
|
||||||
@ -61,7 +67,11 @@ public class ShopManager {
|
|||||||
}
|
}
|
||||||
/* 修复其他插件调用产生的报错... */
|
/* 修复其他插件调用产生的报错... */
|
||||||
try {
|
try {
|
||||||
final PlayerInteractEvent pie = new PlayerInteractEvent(p, Action.RIGHT_CLICK_BLOCK, new ItemStack(Material.AIR), b, bf); // PIE = PlayerInteractEvent - What else?
|
final PlayerInteractEvent pie = new PlayerInteractEvent(p,
|
||||||
|
Action.RIGHT_CLICK_BLOCK,
|
||||||
|
new ItemStack(Material.AIR),
|
||||||
|
b,
|
||||||
|
bf); // PIE = PlayerInteractEvent - What else?
|
||||||
Bukkit.getPluginManager().callEvent(pie);
|
Bukkit.getPluginManager().callEvent(pie);
|
||||||
pie.getPlayer().closeInventory(); // If the player has chat open, this will close their chat.
|
pie.getPlayer().closeInventory(); // If the player has chat open, this will close their chat.
|
||||||
if (pie.isCancelled()) { return false; }
|
if (pie.isCancelled()) { return false; }
|
||||||
@ -220,7 +230,8 @@ public class ShopManager {
|
|||||||
final Map<String, Info> actions = getActions();
|
final Map<String, Info> actions = getActions();
|
||||||
// They wanted to do something.
|
// They wanted to do something.
|
||||||
final Info info = actions.remove(p.getName());
|
final Info info = actions.remove(p.getName());
|
||||||
if (info == null) { return; // multithreaded means this can happen
|
if (info == null) {
|
||||||
|
return; // multithreaded means this can happen
|
||||||
}
|
}
|
||||||
/* Creation handling */
|
/* Creation handling */
|
||||||
if (info.getAction() == ShopAction.CREATE) {
|
if (info.getAction() == ShopAction.CREATE) {
|
||||||
@ -342,7 +353,9 @@ public class ShopManager {
|
|||||||
// Tries to check their balance nicely to see if
|
// Tries to check their balance nicely to see if
|
||||||
// they can afford it.
|
// they can afford it.
|
||||||
if (plugin.getEcon().getBalance(shop.getOwner()) < amount * shop.getPrice()) {
|
if (plugin.getEcon().getBalance(shop.getOwner()) < amount * shop.getPrice()) {
|
||||||
p.sendMessage(MsgUtil.p("the-owner-cant-afford-to-buy-from-you", format(amount * shop.getPrice()), format(plugin.getEcon().getBalance(shop.getOwner()))));
|
p.sendMessage(MsgUtil.p("the-owner-cant-afford-to-buy-from-you",
|
||||||
|
format(amount * shop.getPrice()),
|
||||||
|
format(plugin.getEcon().getBalance(shop.getOwner()))));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final ShopPurchaseEvent e = new ShopPurchaseEvent(shop, p, amount);
|
final ShopPurchaseEvent e = new ShopPurchaseEvent(shop, p, amount);
|
||||||
@ -352,7 +365,9 @@ public class ShopManager {
|
|||||||
}
|
}
|
||||||
// Check for plugins faking econ.has(amount)
|
// Check for plugins faking econ.has(amount)
|
||||||
if (!plugin.getEcon().withdraw(shop.getOwner(), total)) {
|
if (!plugin.getEcon().withdraw(shop.getOwner(), total)) {
|
||||||
p.sendMessage(MsgUtil.p("the-owner-cant-afford-to-buy-from-you", format(amount * shop.getPrice()), format(plugin.getEcon().getBalance(shop.getOwner()))));
|
p.sendMessage(MsgUtil.p("the-owner-cant-afford-to-buy-from-you",
|
||||||
|
format(amount * shop.getPrice()),
|
||||||
|
format(plugin.getEcon().getBalance(shop.getOwner()))));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (tax != 0) {
|
if (tax != 0) {
|
||||||
@ -364,7 +379,10 @@ public class ShopManager {
|
|||||||
// Notify the owner of the purchase.
|
// Notify the owner of the purchase.
|
||||||
String msg = MsgUtil.p("player-sold-to-your-store", p.getName(), "" + amount, shop.getDataName());
|
String msg = MsgUtil.p("player-sold-to-your-store", p.getName(), "" + amount, shop.getDataName());
|
||||||
if (space == amount) {
|
if (space == amount) {
|
||||||
msg += "\n" + MsgUtil.p("shop-out-of-space", "" + shop.getLocation().getBlockX(), "" + shop.getLocation().getBlockY(), "" + shop.getLocation().getBlockZ());
|
msg += "\n" + MsgUtil.p("shop-out-of-space",
|
||||||
|
"" + shop.getLocation().getBlockX(),
|
||||||
|
"" + shop.getLocation().getBlockY(),
|
||||||
|
"" + shop.getLocation().getBlockZ());
|
||||||
}
|
}
|
||||||
MsgUtil.send(shop.getOwner(), msg);
|
MsgUtil.send(shop.getOwner(), msg);
|
||||||
}
|
}
|
||||||
@ -426,7 +444,13 @@ public class ShopManager {
|
|||||||
createShop(shop);
|
createShop(shop);
|
||||||
p.sendMessage(MsgUtil.p("success-created-shop"));
|
p.sendMessage(MsgUtil.p("success-created-shop"));
|
||||||
final Location loc = shop.getLocation();
|
final Location loc = shop.getLocation();
|
||||||
plugin.log(String.format("玩家: %s 创建了一个 %s 商店 在 (%s - %s, %s, %s)", p.getName(), shop.getDataName(), loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ()));
|
plugin.log(String.format("玩家: %s 创建了一个 %s 商店 在 (%s - %s, %s, %s)",
|
||||||
|
p.getName(),
|
||||||
|
shop.getDataName(),
|
||||||
|
loc.getWorld().getName(),
|
||||||
|
loc.getX(),
|
||||||
|
loc.getY(),
|
||||||
|
loc.getZ()));
|
||||||
if (!plugin.getConfig().getBoolean("shop.lock")) {
|
if (!plugin.getConfig().getBoolean("shop.lock")) {
|
||||||
// Warn them if they haven't been warned since
|
// Warn them if they haven't been warned since
|
||||||
// reboot
|
// reboot
|
||||||
@ -462,8 +486,7 @@ public class ShopManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* They didn't enter a number. */
|
/* They didn't enter a number. */ catch (final NumberFormatException ex) {
|
||||||
catch (final NumberFormatException ex) {
|
|
||||||
p.sendMessage(MsgUtil.p("shop-creation-cancelled"));
|
p.sendMessage(MsgUtil.p("shop-creation-cancelled"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -485,7 +508,9 @@ public class ShopManager {
|
|||||||
// Check their balance. Works with *most* economy
|
// Check their balance. Works with *most* economy
|
||||||
// plugins*
|
// plugins*
|
||||||
if (plugin.getEcon().getBalance(p.getName()) < amount * shop.getPrice()) {
|
if (plugin.getEcon().getBalance(p.getName()) < amount * shop.getPrice()) {
|
||||||
p.sendMessage(MsgUtil.p("you-cant-afford-to-buy", format(amount * shop.getPrice()), format(plugin.getEcon().getBalance(p.getName()))));
|
p.sendMessage(MsgUtil.p("you-cant-afford-to-buy",
|
||||||
|
format(amount * shop.getPrice()),
|
||||||
|
format(plugin.getEcon().getBalance(p.getName()))));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final ShopPurchaseEvent e = new ShopPurchaseEvent(shop, p, amount);
|
final ShopPurchaseEvent e = new ShopPurchaseEvent(shop, p, amount);
|
||||||
@ -499,7 +524,9 @@ public class ShopManager {
|
|||||||
final double tax = plugin.getConfigManager().getTax();
|
final double tax = plugin.getConfigManager().getTax();
|
||||||
final double total = amount * shop.getPrice();
|
final double total = amount * shop.getPrice();
|
||||||
if (!plugin.getEcon().withdraw(p.getName(), total)) {
|
if (!plugin.getEcon().withdraw(p.getName(), total)) {
|
||||||
p.sendMessage(MsgUtil.p("you-cant-afford-to-buy", format(amount * shop.getPrice()), format(plugin.getEcon().getBalance(p.getName()))));
|
p.sendMessage(MsgUtil.p("you-cant-afford-to-buy",
|
||||||
|
format(amount * shop.getPrice()),
|
||||||
|
format(plugin.getEcon().getBalance(p.getName()))));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!shop.isUnlimited() || plugin.getConfig().getBoolean("shop.pay-unlimited-shop-owners")) {
|
if (!shop.isUnlimited() || plugin.getConfig().getBoolean("shop.pay-unlimited-shop-owners")) {
|
||||||
@ -512,13 +539,21 @@ public class ShopManager {
|
|||||||
if (plugin.getConfigManager().isShowTax()) {
|
if (plugin.getConfigManager().isShowTax()) {
|
||||||
String msg = MsgUtil.p("player-bought-from-your-store-tax", p.getName(), "" + amount, shop.getDataName(), Util.format((tax * total)));
|
String msg = MsgUtil.p("player-bought-from-your-store-tax", p.getName(), "" + amount, shop.getDataName(), Util.format((tax * total)));
|
||||||
if (stock == amount) {
|
if (stock == amount) {
|
||||||
msg += "\n" + MsgUtil.p("shop-out-of-stock", "" + shop.getLocation().getBlockX(), "" + shop.getLocation().getBlockY(), "" + shop.getLocation().getBlockZ(), shop.getDataName());
|
msg += "\n" + MsgUtil.p("shop-out-of-stock",
|
||||||
|
"" + shop.getLocation().getBlockX(),
|
||||||
|
"" + shop.getLocation().getBlockY(),
|
||||||
|
"" + shop.getLocation().getBlockZ(),
|
||||||
|
shop.getDataName());
|
||||||
}
|
}
|
||||||
MsgUtil.send(shop.getOwner(), msg);
|
MsgUtil.send(shop.getOwner(), msg);
|
||||||
} else {
|
} else {
|
||||||
String msg = MsgUtil.p("player-bought-from-your-store", p.getName(), "" + amount, shop.getDataName());
|
String msg = MsgUtil.p("player-bought-from-your-store", p.getName(), "" + amount, shop.getDataName());
|
||||||
if (stock == amount) {
|
if (stock == amount) {
|
||||||
msg += "\n" + MsgUtil.p("shop-out-of-stock", "" + shop.getLocation().getBlockX(), "" + shop.getLocation().getBlockY(), "" + shop.getLocation().getBlockZ(), shop.getDataName());
|
msg += "\n" + MsgUtil.p("shop-out-of-stock",
|
||||||
|
"" + shop.getLocation().getBlockX(),
|
||||||
|
"" + shop.getLocation().getBlockY(),
|
||||||
|
"" + shop.getLocation().getBlockZ(),
|
||||||
|
shop.getDataName());
|
||||||
}
|
}
|
||||||
MsgUtil.send(shop.getOwner(), msg);
|
MsgUtil.send(shop.getOwner(), msg);
|
||||||
}
|
}
|
||||||
@ -582,7 +617,8 @@ public class ShopManager {
|
|||||||
}
|
}
|
||||||
shops = chunks.next().values().iterator();
|
shops = chunks.next().values().iterator();
|
||||||
}
|
}
|
||||||
if (!shops.hasNext()) { return this.next(); // Skip to the next one (Empty iterator?)
|
if (!shops.hasNext()) {
|
||||||
|
return this.next(); // Skip to the next one (Empty iterator?)
|
||||||
}
|
}
|
||||||
current = shops.next();
|
current = shops.next();
|
||||||
return current;
|
return current;
|
||||||
|
Loading…
Reference in New Issue
Block a user