Add online mode data for /ess dump (#4497)

EssentialsX/Website#60
This commit is contained in:
Josh Roy 2021-08-31 08:34:10 -07:00 committed by GitHub
parent 6f20a789f9
commit 14c2ab5ddd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 72 additions and 0 deletions

View file

@ -49,6 +49,7 @@ import net.ess3.api.IJails;
import net.ess3.api.ISettings;
import net.ess3.nms.refl.providers.ReflFormattedCommandAliasProvider;
import net.ess3.nms.refl.providers.ReflKnownCommandsProvider;
import net.ess3.nms.refl.providers.ReflOnlineModeProvider;
import net.ess3.nms.refl.providers.ReflPersistentDataProvider;
import net.ess3.nms.refl.providers.ReflServerStateProvider;
import net.ess3.nms.refl.providers.ReflSpawnEggProvider;
@ -165,6 +166,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
private transient MaterialTagProvider materialTagProvider;
private transient SyncCommandsProvider syncCommandsProvider;
private transient PersistentDataProvider persistentDataProvider;
private transient ReflOnlineModeProvider onlineModeProvider;
private transient Kits kits;
private transient RandomTeleport randomTeleport;
private transient UpdateChecker updateChecker;
@ -406,6 +408,8 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
persistentDataProvider = new ReflPersistentDataProvider(this);
}
onlineModeProvider = new ReflOnlineModeProvider();
execTimer.mark("Init(Providers)");
reload();
@ -1260,6 +1264,11 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
return persistentDataProvider;
}
@Override
public ReflOnlineModeProvider getOnlineModeProvider() {
return onlineModeProvider;
}
@Override
public PluginCommand getPluginCommand(final String cmd) {
return this.getCommand(cmd);

View file

@ -7,6 +7,7 @@ import com.earth2me.essentials.commands.IEssentialsCommand;
import com.earth2me.essentials.commands.PlayerNotFoundException;
import com.earth2me.essentials.perm.PermissionsHandler;
import com.earth2me.essentials.updatecheck.UpdateChecker;
import net.ess3.nms.refl.providers.ReflOnlineModeProvider;
import net.ess3.provider.ContainerProvider;
import net.ess3.provider.FormattedCommandAliasProvider;
import net.ess3.provider.KnownCommandsProvider;
@ -156,5 +157,7 @@ public interface IEssentials extends Plugin {
PersistentDataProvider getPersistentDataProvider();
ReflOnlineModeProvider getOnlineModeProvider();
PluginCommand getPluginCommand(String cmd);
}

View file

@ -190,6 +190,7 @@ public class Commandessentials extends EssentialsCommand {
serverData.addProperty("bukkit-version", Bukkit.getBukkitVersion());
serverData.addProperty("server-version", Bukkit.getVersion());
serverData.addProperty("server-brand", Bukkit.getName());
serverData.addProperty("online-mode", ess.getOnlineModeProvider().getOnlineModeString());
final JsonObject supportStatus = new JsonObject();
final VersionUtil.SupportStatus status = VersionUtil.getServerSupportStatus();
supportStatus.addProperty("status", status.name());

View file

@ -0,0 +1,59 @@
package net.ess3.nms.refl.providers;
import org.bukkit.Bukkit;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
public class ReflOnlineModeProvider {
private final MethodHandle spigotBungeeGetter;
private final MethodHandle paperBungeeGetter;
private final boolean fancyPaperCheck;
public ReflOnlineModeProvider() {
MethodHandle spigotBungeeGetter = null;
MethodHandle paperBungeeGetter = null;
boolean fancyCheck = false;
try {
final MethodHandles.Lookup lookup = MethodHandles.lookup();
spigotBungeeGetter = lookup.findStaticGetter(Class.forName("org.spigotmc.SpigotConfig"), "bungee", boolean.class);
final Class<?> paperConfig = Class.forName("com.destroystokyo.paper.PaperConfig");
paperBungeeGetter = lookup.findStaticGetter(paperConfig, "bungeeOnlineMode", boolean.class);
paperBungeeGetter = lookup.findStatic(paperConfig, "isProxyOnlineMode", MethodType.methodType(boolean.class));
fancyCheck = true;
} catch (Throwable ignored) {
}
this.spigotBungeeGetter = spigotBungeeGetter;
this.paperBungeeGetter = paperBungeeGetter;
this.fancyPaperCheck = fancyCheck;
}
public String getOnlineModeString() {
if (spigotBungeeGetter == null) {
return Bukkit.getOnlineMode() ? "Online Mode" : "Offline Mode";
}
try {
if (Bukkit.getOnlineMode()) {
return "Online Mode";
}
if (fancyPaperCheck) {
if ((boolean) paperBungeeGetter.invoke()) {
// Could be Velocity or Bungee, so do not specify.
return "Proxy Mode";
}
return "Offline Mode";
}
if ((boolean) spigotBungeeGetter.invoke() && (paperBungeeGetter == null || (boolean) paperBungeeGetter.invoke())) {
return "Bungee Mode";
}
return "Offline Mode";
} catch (Throwable ignored) {
return "Unknown";
}
}
}