mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-14 05:01:28 +00:00
Initial implementation of Supervisor.
EssentialsReportContext provides all online players' userdata files if report level is 400 or higher, as well as config.yml if report level is over 200.
This commit is contained in:
parent
bc08b11011
commit
6231a25413
4 changed files with 117 additions and 0 deletions
|
@ -133,11 +133,21 @@
|
|||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.supaham.supervisor</groupId>
|
||||
<artifactId>supervisor-bukkit</artifactId>
|
||||
<version>1.3-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>ender-zone-repo</id>
|
||||
<url>http://ci.ender.zone/plugin/repository/everything/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
</project>
|
||||
|
|
|
@ -24,6 +24,7 @@ import com.earth2me.essentials.register.payment.Methods;
|
|||
import com.earth2me.essentials.signs.SignBlockListener;
|
||||
import com.earth2me.essentials.signs.SignEntityListener;
|
||||
import com.earth2me.essentials.signs.SignPlayerListener;
|
||||
import com.earth2me.essentials.supervisor.EssentialsReportContext;
|
||||
import com.earth2me.essentials.textreader.IText;
|
||||
import com.earth2me.essentials.textreader.KeywordReplacer;
|
||||
import com.earth2me.essentials.textreader.SimpleTextInput;
|
||||
|
@ -257,6 +258,10 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
|||
// Failed to submit the stats :-(
|
||||
}
|
||||
|
||||
if (getServer().getPluginManager().getPlugin("Supervisor") != null) {
|
||||
EssentialsReportContext.load(this);
|
||||
}
|
||||
|
||||
final String timeroutput = execTimer.end();
|
||||
if (getSettings().isDebug()) {
|
||||
LOGGER.log(Level.INFO, "Essentials load {0}", timeroutput);
|
||||
|
|
|
@ -911,4 +911,8 @@ public abstract class UserData extends PlayerExtension implements IConf {
|
|||
public void stopTransaction() {
|
||||
config.stopTransaction();
|
||||
}
|
||||
|
||||
public EssentialsUserConf getConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,98 @@
|
|||
package com.earth2me.essentials.supervisor;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.UserMap;
|
||||
import com.supaham.supervisor.bukkit.SupervisorPlugin;
|
||||
import com.supaham.supervisor.report.AbstractReportContextEntry;
|
||||
import com.supaham.supervisor.report.ReportContext;
|
||||
import com.supaham.supervisor.report.ReportContextEntry;
|
||||
import com.supaham.supervisor.report.ReportSpecifications;
|
||||
import com.supaham.supervisor.report.ReportSpecifications.ReportLevel;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class EssentialsReportContext extends ReportContext {
|
||||
|
||||
private static final Method getNamesMethod;
|
||||
|
||||
private final Essentials ess;
|
||||
|
||||
static {
|
||||
try {
|
||||
getNamesMethod = UserMap.class.getDeclaredMethod("getNames");
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void load(Essentials ess) {
|
||||
SupervisorPlugin.get().registerContext(ess, new EssentialsReportContext(ess));
|
||||
}
|
||||
|
||||
public EssentialsReportContext(Essentials ess) {
|
||||
super("essentialsx", "EssentialsX", "1");
|
||||
this.ess = ess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReportContextEntry createEntry(@Nonnull ReportSpecifications specs) {
|
||||
return new EssentialsContext(this, specs);
|
||||
}
|
||||
|
||||
private final class EssentialsContext extends AbstractReportContextEntry {
|
||||
|
||||
public EssentialsContext(@Nonnull ReportContext parentContext, @Nonnull ReportSpecifications reportSpecifications) {
|
||||
super(parentContext, reportSpecifications);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
append("users_count", ess.getUserMap().getUniqueUsers());
|
||||
uuidMapCount();
|
||||
|
||||
if (getReportLevel() >= ReportLevel.NORMAL) {
|
||||
userdata();
|
||||
}
|
||||
|
||||
if (getReportLevel() > ReportLevel.BRIEF) {
|
||||
config();
|
||||
}
|
||||
}
|
||||
|
||||
private void uuidMapCount() {
|
||||
try {
|
||||
getNamesMethod.setAccessible(true);
|
||||
append("uuidmap_count", ((Map) getNamesMethod.invoke(ess.getUserMap())).size());
|
||||
getNamesMethod.setAccessible(false);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void userdata() {
|
||||
for (User user : ess.getOnlineUsers()) {
|
||||
File file = user.getConfig().getFile();
|
||||
try {
|
||||
createPlainTextFile("userdata/" + file.getName(), user.getName() + " data").appendFile(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void config() {
|
||||
try {
|
||||
createPlainTextFile("config.yml", "Essentials Configuration file").appendFile(new File(ess.getDataFolder(), "config.yml"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue