mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-01 00:10:32 +01:00
Revert "Split plugin compatibility report into own class"
Revert 6fa5b80c0a
, which broke `/ess version`, until this can be fixed.
This commit is contained in:
parent
9e89cfa4ed
commit
5503e1e14c
@ -1,32 +1,26 @@
|
|||||||
package com.earth2me.essentials.commands;
|
package com.earth2me.essentials.commands;
|
||||||
|
|
||||||
import static com.earth2me.essentials.I18n.tl;
|
|
||||||
|
|
||||||
import com.earth2me.essentials.CommandSource;
|
import com.earth2me.essentials.CommandSource;
|
||||||
import com.earth2me.essentials.EssentialsUpgrade;
|
import com.earth2me.essentials.EssentialsUpgrade;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import com.earth2me.essentials.UserMap;
|
import com.earth2me.essentials.UserMap;
|
||||||
import com.earth2me.essentials.compat.PluginReport;
|
import com.earth2me.essentials.utils.*;
|
||||||
import com.earth2me.essentials.utils.DateUtil;
|
|
||||||
import com.earth2me.essentials.utils.EnumUtil;
|
|
||||||
import com.earth2me.essentials.utils.FloatUtil;
|
|
||||||
import com.earth2me.essentials.utils.NumberUtil;
|
|
||||||
import com.earth2me.essentials.utils.VersionUtil;
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import static com.earth2me.essentials.I18n.tl;
|
||||||
|
|
||||||
// This command has 4 undocumented behaviours #EasterEgg
|
// This command has 4 undocumented behaviours #EasterEgg
|
||||||
public class Commandessentials extends EssentialsCommand {
|
public class Commandessentials extends EssentialsCommand {
|
||||||
|
|
||||||
@ -43,6 +37,36 @@ public class Commandessentials extends EssentialsCommand {
|
|||||||
|
|
||||||
private transient TuneRunnable currentTune = null;
|
private transient TuneRunnable currentTune = null;
|
||||||
|
|
||||||
|
private static final List<String> versionPlugins = Arrays.asList(
|
||||||
|
"Vault", // API
|
||||||
|
"Reserve", // API
|
||||||
|
"PlaceholderAPI", // API
|
||||||
|
"CMI", // potential for issues
|
||||||
|
"Towny", // past issues; admins should ensure latest
|
||||||
|
"ChestShop", // past issues; admins should ensure latest
|
||||||
|
"Citizens", // fires player events
|
||||||
|
"LuckPerms", // permissions (recommended)
|
||||||
|
"UltraPermissions",
|
||||||
|
"PermissionsEx", // permissions (unsupported)
|
||||||
|
"GroupManager", // permissions (unsupported)
|
||||||
|
"bPermissions" // permissions (unsupported)
|
||||||
|
);
|
||||||
|
|
||||||
|
private static final List<String> officialPlugins = Arrays.asList(
|
||||||
|
"EssentialsAntiBuild",
|
||||||
|
"EssentialsChat",
|
||||||
|
"EssentialsGeoIP",
|
||||||
|
"EssentialsProtect",
|
||||||
|
"EssentialsSpawn",
|
||||||
|
"EssentialsXMPP"
|
||||||
|
);
|
||||||
|
|
||||||
|
private static final List<String> warnPlugins = Arrays.asList(
|
||||||
|
"PermissionsEx",
|
||||||
|
"GroupManager",
|
||||||
|
"bPremissions"
|
||||||
|
);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
@ -280,10 +304,60 @@ public class Commandessentials extends EssentialsCommand {
|
|||||||
private void runVersion(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
private void runVersion(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
||||||
if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.version")) return;
|
if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.version")) return;
|
||||||
|
|
||||||
|
boolean isMismatched = false;
|
||||||
|
boolean isVaultInstalled = false;
|
||||||
|
boolean isUnsupported = false;
|
||||||
final boolean isServerSupported = VersionUtil.isServerSupported();
|
final boolean isServerSupported = VersionUtil.isServerSupported();
|
||||||
sender.sendMessage(tl(isServerSupported ? "versionOutputFine" : "versionOutputWarn", "Server", server.getBukkitVersion() + " " + server.getVersion()));
|
final PluginManager pm = server.getPluginManager();
|
||||||
|
final String essVer = pm.getPlugin("Essentials").getDescription().getVersion();
|
||||||
|
|
||||||
sender.sendMessage(PluginReport.generateReport());
|
sender.sendMessage(tl(isServerSupported ? "versionOutputFine" : "versionOutputWarn", "Server", server.getBukkitVersion() + " " + server.getVersion()));
|
||||||
|
sender.sendMessage(tl("versionOutputFine", "EssentialsX", essVer));
|
||||||
|
|
||||||
|
for (Plugin plugin : pm.getPlugins()) {
|
||||||
|
final PluginDescriptionFile desc = plugin.getDescription();
|
||||||
|
String name = desc.getName();
|
||||||
|
String version = desc.getVersion();
|
||||||
|
|
||||||
|
if (name.startsWith("Essentials") && !name.equalsIgnoreCase("Essentials")) {
|
||||||
|
if (officialPlugins.contains(name)) {
|
||||||
|
name = name.replace("Essentials", "EssentialsX");
|
||||||
|
|
||||||
|
if (!version.equalsIgnoreCase(essVer)) {
|
||||||
|
isMismatched = true;
|
||||||
|
sender.sendMessage(tl("versionOutputWarn", name, version));
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(tl("versionOutputFine", name, version));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(tl("versionOutputUnsupported", name, version));
|
||||||
|
isUnsupported = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (versionPlugins.contains(name)) {
|
||||||
|
if (warnPlugins.contains(name)) {
|
||||||
|
sender.sendMessage(tl("versionOutputUnsupported", name, version));
|
||||||
|
isUnsupported = true;
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(tl("versionOutputFine", name, version));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name.equals("Vault")) isVaultInstalled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMismatched) {
|
||||||
|
sender.sendMessage(tl("versionMismatchAll"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isVaultInstalled) {
|
||||||
|
sender.sendMessage(tl("versionOutputVaultMissing"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isUnsupported) {
|
||||||
|
sender.sendMessage(tl("versionOutputUnsupportedPlugins"));
|
||||||
|
}
|
||||||
|
|
||||||
if (!VersionUtil.isServerSupported()) {
|
if (!VersionUtil.isServerSupported()) {
|
||||||
sender.sendMessage(tl("serverUnsupported"));
|
sender.sendMessage(tl("serverUnsupported"));
|
||||||
|
@ -1,173 +0,0 @@
|
|||||||
package com.earth2me.essentials.compat;
|
|
||||||
|
|
||||||
import static com.earth2me.essentials.I18n.tl;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
public class PluginReport {
|
|
||||||
|
|
||||||
private static String sameVersionPattern = "";
|
|
||||||
|
|
||||||
static {
|
|
||||||
Plugin essPlugin = Bukkit.getPluginManager().getPlugin("Essentials");
|
|
||||||
if (essPlugin != null) {
|
|
||||||
sameVersionPattern = "^" + essPlugin.getDescription().getVersion().replace(".", "\\.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String generateReport() {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
boolean isMismatched = false;
|
|
||||||
boolean isUnsupported = false;
|
|
||||||
boolean isVaultInstalled = false;
|
|
||||||
|
|
||||||
List<ReportEntry> entries = Arrays.stream(Bukkit.getPluginManager().getPlugins())
|
|
||||||
.map(ReportEntry::getEntry)
|
|
||||||
.filter(Objects::nonNull)
|
|
||||||
.sorted()
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
for (ReportEntry entry : entries) {
|
|
||||||
if (entry.type == EntryType.THIRD_PARTY_WARN) {
|
|
||||||
isUnsupported = true;
|
|
||||||
} else if (entry.type == EntryType.UPSTREAM) {
|
|
||||||
isMismatched = true;
|
|
||||||
} else if (entry.id.equals("Vault")) {
|
|
||||||
isVaultInstalled = true;
|
|
||||||
}
|
|
||||||
sb.append(getReportLine(entry)).append("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isMismatched) {
|
|
||||||
sb.append(tl("versionMismatchAll")).append("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isVaultInstalled) {
|
|
||||||
sb.append(tl("versionOutputVaultMissing")).append("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isUnsupported) {
|
|
||||||
sb.append(tl("versionOutputUnsupportedPlugins")).append("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getReportLine(ReportEntry entry) {
|
|
||||||
switch (entry.type) {
|
|
||||||
case OFFICIAL:
|
|
||||||
case THIRD_PARTY:
|
|
||||||
return tl("versionOutputFine", entry.name, entry.getInstalledVersion());
|
|
||||||
case UPSTREAM:
|
|
||||||
return tl("versionOutputUnsupported", entry.name, entry.getInstalledVersion());
|
|
||||||
case THIRD_PARTY_WARN:
|
|
||||||
return tl("versionOutputWarn", entry.name, entry.getInstalledVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new RuntimeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
enum ReportEntry {
|
|
||||||
// EssentialsX
|
|
||||||
ESSENTIALSX("Essentials", "EssentialsX", EntryType.OFFICIAL, sameVersionPattern),
|
|
||||||
ESSENTIALSX_ANTIBUILD("Essentials", "EssentialsX AntiBuild", EntryType.OFFICIAL, sameVersionPattern),
|
|
||||||
ESSENTIALSX_CHAT("Essentials", "EssentialsX Chat", EntryType.OFFICIAL, sameVersionPattern),
|
|
||||||
ESSENTIALSX_GEOIP("Essentials", "EssentialsX GeoIP", EntryType.OFFICIAL, sameVersionPattern),
|
|
||||||
ESSENTIALSX_PROTECT("Essentials", "EssentialsX Protect", EntryType.OFFICIAL, sameVersionPattern),
|
|
||||||
ESSENTIALSX_SPAWN("Essentials", "EssentialsX Spawn", EntryType.OFFICIAL, sameVersionPattern),
|
|
||||||
ESSENTIALSX_XMPP("Essentials", "EssentialsX XMPP", EntryType.OFFICIAL, sameVersionPattern),
|
|
||||||
|
|
||||||
// Essentials 2
|
|
||||||
LEGACY_ANTIBUILD("Essentials", "Essentials AntiBuild", EntryType.UPSTREAM),
|
|
||||||
LEGACY_CHAT("Essentials", "Essentials Chat", EntryType.UPSTREAM),
|
|
||||||
LEGACY_GEOIP("Essentials", "Essentials GeoIP", EntryType.UPSTREAM),
|
|
||||||
LEGACY_PROTECT("Essentials", "Essentials Protect", EntryType.UPSTREAM),
|
|
||||||
LEGACY_SPAWN("Essentials", "Essentials Spawn", EntryType.UPSTREAM),
|
|
||||||
LEGACY_XMPP("Essentials", "Essentials XMPP", EntryType.UPSTREAM),
|
|
||||||
|
|
||||||
// APIs
|
|
||||||
VAULT("Vault", "Vault", EntryType.THIRD_PARTY),
|
|
||||||
PLACEHOLDERAPI("PlaceholderAPI", "PlaceholderAPI", EntryType.THIRD_PARTY),
|
|
||||||
|
|
||||||
// Supported permissions plugins
|
|
||||||
PERMISSIONSEX_2("PermissionsEx", "PermissionsEx", EntryType.THIRD_PARTY, "^2\\.[0-9A-Za-z-_\\.]+"),
|
|
||||||
LUCKPERMS("LuckPerms", "LuckPerms", EntryType.THIRD_PARTY, "^[45]\\.[0-9\\.]{3,}$"),
|
|
||||||
ULTRAPERMISSIONS("UltraPermissions", "UltraPermissions", EntryType.THIRD_PARTY),
|
|
||||||
|
|
||||||
// Unsupported permissions plugins
|
|
||||||
PERMISSIONSEX_1("PermissionsEx", "PermissionsEx", EntryType.THIRD_PARTY_WARN),
|
|
||||||
BPERMISSIONS("bPermissions", "bPermissions", EntryType.THIRD_PARTY_WARN),
|
|
||||||
GROUPMANAGER("GroupManager", "GroupManager", EntryType.THIRD_PARTY_WARN),
|
|
||||||
|
|
||||||
// Misc third-party plugins
|
|
||||||
CHESTSHOP("ChestShop", "ChestShop", EntryType.THIRD_PARTY),
|
|
||||||
CITIZENS("Citizens", "Citizens", EntryType.THIRD_PARTY),
|
|
||||||
CMI("CMI", "CMI", EntryType.THIRD_PARTY_WARN),
|
|
||||||
TOWNY("Towny", "Towny", EntryType.THIRD_PARTY_WARN),
|
|
||||||
;
|
|
||||||
|
|
||||||
private final String id;
|
|
||||||
private final String name;
|
|
||||||
private final EntryType type;
|
|
||||||
private final Pattern versionPattern;
|
|
||||||
|
|
||||||
ReportEntry(String id, String name, EntryType type) {
|
|
||||||
this(id, name, type, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
ReportEntry(String id, String name, EntryType type, String versionMatch) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
this.type = type;
|
|
||||||
this.versionPattern = Pattern.compile(versionMatch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ReportEntry getEntry(Plugin plugin) {
|
|
||||||
for (ReportEntry entry : ReportEntry.values()) {
|
|
||||||
if (entry.id.equals(plugin.getName())) {
|
|
||||||
Matcher matcher = entry.versionPattern.matcher(plugin.getDescription().getVersion());
|
|
||||||
if (matcher.matches()) {
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntryType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getInstalledVersion() {
|
|
||||||
Plugin plugin = Bukkit.getPluginManager().getPlugin(id);
|
|
||||||
if (plugin != null) {
|
|
||||||
return plugin.getDescription().getVersion();
|
|
||||||
}
|
|
||||||
|
|
||||||
return "unknown";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum EntryType {
|
|
||||||
OFFICIAL,
|
|
||||||
UPSTREAM,
|
|
||||||
THIRD_PARTY,
|
|
||||||
THIRD_PARTY_WARN
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user