Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/main/java/net/IchigyouRuri/Mail/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import cn.nukkit.utils.TextFormat;
import net.IchigyouRuri.Mail.Utils.load.*;
import net.IchigyouRuri.Mail.mailsN.listener.MailListener;
import net.IchigyouRuri.Mail.mailsN.listener.PlayerListener;
import net.IchigyouRuri.Mail.mailsN.math.MailWindowMath;

public class Main extends PluginBase {
Expand All @@ -16,16 +17,14 @@ public class Main extends PluginBase {
@Override
public void onDisable() {
this.getLogger().info(TextFormat.GREEN + "MailSystem Disable");


this.getLogger().info(TextFormat.GREEN+"线程池关闭...");
}

@Override
public void onEnable() {
plugin = this;
this.getLogger().info(TextFormat.GREEN + "MailSystem Loading");
//加载监听器
this.getServer().getPluginManager().registerEvents(new net.IchigyouRuri.Mail.mailsN.listener.PlayerListener(),this);
this.getServer().getPluginManager().registerEvents(new PlayerListener(),this);
this.getServer().getPluginManager().registerEvents(new MailListener(),this);
this.getLogger().info(TextFormat.GREEN+"监听器注册完毕!");

Expand All @@ -36,19 +35,22 @@ public void onEnable() {
LoadMails.loadMails();
LoadAuction.loadAuctionData();

//启动线程
this.getLogger().info(TextFormat.GREEN+"检查线程已启动!");
this.getLogger().info(TextFormat.GREEN+"MailSystem 加载完成!");
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
switch (command.getName()){
case "mail":
((Player)sender).showFormWindow(MailWindowMath.getMenu((Player)sender));
return true;
case "maila":
((Player)sender).showFormWindow(MailWindowMath.getGlobalSendMailWindow((Player)sender));
return true;
if (sender instanceof Player) {
switch (command.getName()) {
case "mail":
((Player) sender).showFormWindow(MailWindowMath.getMenu((Player) sender));
return true;
case "maila":
((Player) sender).showFormWindow(MailWindowMath.getGlobalSendMailWindow((Player) sender));
return true;
}
} else {
sender.sendMessage(TextFormat.RED + "请在游戏内使用此命令");
}
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/IchigyouRuri/Mail/Utils/load/LoadCfg.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class LoadCfg {
public static String globalMailTitle="",globalMailText="",globalMailBtPersonalText="",globalMailBtGlobalText="",globalMailListMenuTitle="";
public static String auctionTitle="",auctionText="",auctionBtShop="",auctionBtAuction="",auctionShopTitle="",auctionGoodsTitle="",auctionInfoTitle="",auctionAddPriceTitle="";
public static float chargeSellMoney=0f,chargeSellPoint=0f,chargeBuyMoney=0f,chargeBuyPoint=0f,aBankMoney=0f,aBankPoint=0f;
public static int keepDay=7,maxSell=3,mailAutoLookTick=15000,watchDog=15*1000*60,auctionKeepDay=1,auctionMax=3;
public static int keepDay=7,maxSell=3,mailAutoLookTick=15,watchDog=15*1000*60,auctionKeepDay=1,auctionMax=3;
public static void loadCfg(){
if(!new File(Main.getPlugin().getDataFolder(), "config.yml").exists()) {
Main.getPlugin().getLogger().info(TextFormat.BLUE+"未找到config.yml,正在创建...");
Expand All @@ -52,7 +52,7 @@ public static void reLoadCfg(){
auctionMax=cfg.getInt("Auction.Max");

mailsAutoLook=cfg.getString("Mails.AutoLook").replaceAll("&","§");
mailAutoLookTick=cfg.getInt("Mail.Wait")*1000;
mailAutoLookTick=cfg.getInt("Mail.Wait")*20;

menuTitle=cfg.getString("Gui.Menu.Title").replaceAll("&","§");
menuText=cfg.getString("Gui.Menu.Text").replaceAll("&","§");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.IchigyouRuri.Mail.mailsN.listener;

import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.event.EventHandler;
import cn.nukkit.event.Listener;
import cn.nukkit.event.player.PlayerJoinEvent;
Expand All @@ -11,25 +12,20 @@
import net.IchigyouRuri.Mail.Utils.load.LoadMails;
import net.IchigyouRuri.Mail.Main;
import net.IchigyouRuri.Mail.mailsN.math.MailWindowMath;
import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

public class PlayerListener implements Listener {
private static ThreadFactory threadFactory=new ThreadFactoryBuilder().setNameFormat("my-pool-%d").build();
public static ExecutorService sigleThreadPool = new ThreadPoolExecutor(1,1,0L,
TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(1024),threadFactory,new ThreadPoolExecutor.AbortPolicy());

/**
* 创建用户邮箱文件
* @param e 玩家加入事件
*/
@EventHandler
public void onPlayerJoins(PlayerJoinEvent e){
public void onPlayerJoin(PlayerJoinEvent e){
Player p = e.getPlayer();
File pf=new File(Main.getPlugin().getDataFolder()+File.separator+"Players"+File.separator+"Mail",p.getName()+".yml");
if(!pf.exists()) {
Expand Down Expand Up @@ -60,15 +56,15 @@ public void onPlayerJoins(PlayerJoinEvent e){
p.sendMessage(LoadLang.title+LoadLang.mailHas.replaceAll("<count>",(count)+""));
}
}

this.checkUnreadEmail(p);
}

/**
* 检查玩家是否有未读邮件,并弹出
* @param e
* @param p 玩家
*/
@EventHandler
public void onPlayerJoinGameEvent(PlayerJoinEvent e){
Player p = e.getPlayer();
public void checkUnreadEmail(Player p){
File pf=new File(Main.getPlugin().getDataFolder()+File.separator+"Players"+File.separator+"Mail",p.getName()+".yml");
if(!pf.exists()) {
return;
Expand All @@ -78,15 +74,10 @@ public void onPlayerJoinGameEvent(PlayerJoinEvent e){
for(String key: LoadMails.globalMails.getKeys(false)){
if(!hasLookedMails.contains(key)){
if(LoadMails.globalMails.getBoolean(key+".AutoLook")){
//休眠 xxS 后弹出界面
sigleThreadPool.execute(() -> {
try {
Thread.sleep(LoadCfg.mailAutoLookTick);
p.showFormWindow(MailWindowMath.getGlobalMailListWindow(p));
} catch (InterruptedException ex) {
ex.printStackTrace();
}
});
//延迟 xxS 后弹出界面
Server.getInstance().getScheduler().scheduleDelayedTask(Main.getPlugin(), () -> {
p.showFormWindow(MailWindowMath.getGlobalMailListWindow(p));
}, LoadCfg.mailAutoLookTick);
break;
}
}
Expand Down