1
1
mirror of https://github.com/geekfrog/PermissionsTime.git synced 2025-09-06 11:06:58 +00:00

修复路径BUG 更换统计

This commit is contained in:
2017-07-31 01:45:11 +08:00
parent 6953d1b5dd
commit b94799dcea
4 changed files with 183 additions and 173 deletions

View File

@ -5,6 +5,7 @@ import java.util.Locale;
import java.util.UUID;
import java.util.logging.Logger;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.RegisteredServiceProvider;
@ -41,7 +42,6 @@ public class PluginMain extends JavaPlugin {
@Override
public void onEnable() {
super.onEnable();
pm = this;
cm = new ConfigManager(pm);
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "==============================="));
@ -64,8 +64,8 @@ public class PluginMain extends JavaPlugin {
}
if (PluginCfg.IS_METRICS) {
try {
org.mcstats.Metrics mcstats = new org.mcstats.Metrics(pm);
mcstats.start();
Metrics metrics = new Metrics(pm);
// metrics.addCustomChart(new Metrics.SimplePie("chart_id", () -> "My value"));
} catch (Exception e) {
e.printStackTrace();
}
@ -132,7 +132,6 @@ public class PluginMain extends JavaPlugin {
@Override
public void onDisable() {
super.onDisable();
getServer().getServicesManager().unregisterAll(pm);
Bukkit.getScheduler().cancelTasks(pm);
try {

View File

@ -4,57 +4,61 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
public class FileUtil {
public interface FindFilesDo {
boolean isProcess(String fileName);
void process(String fileName, InputStream is);
}
public interface FindFilesDo {
boolean isProcess(String fileName);
public static void findFilesFromJar(FindFilesDo ffd, Class<?> jarClazz) {
JarFile jarFile = null;
try {
String jarFilePath = jarClazz.getProtectionDomain().getCodeSource().getLocation().getFile();
jarFile = new JarFile(jarFilePath);
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry e = entries.nextElement();
if (ffd.isProcess(e.getName())) {
InputStream is = jarFile.getInputStream(e);
ffd.process(e.getName(), is);
try {
is.close();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (jarFile != null) {
try {
jarFile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
void process(String fileName, InputStream is);
}
public static void writeOnFile(String fileName, String content) {
FileWriter fw;
try {
File f = new File(fileName);
fw = new FileWriter(f, true);
fw.write(content + "\r\n");
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void findFilesFromJar(FindFilesDo ffd, Class<?> jarClazz) {
JarFile jarFile = null;
try {
String jarFilePath = jarClazz.getProtectionDomain().getCodeSource().getLocation().getFile();
jarFilePath = URLDecoder.decode(jarFilePath, Charset.defaultCharset().name());
jarFile = new JarFile(jarFilePath);
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry e = entries.nextElement();
if (ffd.isProcess(e.getName())) {
InputStream is = jarFile.getInputStream(e);
ffd.process(e.getName(), is);
try {
is.close();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (jarFile != null) {
try {
jarFile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static void writeOnFile(String fileName, String content) {
FileWriter fw;
try {
File f = new File(fileName);
fw = new FileWriter(f, true);
fw.write(content + "\r\n");
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}