Skip to content

Commit

Permalink
Rename Paper module, replace dump and update message sending with adv…
Browse files Browse the repository at this point in the history
…enture components
  • Loading branch information
kennytv committed Aug 26, 2024
1 parent 9c5e818 commit 0f375ad
Show file tree
Hide file tree
Showing 25 changed files with 134 additions and 220 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Crowdin](https://badges.crowdin.net/maintenance/localized.svg)](https://crowdin.com/project/maintenance)
[![Discord](https://img.shields.io/discord/489135856284729384.svg?label=Discord&logo=discord&logoColor=fff)](https://discord.gg/vGCUzHq)

Maintenance is the most customizable free maintenance plugin for your Minecraft server you can find. It runs on Spigot, BungeeCord, Sponge, as well as Velocity.
Maintenance is the most customizable free maintenance plugin for your Minecraft server you can find. It runs on Paper (also Spigot, but with limited functionality), BungeeCord, Sponge, as well as Velocity.

Its features include:
* A custom motd as well as server icon, that will be shown during maintenance
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ allprojects {
}

val platforms = setOf(
projects.maintenanceSpigot,
projects.maintenancePaper,
projects.maintenanceBungee,
projects.maintenanceSponge,
projects.maintenanceVelocity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,6 @@
import eu.kennytv.maintenance.core.util.Task;
import eu.kennytv.maintenance.lib.kyori.adventure.platform.bungeecord.BungeeAudiences;
import eu.kennytv.maintenance.lib.kyori.adventure.text.Component;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.Favicon;
import net.md_5.bungee.api.ProxyServer;
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.TextComponent;
import net.md_5.bungee.api.chat.hover.content.Text;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.api.plugin.PluginManager;
import org.bstats.bungeecord.Metrics;
import org.jetbrains.annotations.Nullable;

import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -65,6 +49,16 @@
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.imageio.ImageIO;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.Favicon;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.api.plugin.PluginManager;
import org.bstats.bungeecord.Metrics;
import org.jetbrains.annotations.Nullable;

public final class MaintenanceBungeePlugin extends MaintenanceProxyPlugin {
private final MaintenanceBungeeBase plugin;
Expand Down Expand Up @@ -108,18 +102,6 @@ public final class MaintenanceBungeePlugin extends MaintenanceProxyPlugin {
}
}

@Override
public void sendUpdateNotification(final SenderInfo sender) {
final TextComponent tc1 = new TextComponent(TextComponent.fromLegacyText(getPrefix()));
final TextComponent tc2 = new TextComponent(TextComponent.fromLegacyText("§cDownload it at: §6" + HANGAR_URL));
final TextComponent click = new TextComponent(TextComponent.fromLegacyText(" §7§l§o(CLICK ME)"));
click.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, HANGAR_URL));
click.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(new ComponentBuilder("§aDownload the latest version").create())));
tc1.addExtra(tc2);
tc1.addExtra(click);
((BungeeSenderInfo) sender).sendMessage(tc1);
}

