From b5f2a55a43aa3f0b9074dae0218e650e4fe9d81e Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 7 Nov 2020 07:37:01 +1300 Subject: [PATCH] Start spamming protocollib updating for command usage too --- .../disguise/commands/DisguiseBaseCommand.java | 10 ++++++++++ .../disguise/utilities/DisguiseUtilities.java | 12 ++++++++++++ .../utilities/listeners/DisguiseListener.java | 17 +++-------------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java index 27a48b3f..5cc3f085 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java @@ -1,6 +1,8 @@ package me.libraryaddict.disguise.commands; +import com.comphenix.protocol.ProtocolLibrary; import me.libraryaddict.disguise.DisguiseConfig; +import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.commands.disguise.DisguiseCommand; import me.libraryaddict.disguise.commands.disguise.DisguiseEntityCommand; import me.libraryaddict.disguise.commands.disguise.DisguisePlayerCommand; @@ -23,6 +25,7 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitRunnable; import java.lang.reflect.Method; import java.util.*; @@ -49,6 +52,13 @@ public abstract class DisguiseBaseCommand implements CommandExecutor { } protected boolean isNotPremium(CommandSender sender) { + String requiredProtocolLib = DisguiseUtilities.getProtocolLibRequiredVersion(); + String version = ProtocolLibrary.getPlugin().getDescription().getVersion(); + + if (DisguiseUtilities.isOlderThan(requiredProtocolLib, version)) { + DisguiseUtilities.sendProtocolLibUpdateMessage(sender, version, requiredProtocolLib); + } + if (sender instanceof Player && !sender.isOp() && (!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) { sender.sendMessage(ChatColor.RED + diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 15ab0885..9187cafc 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -2531,6 +2531,18 @@ public class DisguiseUtilities { return components.toArray(new BaseComponent[0]); } + public static void sendProtocolLibUpdateMessage(CommandSender p, String version, String requiredProtocolLib) { + p.sendMessage(ChatColor.RED + "Please ask the server owner to update ProtocolLib! You are running " + version + + " but the minimum version you should be on is " + requiredProtocolLib + "!"); + p.sendMessage(ChatColor.RED + "https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/target" + + "/ProtocolLib" + ".jar"); + p.sendMessage(ChatColor.RED + "Or! Use " + ChatColor.DARK_RED + "/ld updateprotocollib" + ChatColor.RED + + " - To update to the latest development build"); + p.sendMessage(ChatColor.DARK_GREEN + + "This message is `kindly` provided by Lib's Disguises on repeat to all players due to the sheer " + + "number of people who don't see it"); + } + public static boolean isOlderThan(String requiredVersion, String theirVersion) { int[] required = getNumericVersion(requiredVersion); int[] has = getNumericVersion(theirVersion); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/listeners/DisguiseListener.java b/src/main/java/me/libraryaddict/disguise/utilities/listeners/DisguiseListener.java index 9d17d833..f18332af 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/listeners/DisguiseListener.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/listeners/DisguiseListener.java @@ -330,7 +330,8 @@ public class DisguiseListener implements Listener { String version = ProtocolLibrary.getPlugin().getDescription().getVersion(); if (DisguiseUtilities.isOlderThan(requiredProtocolLib, version)) { - sendUpdateMessage(p, version, requiredProtocolLib); + DisguiseUtilities.sendProtocolLibUpdateMessage(p, version, requiredProtocolLib); + new BukkitRunnable() { @Override public void run() { @@ -339,7 +340,7 @@ public class DisguiseListener implements Listener { return; } - sendUpdateMessage(p, version, requiredProtocolLib); + DisguiseUtilities.sendProtocolLibUpdateMessage(p, version, requiredProtocolLib); } }.runTaskTimer(LibsDisguises.getInstance(), 10, 10 * 60 * 20); // Run every 10 minutes } @@ -432,18 +433,6 @@ public class DisguiseListener implements Listener { }.runTaskLater(LibsDisguises.getInstance(), 60); } - private void sendUpdateMessage(Player p, String version, String requiredProtocolLib) { - p.sendMessage(ChatColor.RED + "Please ask the server owner to update ProtocolLib! You are running " + version + - " but the minimum version you should be on is " + requiredProtocolLib + "!"); - p.sendMessage(ChatColor.RED + "https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/target" + - "/ProtocolLib" + ".jar"); - p.sendMessage(ChatColor.RED + "Or! Use " + ChatColor.DARK_RED + "/ld updateprotocollib" + ChatColor.RED + - " - To update to the latest development build"); - p.sendMessage(ChatColor.DARK_GREEN + - "This message is `kindly` provided by Lib's Disguises on repeat to all players due to the sheer " + - "number of people who don't see it"); - } - /** * Most likely faster if we don't bother doing checks if he sees a player disguise */