Fix #53
This commit is contained in:
@@ -47,8 +47,8 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
|
|||||||
{
|
{
|
||||||
put("MessageBox", "");
|
put("MessageBox", "");
|
||||||
put("AWTError", "");
|
put("AWTError", "");
|
||||||
put("JFileChooser", "Has your operating system been installed completely or is a ghost system? ");
|
put("JFileChooser", "Has your operating system been installed completely or is a ghost system?");
|
||||||
put("Jce", "Has your operating system been installed completely or is a ghost system? ");
|
put("Jce", "Has your operating system been installed completely or is a ghost system?");
|
||||||
put("couldn't create component peer", "Fucking computer!");
|
put("couldn't create component peer", "Fucking computer!");
|
||||||
put("sun.awt.shell.Win32ShellFolder2", "crash.user_fault");
|
put("sun.awt.shell.Win32ShellFolder2", "crash.user_fault");
|
||||||
put("UnsatisfiedLinkError", "crash.user_fault");
|
put("UnsatisfiedLinkError", "crash.user_fault");
|
||||||
@@ -60,6 +60,7 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
|
|||||||
put("java.lang.ClassFormatError", "crash.NoClassDefFound");
|
put("java.lang.ClassFormatError", "crash.NoClassDefFound");
|
||||||
put("java.lang.OutOfMemoryError", "FUCKING MEMORY LIMIT!");
|
put("java.lang.OutOfMemoryError", "FUCKING MEMORY LIMIT!");
|
||||||
put("Trampoline", "ui.message.update_java");
|
put("Trampoline", "ui.message.update_java");
|
||||||
|
put("NoSuchAlgorithmException", "Has your operating system been installed completely or is a ghost system?");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -242,9 +242,9 @@ public final class MainWindow extends javax.swing.JFrame
|
|||||||
itm.addActionListener(new ActionListenerImpl("time set 0"));
|
itm.addActionListener(new ActionListenerImpl("time set 0"));
|
||||||
ppmBasically.add(itm);
|
ppmBasically.add(itm);
|
||||||
itm = new JMenuItem("广播");
|
itm = new JMenuItem("广播");
|
||||||
itm.addActionListener(new ActionListenerImpl("say {}", JOptionPane.showInputDialog("广播讯息")));
|
itm.addActionListener(new ActionListenerImpl("say {}", "广播讯息"));
|
||||||
itm = new JMenuItem("红字广播");
|
itm = new JMenuItem("红字广播");
|
||||||
itm.addActionListener(new ActionListenerImpl("me {}", JOptionPane.showInputDialog("广播讯息")));
|
itm.addActionListener(new ActionListenerImpl("me {}", "广播讯息"));
|
||||||
itm = new JMenuItem("私聊");
|
itm = new JMenuItem("私聊");
|
||||||
itm.addActionListener(e -> {
|
itm.addActionListener(e -> {
|
||||||
InputDialog id = new InputDialog(MainWindow.this, true, new String[] { "玩家", "讯息" });
|
InputDialog id = new InputDialog(MainWindow.this, true, new String[] { "玩家", "讯息" });
|
||||||
@@ -253,16 +253,16 @@ public final class MainWindow extends javax.swing.JFrame
|
|||||||
});
|
});
|
||||||
ppmBasically.add(itm);
|
ppmBasically.add(itm);
|
||||||
itm = new JMenuItem("给予OP");
|
itm = new JMenuItem("给予OP");
|
||||||
itm.addActionListener(new ActionListenerImpl("op {}", JOptionPane.showInputDialog("新OP的游戏名")));
|
itm.addActionListener(new ActionListenerImpl("op {}", "新OP的游戏名"));
|
||||||
ppmBasically.add(itm);
|
ppmBasically.add(itm);
|
||||||
itm = new JMenuItem("卸除OP");
|
itm = new JMenuItem("卸除OP");
|
||||||
itm.addActionListener(new ActionListenerImpl("deop {}", JOptionPane.showInputDialog("要卸除OP的游戏名")));
|
itm.addActionListener(new ActionListenerImpl("deop {}", "要卸除OP的游戏名"));
|
||||||
ppmBasically.add(itm);
|
ppmBasically.add(itm);
|
||||||
itm = new JMenuItem("给予玩家白名单");
|
itm = new JMenuItem("给予玩家白名单");
|
||||||
itm.addActionListener(new ActionListenerImpl("whitelist add {}", JOptionPane.showInputDialog("要添入白名单的游戏名")));
|
itm.addActionListener(new ActionListenerImpl("whitelist add {}", "要添入白名单的游戏名"));
|
||||||
ppmBasically.add(itm);
|
ppmBasically.add(itm);
|
||||||
itm = new JMenuItem("解除玩家白名单");
|
itm = new JMenuItem("解除玩家白名单");
|
||||||
itm.addActionListener(new ActionListenerImpl("whitelist remove {}", JOptionPane.showInputDialog("要解除白名单的游戏名")));
|
itm.addActionListener(new ActionListenerImpl("whitelist remove {}", "要解除白名单的游戏名"));
|
||||||
ppmBasically.add(itm);
|
ppmBasically.add(itm);
|
||||||
itm = new JMenuItem("启用白名单");
|
itm = new JMenuItem("启用白名单");
|
||||||
itm.addActionListener(new ActionListenerImpl("whitelist on"));
|
itm.addActionListener(new ActionListenerImpl("whitelist on"));
|
||||||
@@ -274,31 +274,31 @@ public final class MainWindow extends javax.swing.JFrame
|
|||||||
itm.addActionListener(new ActionListenerImpl("whitelist list"));
|
itm.addActionListener(new ActionListenerImpl("whitelist list"));
|
||||||
ppmBasically.add(itm);
|
ppmBasically.add(itm);
|
||||||
itm = new JMenuItem("封禁玩家");
|
itm = new JMenuItem("封禁玩家");
|
||||||
itm.addActionListener(new ActionListenerImpl("ban {}", JOptionPane.showInputDialog("要封禁玩家的游戏名")));
|
itm.addActionListener(new ActionListenerImpl("ban {}", "要封禁玩家的游戏名"));
|
||||||
ppmBasically.add(itm);
|
ppmBasically.add(itm);
|
||||||
itm = new JMenuItem("封禁玩家IP");
|
itm = new JMenuItem("封禁玩家IP");
|
||||||
itm.addActionListener(new ActionListenerImpl("ban-ip {}", JOptionPane.showInputDialog("要封禁玩家IP的游戏名")));
|
itm.addActionListener(new ActionListenerImpl("ban-ip {}", "要封禁玩家IP的游戏名"));
|
||||||
itm = new JMenuItem("解封玩家");
|
itm = new JMenuItem("解封玩家");
|
||||||
itm.addActionListener(new ActionListenerImpl("pardon {}", JOptionPane.showInputDialog("要解封玩家的游戏名")));
|
itm.addActionListener(new ActionListenerImpl("pardon {}", "要解封玩家的游戏名"));
|
||||||
ppmBasically.add(itm);
|
ppmBasically.add(itm);
|
||||||
itm = new JMenuItem("解封玩家IP");
|
itm = new JMenuItem("解封玩家IP");
|
||||||
itm.addActionListener(new ActionListenerImpl("pardon-ip {}", JOptionPane.showInputDialog("要解封玩家IP的游戏名")));
|
itm.addActionListener(new ActionListenerImpl("pardon-ip {}", "要解封玩家IP的游戏名"));
|
||||||
itm = new JMenuItem("封禁玩家");
|
itm = new JMenuItem("封禁玩家");
|
||||||
itm.addActionListener(new ActionListenerImpl("ban {}", JOptionPane.showInputDialog("要封禁玩家的游戏名")));
|
itm.addActionListener(new ActionListenerImpl("ban {}", "要封禁玩家的游戏名"));
|
||||||
ppmBasically.add(itm);
|
ppmBasically.add(itm);
|
||||||
itm = new JMenuItem("封禁玩家IP");
|
itm = new JMenuItem("封禁玩家IP");
|
||||||
itm.addActionListener(new ActionListenerImpl("ban-ip {}", JOptionPane.showInputDialog("要封禁玩家IP的游戏名")));
|
itm.addActionListener(new ActionListenerImpl("ban-ip {}", "要封禁玩家IP的游戏名"));
|
||||||
itm = new JMenuItem("封禁玩家列表");
|
itm = new JMenuItem("封禁玩家列表");
|
||||||
itm.addActionListener(new ActionListenerImpl("banlist"));
|
itm.addActionListener(new ActionListenerImpl("banlist"));
|
||||||
ppmBasically.add(itm);
|
ppmBasically.add(itm);
|
||||||
itm = new JMenuItem("修改时间");
|
itm = new JMenuItem("修改时间");
|
||||||
itm.addActionListener(new ActionListenerImpl("time set {}", JOptionPane.showInputDialog("要调整的时间值")));
|
itm.addActionListener(new ActionListenerImpl("time set {}", "要调整的时间值"));
|
||||||
ppmBasically.add(itm);
|
ppmBasically.add(itm);
|
||||||
itm = new JMenuItem("往后调整时间");
|
itm = new JMenuItem("往后调整时间");
|
||||||
itm.addActionListener(new ActionListenerImpl("time add {}", JOptionPane.showInputDialog("要往后调整的时间值")));
|
itm.addActionListener(new ActionListenerImpl("time add {}", "要往后调整的时间值"));
|
||||||
ppmBasically.add(itm);
|
ppmBasically.add(itm);
|
||||||
itm = new JMenuItem("调整天气");
|
itm = new JMenuItem("调整天气");
|
||||||
itm.addActionListener(new ActionListenerImpl("weather {}", JOptionPane.showInputDialog("要调整的天气(只能填:clear[意思是取消所有天气]或rain[意思是下雨]或thunder[意思是打雷]")));
|
itm.addActionListener(new ActionListenerImpl("weather {}", "要调整的天气(只能填:clear[意思是取消所有天气]或rain[意思是下雨]或thunder[意思是打雷]"));
|
||||||
ppmBasically.add(itm);
|
ppmBasically.add(itm);
|
||||||
itm = new JMenuItem("调整一定时间的天气");
|
itm = new JMenuItem("调整一定时间的天气");
|
||||||
itm.addActionListener(e -> {
|
itm.addActionListener(e -> {
|
||||||
@@ -314,10 +314,10 @@ public final class MainWindow extends javax.swing.JFrame
|
|||||||
});
|
});
|
||||||
ppmBasically.add(itm);
|
ppmBasically.add(itm);
|
||||||
itm = new JMenuItem("清除背包");
|
itm = new JMenuItem("清除背包");
|
||||||
itm.addActionListener(new ActionListenerImpl("clear {}", JOptionPane.showInputDialog("要被清除背包的玩家")));
|
itm.addActionListener(new ActionListenerImpl("clear {}", "要被清除背包的玩家"));
|
||||||
ppmBasically.add(itm);
|
ppmBasically.add(itm);
|
||||||
itm = new JMenuItem("踢出玩家");
|
itm = new JMenuItem("踢出玩家");
|
||||||
itm.addActionListener(new ActionListenerImpl("kick {}", JOptionPane.showInputDialog("要被踢出的玩家")));
|
itm.addActionListener(new ActionListenerImpl("kick {}", "要被踢出的玩家"));
|
||||||
ppmBasically.add(itm);
|
ppmBasically.add(itm);
|
||||||
itm = new JMenuItem("在线玩家");
|
itm = new JMenuItem("在线玩家");
|
||||||
itm.addActionListener(new ActionListenerImpl("list"));
|
itm.addActionListener(new ActionListenerImpl("list"));
|
||||||
@@ -343,10 +343,10 @@ public final class MainWindow extends javax.swing.JFrame
|
|||||||
itm.addActionListener(new ActionListenerImpl("save-off"));
|
itm.addActionListener(new ActionListenerImpl("save-off"));
|
||||||
ppmBasically.add(itm);
|
ppmBasically.add(itm);
|
||||||
itm = new JMenuItem("难度");
|
itm = new JMenuItem("难度");
|
||||||
itm.addActionListener(new ActionListenerImpl("difficulty {}", JOptionPane.showInputDialog("难度")));
|
itm.addActionListener(new ActionListenerImpl("difficulty {}", "难度"));
|
||||||
ppmBasically.add(itm);
|
ppmBasically.add(itm);
|
||||||
itm = new JMenuItem("默认游戏模式");
|
itm = new JMenuItem("默认游戏模式");
|
||||||
itm.addActionListener(new ActionListenerImpl("defaultgamemode {}", JOptionPane.showInputDialog("默认游戏模式")));
|
itm.addActionListener(new ActionListenerImpl("defaultgamemode {}", "默认游戏模式"));
|
||||||
ppmBasically.add(itm);
|
ppmBasically.add(itm);
|
||||||
itm = new JMenuItem("地图种子");
|
itm = new JMenuItem("地图种子");
|
||||||
itm.addActionListener(new ActionListenerImpl("seed"));
|
itm.addActionListener(new ActionListenerImpl("seed"));
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import java.lang.management.ManagementFactory;
|
|||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import com.sun.management.OperatingSystemMXBean;
|
import com.sun.management.OperatingSystemMXBean;
|
||||||
import org.jackhuang.hellominecraft.util.StrUtils;
|
import org.jackhuang.hellominecraft.util.StrUtils;
|
||||||
|
import org.jackhuang.hellominecraft.util.logging.HMCLog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -76,7 +77,7 @@ public class MonitorServiceImpl implements IMonitorService {
|
|||||||
else if (osName.toLowerCase().startsWith("mac"))
|
else if (osName.toLowerCase().startsWith("mac"))
|
||||||
cpuRatio = this.getCpuRatioForMac();
|
cpuRatio = this.getCpuRatioForMac();
|
||||||
else
|
else
|
||||||
cpuRatio = getCpuRateForLinux();
|
cpuRatio = this.getCpuRatioForLinux();
|
||||||
// 构造返回对象
|
// 构造返回对象
|
||||||
MonitorInfoBean infoBean = new MonitorInfoBean();
|
MonitorInfoBean infoBean = new MonitorInfoBean();
|
||||||
infoBean.setFreeMemory(freeMemory);
|
infoBean.setFreeMemory(freeMemory);
|
||||||
@@ -91,59 +92,57 @@ public class MonitorServiceImpl implements IMonitorService {
|
|||||||
return infoBean;
|
return infoBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double getCpuRateForLinux() {
|
private static double getCpuRatioForLinux() {
|
||||||
InputStream is = null;
|
float cpuUsage = 0;
|
||||||
InputStreamReader isr = null;
|
Process pro1, pro2;
|
||||||
BufferedReader brStat = null;
|
Runtime r = Runtime.getRuntime();
|
||||||
StringTokenizer tokenStat;
|
|
||||||
try {
|
try {
|
||||||
Process process = Runtime.getRuntime().exec("top -b -n 1");
|
String command = "cat /proc/stat";
|
||||||
is = process.getInputStream();
|
long startTime = System.currentTimeMillis();
|
||||||
isr = new InputStreamReader(is);
|
pro1 = r.exec(command);
|
||||||
brStat = new BufferedReader(isr);
|
BufferedReader in1 = new BufferedReader(new InputStreamReader(pro1.getInputStream()));
|
||||||
if (linuxVersion == null || linuxVersion.equals("2.4")) {
|
String line = null;
|
||||||
brStat.readLine();
|
long idleCpuTime1 = 0, totalCpuTime1 = 0; //分别为系统启动后空闲的CPU时间和总的CPU时间
|
||||||
brStat.readLine();
|
while ((line = in1.readLine()) != null)
|
||||||
brStat.readLine();
|
if (line.startsWith("cpu")) {
|
||||||
brStat.readLine();
|
line = line.trim();
|
||||||
tokenStat = new StringTokenizer(brStat.readLine());
|
String[] temp = line.split("\\s+");
|
||||||
tokenStat.nextToken();
|
idleCpuTime1 = Long.parseLong(temp[4]);
|
||||||
tokenStat.nextToken();
|
for (String s : temp)
|
||||||
String user = tokenStat.nextToken();
|
if (!s.equals("cpu"))
|
||||||
tokenStat.nextToken();
|
totalCpuTime1 += Long.parseLong(s);
|
||||||
String system = tokenStat.nextToken();
|
break;
|
||||||
tokenStat.nextToken();
|
}
|
||||||
String nice = tokenStat.nextToken();
|
in1.close();
|
||||||
System.out.println(user + " , " + system + " , " + nice);
|
pro1.destroy();
|
||||||
user = user.substring(0, user.indexOf("%"));
|
try {
|
||||||
system = system.substring(0, system.indexOf("%"));
|
Thread.sleep(100);
|
||||||
nice = nice.substring(0, nice.indexOf("%"));
|
} catch (InterruptedException e) {
|
||||||
float userUsage = new Float(user);
|
HMCLog.err("Failed to catch sysout", e);
|
||||||
float systemUsage = new Float(system);
|
|
||||||
float niceUsage = new Float(nice);
|
|
||||||
return (userUsage + systemUsage + niceUsage) / 100;
|
|
||||||
} else {
|
|
||||||
brStat.readLine();
|
|
||||||
brStat.readLine();
|
|
||||||
tokenStat = new StringTokenizer(brStat.readLine());
|
|
||||||
tokenStat.nextToken();
|
|
||||||
tokenStat.nextToken();
|
|
||||||
tokenStat.nextToken();
|
|
||||||
tokenStat.nextToken();
|
|
||||||
tokenStat.nextToken();
|
|
||||||
tokenStat.nextToken();
|
|
||||||
tokenStat.nextToken();
|
|
||||||
String cpuUsage = tokenStat.nextToken();
|
|
||||||
System.out.println("CPU idle : " + cpuUsage);
|
|
||||||
Float usage = new Float(cpuUsage.substring(0, cpuUsage.indexOf("%")));
|
|
||||||
return (1 - usage / 100);
|
|
||||||
}
|
}
|
||||||
} catch (IOException ioe) {
|
//第二次采集CPU时间
|
||||||
System.out.println(ioe.getMessage());
|
long endTime = System.currentTimeMillis();
|
||||||
return 1;
|
pro2 = r.exec(command);
|
||||||
} finally {
|
BufferedReader in2 = new BufferedReader(new InputStreamReader(pro2.getInputStream()));
|
||||||
freeResource(is, isr, brStat);
|
long idleCpuTime2 = 0, totalCpuTime2 = 0; //分别为系统启动后空闲的CPU时间和总的CPU时间
|
||||||
|
while ((line = in2.readLine()) != null)
|
||||||
|
if (line.startsWith("cpu")) {
|
||||||
|
line = line.trim();
|
||||||
|
String[] temp = line.split("\\s+");
|
||||||
|
idleCpuTime2 = Long.parseLong(temp[4]);
|
||||||
|
for (String s : temp)
|
||||||
|
if (!s.equals("cpu"))
|
||||||
|
totalCpuTime2 += Long.parseLong(s);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (idleCpuTime1 != 0 && totalCpuTime1 != 0 && idleCpuTime2 != 0 && totalCpuTime2 != 0)
|
||||||
|
cpuUsage = 1 - (float) (idleCpuTime2 - idleCpuTime1) / (float) (totalCpuTime2 - totalCpuTime1);
|
||||||
|
in2.close();
|
||||||
|
pro2.destroy();
|
||||||
|
} catch (IOException e) {
|
||||||
|
HMCLog.err("Failed to catch sysout", e);
|
||||||
}
|
}
|
||||||
|
return cpuUsage * 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getCpuRatioForMac() {
|
private double getCpuRatioForMac() {
|
||||||
|
|||||||
Reference in New Issue
Block a user