public boolean isMaintenance(final ServerInfo serverInfo) {
return settingsProxy.isMaintenance(serverInfo.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@
import eu.kennytv.maintenance.core.proxy.SettingsProxy;
import eu.kennytv.maintenance.core.proxy.command.MaintenanceProxyCommand;
import eu.kennytv.maintenance.core.util.SenderInfo;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public final class MaintenanceBungeeCommand extends MaintenanceProxyCommand {
private final MaintenanceBungeePlugin plugin;

Expand Down Expand Up @@ -62,15 +61,6 @@ public List<String> getServersCompletion(final String s) {
return list;
}

@Override
public void sendDumpMessage(final SenderInfo sender, final String url) {
final BungeeSenderInfo bungeeSender = ((BungeeSenderInfo) sender);
final TextComponent clickText = new TextComponent(plugin.getPrefix() + "§7Click here to copy the link");
clickText.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, url));
clickText.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§aClick here to copy the link")));
bungeeSender.sendMessage(clickText);
}

@Override
public List<String> getPlayersCompletion() {
final List<String> list = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@
import eu.kennytv.maintenance.core.util.Task;
import eu.kennytv.maintenance.core.util.Version;
import eu.kennytv.maintenance.lib.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;

import eu.kennytv.maintenance.lib.kyori.adventure.text.TextComponent;
import eu.kennytv.maintenance.lib.kyori.adventure.text.event.ClickEvent;
import eu.kennytv.maintenance.lib.kyori.adventure.text.event.HoverEvent;
import eu.kennytv.maintenance.lib.kyori.adventure.text.format.NamedTextColor;
import eu.kennytv.maintenance.lib.kyori.adventure.text.format.TextDecoration;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
Expand All @@ -61,6 +64,7 @@
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jetbrains.annotations.Nullable;

public abstract class MaintenancePlugin implements Maintenance {
public static final Gson GSON = new GsonBuilder().create();
Expand All @@ -71,15 +75,22 @@ public abstract class MaintenancePlugin implements Maintenance {
protected ServerListPlusHook serverListPlusHook;
protected MaintenanceRunnable runnable;
protected MaintenanceCommand commandManager;
private final String prefix;
private final Component prefix;
private final String legacyPrefix;
private final ServerType serverType;
private Version newestVersion;
private boolean debug;

protected MaintenancePlugin(final String version, final ServerType serverType) {
this.version = new Version(version);
this.serverType = serverType;
this.prefix = "§8[§eMaintenance" + serverType + "§8] ";
this.legacyPrefix = "§8[§eMaintenance" + serverType + "§8] ";
this.prefix = Component.text()
.append(Component.text().content("[").color(NamedTextColor.DARK_GRAY))
.append(Component.text().content("Maintenance").color(NamedTextColor.YELLOW))
.append(Component.text().content("]").color(NamedTextColor.DARK_GRAY))
.append(Component.text(" "))
.build();
this.eventManager = new eu.kennytv.maintenance.core.event.EventManager();
MaintenanceProvider.setMaintenance(this);
}
Expand Down Expand Up @@ -406,7 +417,12 @@ public Version getNewestVersion() {
return newestVersion;
}

@Deprecated
public String getPrefix() {
return legacyPrefix;
}

public Component prefix() {
return prefix;
}

Expand Down Expand Up @@ -436,7 +452,15 @@ protected String getPluginFolder() {

public abstract void broadcast(Component component);

public abstract void sendUpdateNotification(SenderInfo sender);
public void sendUpdateNotification(final SenderInfo sender) {
final TextComponent text = Component.text().content("Download it at: ").color(NamedTextColor.RED)
.append(Component.text().content(HANGAR_URL).color(NamedTextColor.GOLD))
.append(Component.text().content(" (CLICK ME)").color(NamedTextColor.GRAY).decorate(TextDecoration.BOLD))
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, HANGAR_URL))
.hoverEvent(HoverEvent.showText(Component.text("Download the latest version").color(NamedTextColor.GREEN)))
.build();
sender.send(Component.text().append(this.prefix).append(text).build());
}

public abstract Task startMaintenanceRunnable(Runnable runnable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
import eu.kennytv.maintenance.core.command.subcommand.WhitelistCommand;
import eu.kennytv.maintenance.core.command.subcommand.WhitelistRemoveCommand;
import eu.kennytv.maintenance.core.util.SenderInfo;
import eu.kennytv.maintenance.lib.kyori.adventure.text.Component;
import eu.kennytv.maintenance.lib.kyori.adventure.text.TextComponent;
import eu.kennytv.maintenance.lib.kyori.adventure.text.event.ClickEvent;
import eu.kennytv.maintenance.lib.kyori.adventure.text.event.HoverEvent;
import eu.kennytv.maintenance.lib.kyori.adventure.text.format.NamedTextColor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -162,8 +167,9 @@ public void checkForUpdate(final SenderInfo sender) {
sender.sendMessage(plugin.getPrefix() + "§cNewest version available: §aVersion " + plugin.getNewestVersion() + "§c, you're on §a" + plugin.getVersion());
sender.sendMessage(plugin.getPrefix() + "§c§lWARNING: §cYou will have to restart the server to prevent further issues and to complete the update! If you can't do that, don't update!");
sendUpdateMessage(sender);
} else
} else {
sender.sendMessage(plugin.getPrefix() + "§aYou already have the latest version of the plugin!");
}
}

protected void sendUpdateMessage(final SenderInfo sender) {
Expand All @@ -182,7 +188,13 @@ public List<String> getPlayersCompletion() {
return null;
}

public abstract void sendDumpMessage(final SenderInfo sender, final String url);
public void sendDumpMessage(final SenderInfo sender, final String url) {
final TextComponent text = Component.text().content("Click here to copy the link").color(NamedTextColor.GRAY)
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND, url))
.hoverEvent(HoverEvent.showText(Component.text("Click here to copy the link").color(NamedTextColor.GREEN)))
.build();
sender.send(Component.text().append(plugin.prefix()).append(text).build());
}

public List<CommandInfo> getCommands() {
return commands;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.kennytv.maintenance.spigot;
package eu.kennytv.maintenance.paper;

import eu.kennytv.maintenance.api.Maintenance;
import eu.kennytv.maintenance.core.MaintenanceBase;
Expand All @@ -24,12 +24,12 @@

import java.io.File;

public final class MaintenanceSpigotBase extends JavaPlugin implements MaintenanceBase {
public final class MaintenancePaperBase extends JavaPlugin implements MaintenanceBase {
private MaintenancePlugin maintenance;

@Override
public void onEnable() {
maintenance = new MaintenanceSpigotPlugin(this);
maintenance = new MaintenancePaperPlugin(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.kennytv.maintenance.spigot;
package eu.kennytv.maintenance.paper;

import eu.kennytv.maintenance.core.MaintenancePlugin;
import eu.kennytv.maintenance.core.Settings;
Expand All @@ -27,15 +27,14 @@
import eu.kennytv.maintenance.core.util.Task;
import eu.kennytv.maintenance.lib.kyori.adventure.platform.bukkit.BukkitAudiences;
import eu.kennytv.maintenance.lib.kyori.adventure.text.Component;
import eu.kennytv.maintenance.spigot.command.MaintenanceSpigotCommand;
import eu.kennytv.maintenance.spigot.listener.PaperServerListPingListener;
import eu.kennytv.maintenance.spigot.listener.PlayerLoginListener;
import eu.kennytv.maintenance.spigot.listener.ServerInfoPacketListener;
import eu.kennytv.maintenance.spigot.listener.ServerListPingListener;
import eu.kennytv.maintenance.spigot.util.BukkitOfflinePlayerInfo;
import eu.kennytv.maintenance.spigot.util.BukkitSenderInfo;
import eu.kennytv.maintenance.spigot.util.BukkitTask;
import eu.kennytv.maintenance.spigot.util.ComponentUtil;
import eu.kennytv.maintenance.paper.command.MaintenancePaperCommand;
import eu.kennytv.maintenance.paper.listener.PaperServerListPingListener;
import eu.kennytv.maintenance.paper.listener.PlayerLoginListener;
import eu.kennytv.maintenance.paper.listener.ServerInfoPacketListener;
import eu.kennytv.maintenance.paper.listener.ServerListPingListener;
import eu.kennytv.maintenance.paper.util.BukkitOfflinePlayerInfo;
import eu.kennytv.maintenance.paper.util.BukkitTask;
import eu.kennytv.maintenance.paper.util.ComponentUtil;
import java.io.File;
import java.io.InputStream;
import java.util.Arrays;
Expand All @@ -45,10 +44,6 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.imageio.ImageIO;
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.TextComponent;
import org.bstats.bukkit.Metrics;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
Expand All @@ -59,13 +54,13 @@
import org.bukkit.util.CachedServerIcon;
import org.jetbrains.annotations.Nullable;

public final class MaintenanceSpigotPlugin extends MaintenancePlugin {
public final class MaintenancePaperPlugin extends MaintenancePlugin {
private static final boolean FOLIA = hasClass("io.papermc.paper.threadedregions.RegionizedServer");
private final MaintenanceSpigotBase plugin;
private final MaintenancePaperBase plugin;
private final BukkitAudiences audiences;
private CachedServerIcon favicon;

MaintenanceSpigotPlugin(final MaintenanceSpigotBase plugin) {
MaintenancePaperPlugin(final MaintenancePaperBase plugin) {
super(plugin.getDescription().getVersion(), ServerType.SPIGOT);
this.plugin = plugin;
this.audiences = BukkitAudiences.create(plugin);
Expand All @@ -74,7 +69,7 @@ public final class MaintenanceSpigotPlugin extends MaintenancePlugin {

sendEnableMessage();

final MaintenanceSpigotCommand command = new MaintenanceSpigotCommand(this, settings);
final MaintenancePaperCommand command = new MaintenancePaperCommand(this, settings);
commandManager = command;
plugin.getCommand("maintenance").setExecutor(command);

Expand Down Expand Up @@ -171,18 +166,6 @@ public void broadcast(final Component component) {
audiences.all().sendMessage(component);
}

@Override
public void sendUpdateNotification(final SenderInfo sender) {
final TextComponent tc1 = new TextComponent(TextComponent.fromLegacyText(getPrefix()));
final TextComponent tc2 = new TextComponent(TextComponent.fromLegacyText("§cDownload it at: §6" + HANGAR_URL));
final TextComponent click = new TextComponent(TextComponent.fromLegacyText(" §7§l§o(CLICK ME)"));
click.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, HANGAR_URL));
click.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§aDownload the latest version").create()));
tc1.addExtra(tc2);
tc1.addExtra(click);
((BukkitSenderInfo) sender).sendMessage(tc1, getPrefix() + "§cDownload it at: §6" + HANGAR_URL);
}

@Override
protected void kickPlayers() {
for (final Player p : getServer().getOnlinePlayers()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,21 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.kennytv.maintenance.spigot.command;
package eu.kennytv.maintenance.paper.command;

import eu.kennytv.maintenance.core.Settings;
import eu.kennytv.maintenance.core.command.MaintenanceCommand;
import eu.kennytv.maintenance.core.util.SenderInfo;
import eu.kennytv.maintenance.spigot.MaintenanceSpigotPlugin;
import eu.kennytv.maintenance.spigot.util.BukkitSenderInfo;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import eu.kennytv.maintenance.paper.MaintenancePaperPlugin;
import eu.kennytv.maintenance.paper.util.BukkitSenderInfo;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;

import java.util.List;

public final class MaintenanceSpigotCommand extends MaintenanceCommand implements CommandExecutor, TabCompleter {
public final class MaintenancePaperCommand extends MaintenanceCommand implements CommandExecutor, TabCompleter {

public MaintenanceSpigotCommand(final MaintenanceSpigotPlugin plugin, final Settings settings) {
public MaintenancePaperCommand(final MaintenancePaperPlugin plugin, final Settings settings) {
super(plugin, settings);
registerCommands();
}
Expand All @@ -49,12 +44,4 @@ public boolean onCommand(final CommandSender sender, final Command cmd, final St
public List<String> onTabComplete(final CommandSender sender, final Command command, final String alias, final String[] args) {
return getSuggestions(new BukkitSenderInfo(sender), args);
}

@Override
public void sendDumpMessage(final SenderInfo sender, final String url) {
final TextComponent clickText = new TextComponent(plugin.getPrefix() + "§7Click here to copy the link)");
clickText.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, url));
clickText.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§aClick here to copy the link")));
((BukkitSenderInfo) sender).sendMessage(clickText, null);
}
}
Loading

0 comments on commit 0f375ad

Please sign in to comment.