mirror of
https://e.coding.net/circlecloud/QuickShop.git
synced 2024-11-25 02:28:54 +00:00
feat: 去除调试 优化检测线程
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
b3995f3b2f
commit
833fe1ac43
@ -7,14 +7,11 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.maxgamer.QuickShop.QuickShop;
|
import org.maxgamer.QuickShop.QuickShop;
|
||||||
import org.maxgamer.QuickShop.Shop.Item.DisplayItem;
|
import org.maxgamer.QuickShop.Shop.Item.DisplayItem;
|
||||||
import org.maxgamer.QuickShop.Shop.Item.FakeItem_18;
|
|
||||||
import org.maxgamer.QuickShop.Shop.Item.FakeItem_19_111;
|
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
import pw.yumc.YumCore.config.FileConfig;
|
import pw.yumc.YumCore.config.FileConfig;
|
||||||
@ -109,9 +106,9 @@ public class ConfigManager {
|
|||||||
plugin.getLogger().info("魔改库功能测试正常...");
|
plugin.getLogger().info("魔改库功能测试正常...");
|
||||||
this.enableMagicLib = true;
|
this.enableMagicLib = true;
|
||||||
} catch (final Error | Exception e) {
|
} catch (final Error | Exception e) {
|
||||||
plugin.getLogger().warning("+=========================================");
|
Log.d("+=========================================");
|
||||||
plugin.getLogger().warning("| 警告: 启动魔改库失败 将使用GUI商店界面...");
|
Log.d("| 警告: 启动魔改库失败 将使用GUI商店界面...");
|
||||||
plugin.getLogger().warning("+=========================================");
|
Log.d("+=========================================");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,20 @@
|
|||||||
package org.maxgamer.QuickShop;
|
package org.maxgamer.QuickShop;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.sql.*;
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.bukkit.*;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -18,18 +26,27 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import org.maxgamer.QuickShop.Command.QuickShopCommands;
|
import org.maxgamer.QuickShop.Command.QuickShopCommands;
|
||||||
import org.maxgamer.QuickShop.Config.ConfigManager;
|
import org.maxgamer.QuickShop.Config.ConfigManager;
|
||||||
import org.maxgamer.QuickShop.Database.*;
|
import org.maxgamer.QuickShop.Database.Database;
|
||||||
|
import org.maxgamer.QuickShop.Database.DatabaseCore;
|
||||||
|
import org.maxgamer.QuickShop.Database.DatabaseHelper;
|
||||||
|
import org.maxgamer.QuickShop.Database.MySQLCore;
|
||||||
|
import org.maxgamer.QuickShop.Database.SQLiteCore;
|
||||||
import org.maxgamer.QuickShop.Economy.Economy;
|
import org.maxgamer.QuickShop.Economy.Economy;
|
||||||
import org.maxgamer.QuickShop.Economy.EconomyCore;
|
import org.maxgamer.QuickShop.Economy.EconomyCore;
|
||||||
import org.maxgamer.QuickShop.Economy.Economy_Vault;
|
import org.maxgamer.QuickShop.Economy.Economy_Vault;
|
||||||
import org.maxgamer.QuickShop.Listeners.*;
|
import org.maxgamer.QuickShop.Listeners.BlockListener;
|
||||||
|
import org.maxgamer.QuickShop.Listeners.ChatListener;
|
||||||
|
import org.maxgamer.QuickShop.Listeners.LockListener;
|
||||||
|
import org.maxgamer.QuickShop.Listeners.PlayerListener;
|
||||||
|
import org.maxgamer.QuickShop.Listeners.ProtectListener;
|
||||||
|
import org.maxgamer.QuickShop.Listeners.WorldListener;
|
||||||
|
import org.maxgamer.QuickShop.Listeners.WowSuchCleanerListener;
|
||||||
import org.maxgamer.QuickShop.Shop.ContainerShop;
|
import org.maxgamer.QuickShop.Shop.ContainerShop;
|
||||||
import org.maxgamer.QuickShop.Shop.Shop;
|
import org.maxgamer.QuickShop.Shop.Shop;
|
||||||
import org.maxgamer.QuickShop.Shop.ShopManager;
|
import org.maxgamer.QuickShop.Shop.ShopManager;
|
||||||
import org.maxgamer.QuickShop.Shop.ShopType;
|
import org.maxgamer.QuickShop.Shop.ShopType;
|
||||||
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 org.maxgamer.QuickShop.Watcher.ItemWatcher;
|
|
||||||
import org.maxgamer.QuickShop.Watcher.LogWatcher;
|
import org.maxgamer.QuickShop.Watcher.LogWatcher;
|
||||||
|
|
||||||
import pw.yumc.YumCore.config.FileConfig;
|
import pw.yumc.YumCore.config.FileConfig;
|
||||||
@ -49,7 +66,7 @@ public class QuickShop extends JavaPlugin {
|
|||||||
private Database database;
|
private Database database;
|
||||||
/** The economy we hook into for transactions */
|
/** The economy we hook into for transactions */
|
||||||
private Economy economy;
|
private Economy economy;
|
||||||
private BukkitTask itemWatcherTask;
|
public BukkitTask itemWatcherTask;
|
||||||
private LogWatcher logWatcher;
|
private LogWatcher logWatcher;
|
||||||
/** The Shop Manager used to store shops */
|
/** The Shop Manager used to store shops */
|
||||||
private ShopManager shopManager;
|
private ShopManager shopManager;
|
||||||
@ -61,9 +78,7 @@ public class QuickShop extends JavaPlugin {
|
|||||||
* The string to print.
|
* The string to print.
|
||||||
*/
|
*/
|
||||||
public void debug(final String s) {
|
public void debug(final String s) {
|
||||||
if (!configManager.isDebug()) {
|
if (!configManager.isDebug()) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.getLogger().info(ChatColor.YELLOW + "[Debug] " + s);
|
this.getLogger().info(ChatColor.YELLOW + "[Debug] " + s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,9 +218,7 @@ public class QuickShop extends JavaPlugin {
|
|||||||
* The string to log. It will be prefixed with the date and time.
|
* The string to log. It will be prefixed with the date and time.
|
||||||
*/
|
*/
|
||||||
public void log(final String s) {
|
public void log(final String s) {
|
||||||
if (this.logWatcher == null) {
|
if (this.logWatcher == null) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Date date = Calendar.getInstance().getTime();
|
final Date date = Calendar.getInstance().getTime();
|
||||||
final Timestamp time = new Timestamp(date.getTime());
|
final Timestamp time = new Timestamp(date.getTime());
|
||||||
this.logWatcher.add("[" + time.toString() + "] " + s);
|
this.logWatcher.add("[" + time.toString() + "] " + s);
|
||||||
@ -239,9 +252,7 @@ public class QuickShop extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
if (!loadEcon()) {
|
if (!loadEcon()) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
configManager = new ConfigManager(this);
|
configManager = new ConfigManager(this);
|
||||||
// Initialize Util
|
// Initialize Util
|
||||||
Util.initialize();
|
Util.initialize();
|
||||||
@ -303,14 +314,6 @@ public class QuickShop extends JavaPlugin {
|
|||||||
pm.registerEvents(new WorldListener(this), this);
|
pm.registerEvents(new WorldListener(this), this);
|
||||||
pm.registerEvents(new ProtectListener(this), this);
|
pm.registerEvents(new ProtectListener(this), this);
|
||||||
pm.registerEvents(new ChatListener(this), this);
|
pm.registerEvents(new ChatListener(this), this);
|
||||||
if (configManager.isDisplay()) {
|
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(new ChunkListener(this), this);
|
|
||||||
// Display item handler thread
|
|
||||||
getLogger().info("开启商店检查以及悬浮物刷新线程...");
|
|
||||||
final ItemWatcher itemWatcher = new ItemWatcher(this);
|
|
||||||
itemWatcherTask = Bukkit.getScheduler().runTaskTimer(this, itemWatcher, 20, 1800);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Command handlers
|
// Command handlers
|
||||||
new QuickShopCommands();
|
new QuickShopCommands();
|
||||||
|
|
||||||
|
@ -11,7 +11,9 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.maxgamer.QuickShop.QuickShop;
|
import org.maxgamer.QuickShop.QuickShop;
|
||||||
|
import org.maxgamer.QuickShop.Listeners.ChunkListener;
|
||||||
import org.maxgamer.QuickShop.Shop.ContainerShop;
|
import org.maxgamer.QuickShop.Shop.ContainerShop;
|
||||||
|
import org.maxgamer.QuickShop.Watcher.ItemWatcher;
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
import pw.yumc.YumCore.bukkit.P;
|
import pw.yumc.YumCore.bukkit.P;
|
||||||
@ -43,6 +45,13 @@ public abstract class DisplayItem {
|
|||||||
}
|
}
|
||||||
if (displayItemClass == null) {
|
if (displayItemClass == null) {
|
||||||
displayItemClass = NormalItem.class;
|
displayItemClass = NormalItem.class;
|
||||||
|
if (plugin.getConfigManager().isDisplay()) {
|
||||||
|
Bukkit.getServer().getPluginManager().registerEvents(new ChunkListener(plugin), plugin);
|
||||||
|
// Display item handler thread
|
||||||
|
Log.i("开启商店检查以及悬浮物刷新线程...");
|
||||||
|
final ItemWatcher itemWatcher = new ItemWatcher(plugin);
|
||||||
|
plugin.itemWatcherTask = Bukkit.getScheduler().runTaskTimer(plugin, itemWatcher, 20, 1800);
|
||||||
|
}
|
||||||
Log.w("+=========================================");
|
Log.w("+=========================================");
|
||||||
Log.w("| 警告: 启动虚拟物品失败 使用原版悬浮物品...");
|
Log.w("| 警告: 启动虚拟物品失败 使用原版悬浮物品...");
|
||||||
Log.w("+=========================================");
|
Log.w("+=========================================");
|
||||||
|
@ -13,6 +13,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.maxgamer.QuickShop.QuickShop;
|
import org.maxgamer.QuickShop.QuickShop;
|
||||||
import org.maxgamer.QuickShop.Shop.Shop;
|
import org.maxgamer.QuickShop.Shop.Shop;
|
||||||
|
|
||||||
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
import pw.yumc.YumCore.config.FileConfig;
|
import pw.yumc.YumCore.config.FileConfig;
|
||||||
import pw.yumc.YumCore.tellraw.Tellraw;
|
import pw.yumc.YumCore.tellraw.Tellraw;
|
||||||
|
|
||||||
@ -39,7 +40,7 @@ public class MsgUtil {
|
|||||||
* The player to message
|
* The player to message
|
||||||
* @return true if success, false if the player is offline or null
|
* @return true if success, false if the player is offline or null
|
||||||
*/
|
*/
|
||||||
public static boolean flush(final OfflinePlayer p) {
|
public static void flush(final OfflinePlayer p) {
|
||||||
if (p != null && p.isOnline()) {
|
if (p != null && p.isOnline()) {
|
||||||
final String pName = p.getName();
|
final String pName = p.getName();
|
||||||
final LinkedList<String> msgs = player_messages.get(pName);
|
final LinkedList<String> msgs = player_messages.get(pName);
|
||||||
@ -50,9 +51,7 @@ public class MsgUtil {
|
|||||||
plugin.getDB().execute("DELETE FROM messages WHERE owner = ?", pName);
|
plugin.getDB().execute("DELETE FROM messages WHERE owner = ?", pName);
|
||||||
msgs.clear();
|
msgs.clear();
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init(final QuickShop plugin) {
|
public static void init(final QuickShop plugin) {
|
||||||
@ -73,16 +72,12 @@ public class MsgUtil {
|
|||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
final String owner = rs.getString("owner");
|
final String owner = rs.getString("owner");
|
||||||
final String message = rs.getString("message");
|
final String message = rs.getString("message");
|
||||||
LinkedList<String> msgs = player_messages.get(owner);
|
LinkedList<String> msgs = player_messages.computeIfAbsent(owner, k -> new LinkedList<>());
|
||||||
if (msgs == null) {
|
|
||||||
msgs = new LinkedList<>();
|
|
||||||
player_messages.put(owner, msgs);
|
|
||||||
}
|
|
||||||
msgs.add(message);
|
msgs.add(message);
|
||||||
}
|
}
|
||||||
} catch (final SQLException e) {
|
} catch (final SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
plugin.getLogger().warning("无法从数据库获得玩家的交易记录 跳过...");
|
Log.d("无法从数据库获得玩家的交易记录 跳过...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,24 +105,16 @@ public class MsgUtil {
|
|||||||
* them in the database.
|
* them in the database.
|
||||||
*/
|
*/
|
||||||
public static void send(final String player, final String message) {
|
public static void send(final String player, final String message) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
final OfflinePlayer p = Bukkit.getOfflinePlayer(player);
|
final OfflinePlayer p = Bukkit.getOfflinePlayer(player);
|
||||||
if (p == null || !p.isOnline()) {
|
if (p == null || !p.isOnline()) {
|
||||||
LinkedList<String> msgs = player_messages.get(player);
|
LinkedList<String> msgs = player_messages.computeIfAbsent(player, k -> new LinkedList<>());
|
||||||
if (msgs == null) {
|
|
||||||
msgs = new LinkedList<>();
|
|
||||||
player_messages.put(player, msgs);
|
|
||||||
}
|
|
||||||
msgs.add(message);
|
msgs.add(message);
|
||||||
final String q = "INSERT INTO messages (owner, message, time) VALUES (?, ?, ?)";
|
final String q = "INSERT INTO messages (owner, message, time) VALUES (?, ?, ?)";
|
||||||
plugin.getDB().execute(q, player, message, System.currentTimeMillis());
|
plugin.getDB().execute(q, player, message, System.currentTimeMillis());
|
||||||
} else {
|
} else {
|
||||||
p.getPlayer().sendMessage(message);
|
p.getPlayer().sendMessage(message);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,19 +158,16 @@ public class MsgUtil {
|
|||||||
sendShopInfo(p, shop, shop.getRemainingStock());
|
sendShopInfo(p, shop, shop.getRemainingStock());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public static void sendShopInfo(final Player p, final Shop shop, final int stock) {
|
public static void sendShopInfo(final Player p, final Shop shop, final int stock) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
// Potentially faster with an array?
|
// Potentially faster with an array?
|
||||||
final ItemStack item = shop.getItem();
|
final ItemStack item = shop.getItem();
|
||||||
p.sendMessage("");
|
p.sendMessage("");
|
||||||
p.sendMessage("");
|
p.sendMessage("");
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
|
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.shop-information"));
|
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.shop-information"));
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.owner",
|
p.sendMessage(ChatColor.DARK_PURPLE + "| "
|
||||||
Bukkit.getOfflinePlayer(shop.getOwner()).getName() == null ? (shop.isUnlimited() ? "系统商店" : "未知") : Bukkit.getOfflinePlayer(shop.getOwner()).getName()));
|
+ MsgUtil.p("menu.owner", Bukkit.getOfflinePlayer(shop.getOwner()).getName() == null ? (shop.isUnlimited() ? "系统商店" : "未知") : Bukkit.getOfflinePlayer(shop.getOwner()).getName()));
|
||||||
final String msg = ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.item", shop.getDataName());
|
final String msg = ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.item", shop.getDataName());
|
||||||
sendItemMessage(p, shop.getItem(), msg);
|
sendItemMessage(p, shop.getItem(), msg);
|
||||||
if (Util.isTool(item.getType())) {
|
if (Util.isTool(item.getType())) {
|
||||||
@ -208,7 +192,6 @@ public class MsgUtil {
|
|||||||
final int items = Util.countItems(p.getInventory(), shop.getItem());
|
final int items = Util.countItems(p.getInventory(), shop.getItem());
|
||||||
p.sendMessage(MsgUtil.p("how-many-sell", items));
|
p.sendMessage(MsgUtil.p("how-many-sell", items));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ public class NMS {
|
|||||||
|
|
||||||
public static void safeGuard(final Item item) throws ClassNotFoundException {
|
public static void safeGuard(final Item item) throws ClassNotFoundException {
|
||||||
rename(item.getItemStack());
|
rename(item.getItemStack());
|
||||||
item.setPickupDelay(2147483647);
|
item.setPickupDelay(Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void rename(final ItemStack iStack) {
|
private static void rename(final ItemStack iStack) {
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
package org.maxgamer.QuickShop.Util;
|
package org.maxgamer.QuickShop.Util;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -17,15 +23,8 @@ import org.bukkit.material.MaterialData;
|
|||||||
import org.bukkit.material.Sign;
|
import org.bukkit.material.Sign;
|
||||||
import org.maxgamer.QuickShop.QuickShop;
|
import org.maxgamer.QuickShop.QuickShop;
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
|
||||||
import pw.yumc.YumCore.global.L10N;
|
import pw.yumc.YumCore.global.L10N;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class Util {
|
public class Util {
|
||||||
private static HashSet<Material> blacklist = new HashSet<>();
|
private static HashSet<Material> blacklist = new HashSet<>();
|
||||||
@ -178,7 +177,6 @@ public class Util {
|
|||||||
* @return the block which is also a chest and connected to b.
|
* @return the block which is also a chest and connected to b.
|
||||||
*/
|
*/
|
||||||
public static Block getSecondHalf(final Block b) {
|
public static Block getSecondHalf(final Block b) {
|
||||||
Log.d("%s", b);
|
|
||||||
if (!b.getType().toString().contains("CHEST")) { return null; }
|
if (!b.getType().toString().contains("CHEST")) { return null; }
|
||||||
final Block[] blocks = new Block[4];
|
final Block[] blocks = new Block[4];
|
||||||
blocks[0] = b.getRelative(1, 0, 0);
|
blocks[0] = b.getRelative(1, 0, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user