1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Merge pull request #2791 from Slimefun/feature/componentify-versions-subcommand

This commit is contained in:
Daniel Walsh 2021-02-02 17:31:35 +00:00 committed by GitHub
commit 36639fd22c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,13 +3,18 @@ package io.github.thebusybiscuit.slimefun4.core.commands.subcommands;
import java.util.Collection;
import javax.annotation.Nonnull;
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.hover.content.Text;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.Plugin;
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand;
import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
@ -28,35 +33,107 @@ class VersionsCommand extends SubCommand {
// so we will just fix this inconsistency for them :)
String serverSoftware = PaperLib.isSpigot() && !PaperLib.isPaper() ? "Spigot" : Bukkit.getName();
sender.sendMessage(ChatColor.GRAY + "This Server uses the following setup of Slimefun:");
sender.sendMessage(ChatColors.color("&a" + serverSoftware + " &2" + Bukkit.getVersion()));
sender.sendMessage(ChatColors.color("&aSlimefun &2v" + SlimefunPlugin.getVersion()));
ComponentBuilder builder = new ComponentBuilder();
builder.append("This Server uses the following setup of Slimefun:\n").color(ChatColor.GRAY)
.append(serverSoftware).color(ChatColor.GREEN).append(" " + Bukkit.getVersion() + '\n').color(ChatColor.DARK_GREEN)
.append("Slimefun").color(ChatColor.GREEN).append(" v" + SlimefunPlugin.getVersion() + '\n').color(ChatColor.DARK_GREEN);
if (SlimefunPlugin.getMetricsService().getVersion() != null) {
sender.sendMessage(ChatColors.color("&aMetrics build: &2#" + SlimefunPlugin.getMetricsService().getVersion()));
builder.append("Metrics build: ").color(ChatColor.GREEN)
.append("#" + SlimefunPlugin.getMetricsService().getVersion() + '\n').color(ChatColor.DARK_GREEN);
}
addJavaVersion(builder);
if (SlimefunPlugin.getRegistry().isBackwardsCompatible()) {
sender.sendMessage(ChatColor.RED + "Backwards compatibility enabled!");
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(
"Backwards compatibility has a negative impact on performance!\n"
+ "We recommend you to disable this setting unless your server still "
+ "has legacy Slimefun items (from before summer 2019) in circulation."
));
builder.append("Backwards compatibility enabled!\n").color(ChatColor.RED).event(hoverEvent);
}
sender.sendMessage("");
builder.append("\n").event((HoverEvent) null);
Collection<Plugin> addons = SlimefunPlugin.getInstalledAddons();
sender.sendMessage(ChatColors.color("&7Installed Addons: &8(" + addons.size() + ")"));
addPluginVersions(builder);
for (Plugin plugin : addons) {
String version = plugin.getDescription().getVersion();
if (Bukkit.getPluginManager().isPluginEnabled(plugin)) {
sender.sendMessage(ChatColor.GREEN + " " + plugin.getName() + ChatColor.DARK_GREEN + " v" + version);
} else {
sender.sendMessage(ChatColor.RED + " " + plugin.getName() + ChatColor.DARK_RED + " v" + version);
}
}
sender.spigot().sendMessage(builder.create());
} else {
SlimefunPlugin.getLocalization().sendMessage(sender, "messages.no-permission", true);
}
}
private void addJavaVersion(@Nonnull ComponentBuilder builder) {
String javaVer = System.getProperty("java.version");
if (javaVer.startsWith("1.")) {
javaVer = javaVer.substring(2);
}
// If it's like 11.0.1.3 or 8.0_275
if (javaVer.indexOf('.') != -1) {
javaVer = javaVer.substring(0, javaVer.indexOf('.'));
}
int ver = Integer.parseInt(javaVer);
if (ver < 11) {
builder.append("Java " + ver).color(ChatColor.RED)
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(
"You should be using at least Java 11! Paper will be dropping support for before Java 11 starting at MC 1.17"
)))
.append("\n")
.event((HoverEvent) null);
} else {
builder.append("Java " + ver + "\n").color(ChatColor.GREEN);
}
}
private void addPluginVersions(@Nonnull ComponentBuilder builder) {
Collection<Plugin> addons = SlimefunPlugin.getInstalledAddons();
builder.append("Installed Addons: ").color(ChatColor.GRAY)
.append("(" + addons.size() + ")").color(ChatColor.DARK_GRAY);
for (Plugin plugin : addons) {
String version = plugin.getDescription().getVersion();
if (Bukkit.getPluginManager().isPluginEnabled(plugin)) {
HoverEvent hoverEvent;
ClickEvent clickEvent = null;
if (plugin instanceof SlimefunAddon) {
hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(
"Author(s): " + String.join(", ", plugin.getDescription().getAuthors())
+ "\nClick to open the Bug Tracker"
));
clickEvent = new ClickEvent(ClickEvent.Action.OPEN_URL, ((SlimefunAddon) plugin).getBugTrackerURL());
} else {
hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(
"Author(s): " + String.join(", ", plugin.getDescription().getAuthors())
));
}
builder.append("\n " + plugin.getName()).color(ChatColor.GREEN).event(hoverEvent).event(clickEvent)
.append(" v" + version).color(ChatColor.DARK_GREEN)
.append("").event((ClickEvent) null).event((HoverEvent) null);
} else {
HoverEvent hoverEvent;
ClickEvent clickEvent = null;
if (plugin instanceof SlimefunAddon) {
hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new Text("Plugin is disabled. Check the console for an error. Click here to report on their issue tracker"));
if (((SlimefunAddon) plugin).getBugTrackerURL() != null) {
clickEvent = new ClickEvent(ClickEvent.Action.OPEN_URL, ((SlimefunAddon) plugin).getBugTrackerURL());
}
} else {
hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new Text("Plugin is disabled. Check the console for an error and report on their issue tracker."));
}
// We need to reset the hover event or it's added to all components
builder.append("\n " + plugin.getName()).color(ChatColor.RED).event(hoverEvent).event(clickEvent)
.append(" v" + version).color(ChatColor.DARK_RED)
.append("").event((ClickEvent) null).event((HoverEvent) null);
}
}
}
}