1
0
mirror of https://e.coding.net/circlecloud/QuickShop.git synced 2025-10-02 12:37:27 +00:00

fix(getOfflinePlayer): 修复getOfflinePlayer卡服问题

This commit is contained in:
502647092
2016-03-31 08:56:28 +08:00
parent 44ec03bd30
commit c2ac919c40
5 changed files with 45 additions and 43 deletions

View File

@ -39,7 +39,7 @@ public class PlayerListener implements Listener {
* Handles players left clicking a chest. Left click a NORMAL chest with
* item : Send creation menu Left click a SHOP chest : Send purchase menu
*/
@EventHandler(priority = EventPriority.MONITOR)
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onClick(final PlayerInteractEvent e) {
final Block b = e.getClickedBlock();
final Player p = e.getPlayer();
@ -154,7 +154,7 @@ public class PlayerListener implements Listener {
plugin.getShopManager().getActions().remove(e.getPlayer().getName());
}
@EventHandler(priority = EventPriority.MONITOR)
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onSuperItemClick(final PlayerInteractEvent e) {
final Player p = e.getPlayer();
if (p.getGameMode() != GameMode.SURVIVAL || e.getMaterial() != plugin.getConfigManager().getSuperItem()) {

View File

@ -114,20 +114,25 @@ public class MsgUtil {
* them in the database.
*/
public static void send(final String player, final String message) {
@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<String>();
player_messages.put(player, msgs);
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<String>();
player_messages.put(player, msgs);
}
msgs.add(message);
final String q = "INSERT INTO messages (owner, message, time) VALUES (?, ?, ?)";
plugin.getDB().execute(q, player.toString(), message, System.currentTimeMillis());
} else {
p.getPlayer().sendMessage(message);
}
}
msgs.add(message);
final String q = "INSERT INTO messages (owner, message, time) VALUES (?, ?, ?)";
plugin.getDB().execute(q, player.toString(), message, System.currentTimeMillis());
} else {
p.getPlayer().sendMessage(message);
}
});
}
public static void sendItemMessage(final Player p, final ItemStack is, final String msg) {
@ -181,8 +186,9 @@ public class MsgUtil {
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()));
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())) {

View File

@ -12,36 +12,26 @@ import org.maxgamer.QuickShop.QuickShop;
public class LogWatcher implements Runnable {
private PrintStream ps;
private ArrayList<String> logs = new ArrayList<String>(5);
private final ArrayList<String> logs = new ArrayList<String>(5);
public BukkitTask task;
public LogWatcher(QuickShop plugin, File log) {
public LogWatcher(final QuickShop plugin, final File log) {
try {
if (!log.exists()) {
log.createNewFile();
}
FileOutputStream fos = new FileOutputStream(log, true);
this.ps = new PrintStream(fos);
} catch (FileNotFoundException e) {
final FileOutputStream fos = new FileOutputStream(log, true);
this.ps = new PrintStream(fos, true, "UTF-8");
} catch (final FileNotFoundException e) {
e.printStackTrace();
plugin.getLogger().severe("日志文件未找到!");
} catch (IOException e) {
} catch (final IOException e) {
e.printStackTrace();
plugin.getLogger().severe("无法创建日志文件!");
}
}
@Override
public void run() {
synchronized (logs) {
for (String s : logs) {
ps.println(s);
}
logs.clear();
}
}
public void add(String s) {
public void add(final String s) {
synchronized (logs) {
logs.add(s);
}
@ -50,4 +40,14 @@ public class LogWatcher implements Runnable {
public void close() {
this.ps.close();
}
@Override
public void run() {
synchronized (logs) {
for (final String s : logs) {
ps.println(s);
}
logs.clear();
}
}
}