This commit is contained in:
huangyuhui
2016-03-26 13:02:47 +08:00
parent 2f7f692b84
commit ea6571fdb6
3 changed files with 72 additions and 72 deletions

View File

@@ -47,8 +47,8 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
{
put("MessageBox", "");
put("AWTError", "");
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("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("couldn't create component peer", "Fucking computer!");
put("sun.awt.shell.Win32ShellFolder2", "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.OutOfMemoryError", "FUCKING MEMORY LIMIT!");
put("Trampoline", "ui.message.update_java");
put("NoSuchAlgorithmException", "Has your operating system been installed completely or is a ghost system?");
}
};

View File

@@ -242,9 +242,9 @@ public final class MainWindow extends javax.swing.JFrame
itm.addActionListener(new ActionListenerImpl("time set 0"));
ppmBasically.add(itm);
itm = new JMenuItem("广播");
itm.addActionListener(new ActionListenerImpl("say {}", JOptionPane.showInputDialog("广播讯息")));
itm.addActionListener(new ActionListenerImpl("say {}", "广播讯息"));
itm = new JMenuItem("红字广播");
itm.addActionListener(new ActionListenerImpl("me {}", JOptionPane.showInputDialog("广播讯息")));
itm.addActionListener(new ActionListenerImpl("me {}", "广播讯息"));
itm = new JMenuItem("私聊");
itm.addActionListener(e -> {
InputDialog id = new InputDialog(MainWindow.this, true, new String[] { "玩家", "讯息" });
@@ -253,16 +253,16 @@ public final class MainWindow extends javax.swing.JFrame
});
ppmBasically.add(itm);
itm = new JMenuItem("给予OP");
itm.addActionListener(new ActionListenerImpl("op {}", JOptionPane.showInputDialog("新OP的游戏名")));
itm.addActionListener(new ActionListenerImpl("op {}", "新OP的游戏名"));
ppmBasically.add(itm);
itm = new JMenuItem("卸除OP");
itm.addActionListener(new ActionListenerImpl("deop {}", JOptionPane.showInputDialog("要卸除OP的游戏名")));
itm.addActionListener(new ActionListenerImpl("deop {}", "要卸除OP的游戏名"));
ppmBasically.add(itm);
itm = new JMenuItem("给予玩家白名单");
itm.addActionListener(new ActionListenerImpl("whitelist add {}", JOptionPane.showInputDialog("要添入白名单的游戏名")));
itm.addActionListener(new ActionListenerImpl("whitelist add {}", "要添入白名单的游戏名"));
ppmBasically.add(itm);
itm = new JMenuItem("解除玩家白名单");
itm.addActionListener(new ActionListenerImpl("whitelist remove {}", JOptionPane.showInputDialog("要解除白名单的游戏名")));
itm.addActionListener(new ActionListenerImpl("whitelist remove {}", "要解除白名单的游戏名"));
ppmBasically.add(itm);
itm = new JMenuItem("启用白名单");
itm.addActionListener(new ActionListenerImpl("whitelist on"));
@@ -274,31 +274,31 @@ public final class MainWindow extends javax.swing.JFrame
itm.addActionListener(new ActionListenerImpl("whitelist list"));
ppmBasically.add(itm);
itm = new JMenuItem("封禁玩家");
itm.addActionListener(new ActionListenerImpl("ban {}", JOptionPane.showInputDialog("要封禁玩家的游戏名")));
itm.addActionListener(new ActionListenerImpl("ban {}", "要封禁玩家的游戏名"));
ppmBasically.add(itm);
itm = new JMenuItem("封禁玩家IP");
itm.addActionListener(new ActionListenerImpl("ban-ip {}", JOptionPane.showInputDialog("要封禁玩家IP的游戏名")));
itm.addActionListener(new ActionListenerImpl("ban-ip {}", "要封禁玩家IP的游戏名"));
itm = new JMenuItem("解封玩家");
itm.addActionListener(new ActionListenerImpl("pardon {}", JOptionPane.showInputDialog("要解封玩家的游戏名")));
itm.addActionListener(new ActionListenerImpl("pardon {}", "要解封玩家的游戏名"));
ppmBasically.add(itm);
itm = new JMenuItem("解封玩家IP");
itm.addActionListener(new ActionListenerImpl("pardon-ip {}", JOptionPane.showInputDialog("要解封玩家IP的游戏名")));
itm.addActionListener(new ActionListenerImpl("pardon-ip {}", "要解封玩家IP的游戏名"));
itm = new JMenuItem("封禁玩家");
itm.addActionListener(new ActionListenerImpl("ban {}", JOptionPane.showInputDialog("要封禁玩家的游戏名")));
itm.addActionListener(new ActionListenerImpl("ban {}", "要封禁玩家的游戏名"));
ppmBasically.add(itm);
itm = new JMenuItem("封禁玩家IP");
itm.addActionListener(new ActionListenerImpl("ban-ip {}", JOptionPane.showInputDialog("要封禁玩家IP的游戏名")));
itm.addActionListener(new ActionListenerImpl("ban-ip {}", "要封禁玩家IP的游戏名"));
itm = new JMenuItem("封禁玩家列表");
itm.addActionListener(new ActionListenerImpl("banlist"));
ppmBasically.add(itm);
itm = new JMenuItem("修改时间");
itm.addActionListener(new ActionListenerImpl("time set {}", JOptionPane.showInputDialog("要调整的时间值")));
itm.addActionListener(new ActionListenerImpl("time set {}", "要调整的时间值"));
ppmBasically.add(itm);
itm = new JMenuItem("往后调整时间");
itm.addActionListener(new ActionListenerImpl("time add {}", JOptionPane.showInputDialog("要往后调整的时间值")));
itm.addActionListener(new ActionListenerImpl("time add {}", "要往后调整的时间值"));
ppmBasically.add(itm);
itm = new JMenuItem("调整天气");
itm.addActionListener(new ActionListenerImpl("weather {}", JOptionPane.showInputDialog("要调整的天气只能填clear[意思是取消所有天气]或rain[意思是下雨]或thunder[意思是打雷]")));
itm.addActionListener(new ActionListenerImpl("weather {}", "要调整的天气只能填clear[意思是取消所有天气]或rain[意思是下雨]或thunder[意思是打雷]"));
ppmBasically.add(itm);
itm = new JMenuItem("调整一定时间的天气");
itm.addActionListener(e -> {
@@ -314,10 +314,10 @@ public final class MainWindow extends javax.swing.JFrame
});
ppmBasically.add(itm);
itm = new JMenuItem("清除背包");
itm.addActionListener(new ActionListenerImpl("clear {}", JOptionPane.showInputDialog("要被清除背包的玩家")));
itm.addActionListener(new ActionListenerImpl("clear {}", "要被清除背包的玩家"));
ppmBasically.add(itm);
itm = new JMenuItem("踢出玩家");
itm.addActionListener(new ActionListenerImpl("kick {}", JOptionPane.showInputDialog("要被踢出的玩家")));
itm.addActionListener(new ActionListenerImpl("kick {}", "要被踢出的玩家"));
ppmBasically.add(itm);
itm = new JMenuItem("在线玩家");
itm.addActionListener(new ActionListenerImpl("list"));
@@ -343,10 +343,10 @@ public final class MainWindow extends javax.swing.JFrame
itm.addActionListener(new ActionListenerImpl("save-off"));
ppmBasically.add(itm);
itm = new JMenuItem("难度");
itm.addActionListener(new ActionListenerImpl("difficulty {}", JOptionPane.showInputDialog("难度")));
itm.addActionListener(new ActionListenerImpl("difficulty {}", "难度"));
ppmBasically.add(itm);
itm = new JMenuItem("默认游戏模式");
itm.addActionListener(new ActionListenerImpl("defaultgamemode {}", JOptionPane.showInputDialog("默认游戏模式")));
itm.addActionListener(new ActionListenerImpl("defaultgamemode {}", "默认游戏模式"));
ppmBasically.add(itm);
itm = new JMenuItem("地图种子");
itm.addActionListener(new ActionListenerImpl("seed"));

