From 9df128db6ff1668ab12bb9bdbc6f0650818f0472 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 3 Nov 2019 18:07:12 +1300 Subject: [PATCH] Released 9.8.3, commands disabled for players on non-premium versions --- .../me/libraryaddict/disguise/LibsDisguises.java | 13 +++++-------- .../disguise/commands/DisguiseBaseCommand.java | 13 +++++++++++++ .../disguise/commands/DisguiseCommand.java | 4 ++++ .../disguise/commands/DisguiseEntityCommand.java | 4 ++++ .../disguise/commands/DisguisePlayerCommand.java | 4 ++++ .../disguise/commands/DisguiseRadiusCommand.java | 4 ++++ .../disguise/commands/UndisguiseCommand.java | 8 ++++++++ .../commands/UndisguiseEntityCommand.java | 9 +++++++++ .../commands/UndisguisePlayerCommand.java | 16 ++++++++++++---- .../commands/UndisguiseRadiusCommand.java | 8 ++++++++ .../disguise/utilities/LibsPremium.java | 5 ++++- 11 files changed, 75 insertions(+), 13 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java index a0aba4d6..d5484152 100644 --- a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java @@ -56,17 +56,14 @@ public class LibsDisguises extends JavaPlugin { LibsPremium.check(getDescription().getVersion(), getFile()); if (!LibsPremium.isPremium()) { - getLogger().severe("You must purchase the plugin to use support for 1.14!"); - getLogger().severe("This will be released free once the plugin is stable!"); - getLogger().severe("If you've already purchased the plugin, place the purchased jar inside the " + - "Lib's Disguises plugin folder"); - getPluginLoader().disablePlugin(this); - return; + getLogger() + .info("You are running the free version, commands limited to non-players (Console, Command " + + "Blocks)"); } - if (!ReflectionManager.getMinecraftVersion().startsWith("1.14")) { + if (!ReflectionManager.getMinecraftVersion().startsWith("1.14.4")) { getLogger().severe("You're using the wrong version of Lib's Disguises for your server! This is " + - "intended for 1.14!"); + "intended for 1.14.4!"); getPluginLoader().disablePlugin(this); return; } diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java index c367cf40..a58d6465 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java @@ -1,12 +1,15 @@ package me.libraryaddict.disguise.commands; +import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.disguisetypes.DisguiseType; +import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.parser.DisguiseParser; import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; import me.libraryaddict.disguise.utilities.parser.params.ParamInfoManager; import me.libraryaddict.disguise.utilities.parser.params.ParamInfo; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -36,6 +39,16 @@ public abstract class DisguiseBaseCommand implements CommandExecutor { disguiseCommands = map; } + protected boolean isNotPremium(CommandSender sender) { + if (sender instanceof Player && + (!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) { + sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands"); + return true; + } + + return false; + } + protected List getTabDisguiseTypes(CommandSender sender, DisguisePermissions perms, String[] allArgs, int startsAt, String currentArg) { // If not enough arguments to get current disguise type diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseCommand.java index 1837137e..c6e1f01c 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseCommand.java @@ -23,6 +23,10 @@ import java.util.List; public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (isNotPremium(sender)) { + return true; + } + if (!(sender instanceof Entity)) { sender.sendMessage(LibsMsg.NO_CONSOLE.get()); return true; diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java index c487b32f..29947b82 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java @@ -22,6 +22,10 @@ import java.util.List; public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCompleter { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (isNotPremium(sender)) { + return true; + } + if (!(sender instanceof Player)) { sender.sendMessage(LibsMsg.NO_CONSOLE.get()); return true; diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java index b5ec4013..64e68c09 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java @@ -27,6 +27,10 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (isNotPremium(sender)) { + return true; + } + DisguisePermissions permissions = getPermissions(sender); if (!permissions.hasPermissions()) { diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java index 6e82ccc9..0f96eaaa 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java @@ -42,6 +42,10 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (isNotPremium(sender)) { + return true; + } + if (sender.getName().equals("CONSOLE")) { sender.sendMessage(LibsMsg.NO_CONSOLE.get()); return true; diff --git a/src/main/java/me/libraryaddict/disguise/commands/UndisguiseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/UndisguiseCommand.java index 8ef61651..5ce3373c 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/UndisguiseCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/UndisguiseCommand.java @@ -1,7 +1,9 @@ package me.libraryaddict.disguise.commands; import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -12,6 +14,12 @@ public class UndisguiseCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player && + (!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) { + sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands"); + return true; + } + if (sender.getName().equals("CONSOLE")) { sender.sendMessage(LibsMsg.NO_CONSOLE.get()); return true; diff --git a/src/main/java/me/libraryaddict/disguise/commands/UndisguiseEntityCommand.java b/src/main/java/me/libraryaddict/disguise/commands/UndisguiseEntityCommand.java index 54971029..c7df61b6 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/UndisguiseEntityCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/UndisguiseEntityCommand.java @@ -1,15 +1,24 @@ package me.libraryaddict.disguise.commands; import me.libraryaddict.disguise.LibsDisguises; +import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class UndisguiseEntityCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player && + (!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) { + sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands"); + return true; + } + if (sender.getName().equals("CONSOLE")) { sender.sendMessage(LibsMsg.NO_CONSOLE.get()); return true; diff --git a/src/main/java/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java b/src/main/java/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java index f94a2dad..0ee5c3ae 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java @@ -2,8 +2,10 @@ package me.libraryaddict.disguise.commands; import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.disguisetypes.DisguiseType; +import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.translations.LibsMsg; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -53,6 +55,12 @@ public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player && + (!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) { + sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands"); + return true; + } + if (!sender.hasPermission("libsdisguises.undisguiseplayer")) { sender.sendMessage(LibsMsg.NO_PERM.get()); return true; @@ -82,11 +90,11 @@ public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter { if (DisguiseAPI.isDisguised(entityTarget)) { DisguiseAPI.undisguiseToAll(entityTarget); - sender.sendMessage(LibsMsg.UNDISG_PLAYER - .get(entityTarget instanceof Player ? entityTarget.getName() : DisguiseType.getType(entityTarget).toReadable())); + sender.sendMessage(LibsMsg.UNDISG_PLAYER.get(entityTarget instanceof Player ? entityTarget.getName() : + DisguiseType.getType(entityTarget).toReadable())); } else { - sender.sendMessage(LibsMsg.UNDISG_PLAYER_FAIL - .get(entityTarget instanceof Player ? entityTarget.getName() : DisguiseType.getType(entityTarget).toReadable())); + sender.sendMessage(LibsMsg.UNDISG_PLAYER_FAIL.get(entityTarget instanceof Player ? entityTarget.getName() : + DisguiseType.getType(entityTarget).toReadable())); } return true; diff --git a/src/main/java/me/libraryaddict/disguise/commands/UndisguiseRadiusCommand.java b/src/main/java/me/libraryaddict/disguise/commands/UndisguiseRadiusCommand.java index 36dd5569..31d37dd4 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/UndisguiseRadiusCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/UndisguiseRadiusCommand.java @@ -1,7 +1,9 @@ package me.libraryaddict.disguise.commands; import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -27,6 +29,12 @@ public class UndisguiseRadiusCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player && + (!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) { + sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands"); + return true; + } + if (sender.getName().equals("CONSOLE")) { sender.sendMessage(LibsMsg.NO_CONSOLE.get()); return true; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java b/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java index 41404bbd..526cf3f8 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java @@ -93,7 +93,10 @@ public class LibsPremium { // Comparing major versions // Current version must be the same, or lower than premium version - return Integer.parseInt(currentSplit[0]) <= Integer.parseInt(premSplit[0]); + // return Integer.parseInt(currentSplit[0]) <= Integer.parseInt(premSplit[0]); + + // Snapshot must be of current version + return premiumVersion.equals(currentVersion); } private static PluginInformation getInformation(File file) throws Exception {