1
0
mirror of https://e.coding.net/circlecloud/QuickShop.git synced 2024-11-21 01:48:54 +00:00

feat: 去除调试 优化检测线程

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2017-05-10 00:04:53 +08:00
parent b3995f3b2f
commit 833fe1ac43
6 changed files with 90 additions and 100 deletions

View File

@ -7,14 +7,11 @@ import java.util.List;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.maxgamer.QuickShop.QuickShop;
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.config.FileConfig;
@ -109,9 +106,9 @@ public class ConfigManager {
plugin.getLogger().info("魔改库功能测试正常...");
this.enableMagicLib = true;
} catch (final Error | Exception e) {
plugin.getLogger().warning("+=========================================");
plugin.getLogger().warning("| 警告: 启动魔改库失败 将使用GUI商店界面...");
plugin.getLogger().warning("+=========================================");
Log.d("+=========================================");
Log.d("| 警告: 启动魔改库失败 将使用GUI商店界面...");
Log.d("+=========================================");
}
}
}

View File

@ -1,12 +1,20 @@
package org.maxgamer.QuickShop;
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.Date;
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.file.FileConfiguration;
import org.bukkit.entity.Player;
@ -18,18 +26,27 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.maxgamer.QuickShop.Command.QuickShopCommands;
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.EconomyCore;
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.Shop;
import org.maxgamer.QuickShop.Shop.ShopManager;
import org.maxgamer.QuickShop.Shop.ShopType;
import org.maxgamer.QuickShop.Util.MsgUtil;
import org.maxgamer.QuickShop.Util.Util;
import org.maxgamer.QuickShop.Watcher.ItemWatcher;
import org.maxgamer.QuickShop.Watcher.LogWatcher;
import pw.yumc.YumCore.config.FileConfig;
@ -49,7 +66,7 @@ public class QuickShop extends JavaPlugin {
private Database database;
/** The economy we hook into for transactions */
private Economy economy;
private BukkitTask itemWatcherTask;
public BukkitTask itemWatcherTask;
private LogWatcher logWatcher;
/** The Shop Manager used to store shops */
private ShopManager shopManager;
@ -61,9 +78,7 @@ public class QuickShop extends JavaPlugin {
* The string to print.
*/
public void debug(final String s) {
if (!configManager.isDebug()) {
return;
}
if (!configManager.isDebug()) { return; }
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.
*/
public void log(final String s) {
if (this.logWatcher == null) {
return;
}
if (this.logWatcher == null) { return; }
final Date date = Calendar.getInstance().getTime();
final Timestamp time = new Timestamp(date.getTime());
this.logWatcher.add("[" + time.toString() + "] " + s);
@ -239,9 +252,7 @@ public class QuickShop extends JavaPlugin {
@Override
public void onEnable() {
if (!loadEcon()) {
return;
}
if (!loadEcon()) { return; }
configManager = new ConfigManager(this);
// Initialize Util
Util.initialize();
@ -303,14 +314,6 @@ public class QuickShop extends JavaPlugin {
pm.registerEvents(new WorldListener(this), this);
pm.registerEvents(new ProtectListener(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
new QuickShopCommands();

View File

@ -11,7 +11,9 @@ import org.bukkit.Material;
import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Listeners.ChunkListener;
import org.maxgamer.QuickShop.Shop.ContainerShop;
import org.maxgamer.QuickShop.Watcher.ItemWatcher;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.bukkit.P;
@ -43,6 +45,13 @@ public abstract class DisplayItem {
}
if (displayItemClass == null) {
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("+=========================================");

View File

@ -13,6 +13,7 @@ import org.bukkit.inventory.ItemStack;
import org.maxgamer.QuickShop.QuickShop;
import org.maxgamer.QuickShop.Shop.Shop;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.config.FileConfig;
import pw.yumc.YumCore.tellraw.Tellraw;
@ -39,7 +40,7 @@ public class MsgUtil {
* The player to message
* @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()) {
final String pName = p.getName();
final LinkedList<String> msgs = player_messages.get(pName);
@ -50,9 +51,7 @@ public class MsgUtil {
plugin.getDB().execute("DELETE FROM messages WHERE owner = ?", pName);
msgs.clear();
}
return true;
}
return false;
}
public static void init(final QuickShop plugin) {
@ -73,16 +72,12 @@ public class MsgUtil {
while (rs.next()) {
final String owner = rs.getString("owner");
final String message = rs.getString("message");
LinkedList<String> msgs = player_messages.get(owner);
if (msgs == null) {
msgs = new LinkedList<>();
player_messages.put(owner, msgs);
}
LinkedList<String> msgs = player_messages.computeIfAbsent(owner, k -> new LinkedList<>());
msgs.add(message);
}
} catch (final SQLException e) {
e.printStackTrace();
plugin.getLogger().warning("无法从数据库获得玩家的交易记录 跳过...");
Log.d("无法从数据库获得玩家的交易记录 跳过...");
}
}
@ -110,23 +105,15 @@ public class MsgUtil {
* them in the database.
*/
public static void send(final String player, final String message) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
@SuppressWarnings("deprecation")
final OfflinePlayer p = Bukkit.getOfflinePlayer(player);
if (p == null || !p.isOnline()) {
LinkedList<String> msgs = player_messages.get(player);
if (msgs == null) {
msgs = new LinkedList<>();
player_messages.put(player, msgs);
}
msgs.add(message);
final String q = "INSERT INTO messages (owner, message, time) VALUES (?, ?, ?)";
plugin.getDB().execute(q, player, message, System.currentTimeMillis());
} else {
p.getPlayer().sendMessage(message);
}
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
final OfflinePlayer p = Bukkit.getOfflinePlayer(player);
if (p == null || !p.isOnline()) {
LinkedList<String> msgs = player_messages.computeIfAbsent(player, k -> new LinkedList<>());
msgs.add(message);
final String q = "INSERT INTO messages (owner, message, time) VALUES (?, ?, ?)";
plugin.getDB().execute(q, player, message, System.currentTimeMillis());
} else {
p.getPlayer().sendMessage(message);
}
});
}
@ -171,43 +158,39 @@ public class MsgUtil {
sendShopInfo(p, shop, shop.getRemainingStock());
}
@SuppressWarnings("deprecation")
public static void sendShopInfo(final Player p, final Shop shop, final int stock) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
// Potentially faster with an array?
final ItemStack item = shop.getItem();
p.sendMessage("");
p.sendMessage("");
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.shop-information"));
p.sendMessage(ChatColor.DARK_PURPLE + "| " + 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());
sendItemMessage(p, shop.getItem(), msg);
if (Util.isTool(item.getType())) {
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.damage-percent-remaining", Util.getToolPercentage(item)));
}
if (shop.isSelling()) {
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.stock", "" + (stock == 10000 ? "无限" : stock)));
} else {
final int space = shop.getRemainingSpace();
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.space", "" + (space == 10000 ? "无限" : space)));
}
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.price-per", shop.getDataName(), Util.format(shop.getPrice())));
if (shop.isBuying()) {
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.this-shop-is-buying"));
} else {
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.this-shop-is-selling"));
}
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
if (shop.isSelling()) {
p.sendMessage(MsgUtil.p("how-many-buy"));
} else {
final int items = Util.countItems(p.getInventory(), shop.getItem());
p.sendMessage(MsgUtil.p("how-many-sell", items));
}
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
// Potentially faster with an array?
final ItemStack item = shop.getItem();
p.sendMessage("");
p.sendMessage("");
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.shop-information"));
p.sendMessage(ChatColor.DARK_PURPLE + "| "
+ 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());
sendItemMessage(p, shop.getItem(), msg);
if (Util.isTool(item.getType())) {
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.damage-percent-remaining", Util.getToolPercentage(item)));
}
if (shop.isSelling()) {
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.stock", "" + (stock == 10000 ? "无限" : stock)));
} else {
final int space = shop.getRemainingSpace();
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.space", "" + (space == 10000 ? "无限" : space)));
}
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.price-per", shop.getDataName(), Util.format(shop.getPrice())));
if (shop.isBuying()) {
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.this-shop-is-buying"));
} else {
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.this-shop-is-selling"));
}
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
if (shop.isSelling()) {
p.sendMessage(MsgUtil.p("how-many-buy"));
} else {
final int items = Util.countItems(p.getInventory(), shop.getItem());
p.sendMessage(MsgUtil.p("how-many-sell", items));
}
});
}

View File

@ -7,7 +7,7 @@ public class NMS {
public static void safeGuard(final Item item) throws ClassNotFoundException {
rename(item.getItemStack());
item.setPickupDelay(2147483647);
item.setPickupDelay(Integer.MAX_VALUE);
}
private static void rename(final ItemStack iStack) {

View File

@ -1,5 +1,11 @@
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.Location;
import org.bukkit.Material;
@ -17,15 +23,8 @@ import org.bukkit.material.MaterialData;
import org.bukkit.material.Sign;
import org.maxgamer.QuickShop.QuickShop;
import pw.yumc.YumCore.bukkit.Log;
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")
public class Util {
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.
*/
public static Block getSecondHalf(final Block b) {
Log.d("%s", b);
if (!b.getType().toString().contains("CHEST")) { return null; }
final Block[] blocks = new Block[4];
blocks[0] = b.getRelative(1, 0, 0);