View File

@@ -26,6 +26,7 @@ import java.lang.management.ManagementFactory;
import java.util.StringTokenizer;
import com.sun.management.OperatingSystemMXBean;
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"))
cpuRatio = this.getCpuRatioForMac();
else
cpuRatio = getCpuRateForLinux();
cpuRatio = this.getCpuRatioForLinux();
// 构造返回对象
MonitorInfoBean infoBean = new MonitorInfoBean();
infoBean.setFreeMemory(freeMemory);
@@ -91,59 +92,57 @@ public class MonitorServiceImpl implements IMonitorService {
return infoBean;
}
private static double getCpuRateForLinux() {
InputStream is = null;
InputStreamReader isr = null;
BufferedReader brStat = null;
StringTokenizer tokenStat;
private static double getCpuRatioForLinux() {
float cpuUsage = 0;
Process pro1, pro2;
Runtime r = Runtime.getRuntime();
try {
Process process = Runtime.getRuntime().exec("top -b -n 1");
is = process.getInputStream();
isr = new InputStreamReader(is);
brStat = new BufferedReader(isr);
if (linuxVersion == null || linuxVersion.equals("2.4")) {
brStat.readLine();
brStat.readLine();
brStat.readLine();
brStat.readLine();
tokenStat = new StringTokenizer(brStat.readLine());
tokenStat.nextToken();
tokenStat.nextToken();
String user = tokenStat.nextToken();
tokenStat.nextToken();
String system = tokenStat.nextToken();
tokenStat.nextToken();
String nice = tokenStat.nextToken();
System.out.println(user + " , " + system + " , " + nice);
user = user.substring(0, user.indexOf("%"));
system = system.substring(0, system.indexOf("%"));
nice = nice.substring(0, nice.indexOf("%"));
float userUsage = new Float(user);
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);
String command = "cat /proc/stat";
long startTime = System.currentTimeMillis();
pro1 = r.exec(command);
BufferedReader in1 = new BufferedReader(new InputStreamReader(pro1.getInputStream()));
String line = null;
long idleCpuTime1 = 0, totalCpuTime1 = 0; //分别为系统启动后空闲的CPU时间和总的CPU时间
while ((line = in1.readLine()) != null)
if (line.startsWith("cpu")) {
line = line.trim();
String[] temp = line.split("\\s+");
idleCpuTime1 = Long.parseLong(temp[4]);
for (String s : temp)
if (!s.equals("cpu"))
totalCpuTime1 += Long.parseLong(s);
break;
}
in1.close();
pro1.destroy();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
HMCLog.err("Failed to catch sysout", e);
}
} catch (IOException ioe) {
System.out.println(ioe.getMessage());
return 1;
} finally {
freeResource(is, isr, brStat);
//第二次采集CPU时间
long endTime = System.currentTimeMillis();
pro2 = r.exec(command);
BufferedReader in2 = new BufferedReader(new InputStreamReader(pro2.getInputStream()));
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() {