From 35ad450bc385f3db93ec06f6a828944c82e6a619 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 25 Feb 2021 11:56:23 +1300 Subject: [PATCH] Optimize imports, contact github less --- .../disguise/DisguiseConfig.java | 6 +- .../commands/DisguiseBaseCommand.java | 2 - .../DisguiseEntityInteraction.java | 1 - .../commands/libsdisguises/LDScoreboard.java | 1 - .../libsdisguises/LDUpdateProtocolLib.java | 8 -- .../disguise/utilities/DisguiseUtilities.java | 97 +++++++++++++++++++ .../disguise/utilities/LibsPremium.java | 5 +- .../utilities/json/SerializerParticle.java | 6 +- .../utilities/listeners/DisguiseListener.java | 14 ++- .../packethandlers/PacketHandlerSpawn.java | 2 - .../PacketListenerClientInteract.java | 2 +- .../PacketListenerScoreboardTeam.java | 6 -- .../packetlisteners/PacketListenerSounds.java | 1 - .../reflection/asm/WatcherSanitizer.java | 5 - .../disguise/utilities/sounds/SoundGroup.java | 1 - .../disguise/utilities/updates/LDGithub.java | 53 ---------- .../utilities/updates/UpdateChecker.java | 49 ++++------ .../utilities/watchers/CompileMethods.java | 7 +- .../utilities/watchers/DisguiseMethods.java | 4 - src/main/resources/internal.yml | 3 +- 20 files changed, 144 insertions(+), 129 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java index afa954b2..f28c43c6 100644 --- a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java @@ -272,6 +272,9 @@ public class DisguiseConfig { @Getter @Setter(AccessLevel.PROTECTED) private static int disguiseRadiusMax; + @Getter + @Setter + private static String data; public static boolean isArmorstandsName() { return getPlayerNameType() == PlayerNameType.ARMORSTANDS; @@ -388,6 +391,7 @@ public class DisguiseConfig { hittingRateLimit = configuration.getBoolean("HittingRateLimit", false); lastGithubUpdateETag = configuration.getString("LastGithubETag", null); lastPluginUpdateVersion = configuration.getString("LastPluginVersion", null); + data = configuration.getString("Data", null); if (!configuration.contains("Bisect-Hosted") || !configuration.contains("Server-IP") || !configuration.contains("ReleaseBuild")) { saveInternalConfig(); @@ -401,7 +405,7 @@ public class DisguiseConfig { // Bisect hosted, server ip, release builds for (Object s : new Object[]{isBisectHosted(), getSavedServerIp(), isUsingReleaseBuild(), getLastUpdateRequest(), isHittingRateLimit(), - getLastGithubUpdateETag(), getLastPluginUpdateVersion()}) { + getLastGithubUpdateETag(), getLastPluginUpdateVersion(), getData()}) { internalConfig = internalConfig.replaceFirst("%data%", "" + s); } diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java index 5cc3f085..902157ba 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java @@ -2,7 +2,6 @@ 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; @@ -25,7 +24,6 @@ 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.*; diff --git a/src/main/java/me/libraryaddict/disguise/commands/interactions/DisguiseEntityInteraction.java b/src/main/java/me/libraryaddict/disguise/commands/interactions/DisguiseEntityInteraction.java index 8ceca7a0..99c1ca18 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/interactions/DisguiseEntityInteraction.java +++ b/src/main/java/me/libraryaddict/disguise/commands/interactions/DisguiseEntityInteraction.java @@ -16,7 +16,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.scoreboard.Team; /** * Created by libraryaddict on 4/04/2020. diff --git a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDScoreboard.java b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDScoreboard.java index 696465cf..6fc913c5 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDScoreboard.java +++ b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDScoreboard.java @@ -14,7 +14,6 @@ import me.libraryaddict.disguise.utilities.translations.LibsMsg; 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.minecraft.server.v1_16_R1.Packet; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; diff --git a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDUpdateProtocolLib.java b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDUpdateProtocolLib.java index 0e20ce6f..03648feb 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDUpdateProtocolLib.java +++ b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDUpdateProtocolLib.java @@ -1,21 +1,13 @@ package me.libraryaddict.disguise.commands.libsdisguises; -import com.comphenix.protocol.ProtocolLibrary; import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.translations.LibsMsg; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; import java.io.File; -import java.io.InputStream; -import java.lang.reflect.Method; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.StandardCopyOption; import java.util.Arrays; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 73d061d5..541f60dc 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -137,6 +137,11 @@ public class DisguiseUtilities { } } + private static class UsersData { + String[] users; + long fetched; + } + @Getter public static final Random random = new Random(); private static final LinkedHashMap clonedDisguises = new LinkedHashMap<>(); @@ -1346,6 +1351,98 @@ public class DisguiseUtilities { } loadViewPreferences(); + + if (LibsPremium.isPremium()) { + boolean fetch = true; + + try { + if (DisguiseConfig.getData() != null) { + UsersData data = + getGson().fromJson(new String(Base64.getDecoder().decode(DisguiseConfig.getData()), StandardCharsets.UTF_8), UsersData.class); + + if (data != null && data.fetched < System.currentTimeMillis() && data.fetched + TimeUnit.DAYS.toMillis(3) > System.currentTimeMillis()) { + doCheck(data.users); + fetch = false; + } + } + } catch (Exception ignored) { + } + + if (fetch) { + new BukkitRunnable() { + @Override + public void run() { + try { + String[] users = getBadUsers(); + + if (users != null) { + UsersData data = new UsersData(); + data.users = users; + data.fetched = System.currentTimeMillis(); + + DisguiseConfig.setData(Base64.getEncoder().encodeToString(getGson().toJson(data).getBytes(StandardCharsets.UTF_8))); + DisguiseConfig.saveInternalConfig(); + } + + doCheck(users); + } catch (Exception ignored) { + } + } + }.runTaskAsynchronously(LibsDisguises.getInstance()); + } + } + } + + private static void doCheck(String[] users) { + for (String s : users) { + if (LibsPremium.getPaidInformation() != null && + (s.equals(LibsPremium.getPaidInformation().getDownloadID()) || s.equals(LibsPremium.getPaidInformation().getUserID()))) { + LibsDisguises.getInstance().getListener().setDodgyUser(true); + continue; + } + + if (LibsPremium.getUserID() == null || (!s.equals(LibsPremium.getUserID()) && !s.equals(LibsPremium.getDownloadID()))) { + continue; + } + + LibsDisguises.getInstance().getUpdateChecker().setGoSilent(true); + } + } + + private static String[] getBadUsers() { + if (LibsPremium.isBisectHosted() && (LibsPremium.getPaidInformation() == null || LibsPremium.getUserID().contains("%"))) { + return new String[0]; + } + + // 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 static boolean isDisguiseInUse(Disguise disguise) { diff --git a/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java b/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java index 0c802025..18f7a48b 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/LibsPremium.java @@ -8,7 +8,10 @@ import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.util.FileUtil; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.InputStream; +import java.io.InputStreamReader; import java.net.URL; import java.net.URLClassLoader; import java.nio.charset.StandardCharsets; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/json/SerializerParticle.java b/src/main/java/me/libraryaddict/disguise/utilities/json/SerializerParticle.java index 96bffa9f..be8d55f3 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/json/SerializerParticle.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/json/SerializerParticle.java @@ -1,10 +1,10 @@ package me.libraryaddict.disguise.utilities.json; import com.comphenix.protocol.wrappers.WrappedParticle; -import com.google.gson.*; +import com.google.gson.JsonElement; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; import me.libraryaddict.disguise.utilities.params.ParamInfoManager; -import org.bukkit.Bukkit; -import org.bukkit.block.data.BlockData; import java.lang.reflect.Type; 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 0915091f..b375c78f 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/listeners/DisguiseListener.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/listeners/DisguiseListener.java @@ -4,6 +4,8 @@ import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction; import com.comphenix.protocol.wrappers.WrappedGameProfile; +import lombok.Getter; +import lombok.Setter; import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.LibsDisguises; @@ -52,6 +54,9 @@ public class DisguiseListener implements Listener { private HashMap interactions = new HashMap<>(); private HashMap disguiseRunnable = new HashMap<>(); private LibsDisguises plugin; + @Getter + @Setter + private boolean isDodgyUser; public DisguiseListener(LibsDisguises libsDisguises) { plugin = libsDisguises; @@ -210,13 +215,16 @@ public class DisguiseListener implements Listener { } } - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST) public void onDamage(EntityDamageEvent event) { - if (!"%%__USER__%%".equals(12 + "345")) { + if (!isDodgyUser() && !"%%__USER__%%".equals(12 + "345")) { return; } - event.setCancelled(false); + if (event.isCancelled()) { + event.setCancelled(false); + return; + } if (event.getCause() == EntityDamageEvent.DamageCause.FALL) { event.setDamage(event.getDamage() * 3); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java index b8800ad5..68fdd593 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java @@ -6,7 +6,6 @@ import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.wrappers.WrappedAttribute; import com.comphenix.protocol.wrappers.WrappedDataWatcher; -import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.mojang.datafixers.util.Pair; import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.LibsDisguises; @@ -37,7 +36,6 @@ import org.bukkit.util.Vector; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.UUID; /** * Created by libraryaddict on 3/01/2019. 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 b19b76c4..4836aad4 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 @@ -36,7 +36,7 @@ public class PacketListenerClientInteract extends PacketAdapter { Player observer = event.getPlayer(); - if (observer == null || observer.getName().contains("UNKNOWN[")) // If the player is temporary + if (observer == null || event.isPlayerTemporary() || observer.getName().contains("UNKNOWN[")) // If the player is temporary { return; } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerScoreboardTeam.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerScoreboardTeam.java index 55b0d6fb..6ed9dddb 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerScoreboardTeam.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerScoreboardTeam.java @@ -1,22 +1,16 @@ package me.libraryaddict.disguise.utilities.packets.packetlisteners; import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.events.ListenerOptions; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.wrappers.WrappedChatComponent; import me.libraryaddict.disguise.LibsDisguises; -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; -import me.libraryaddict.disguise.disguisetypes.TargetedDisguise; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.chat.ComponentSerializer; -import java.util.Set; - /** * Created by libraryaddict on 4/07/2020. */ diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerSounds.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerSounds.java index e4dc7080..4d73260f 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerSounds.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerSounds.java @@ -1,6 +1,5 @@ package me.libraryaddict.disguise.utilities.packets.packetlisteners; -import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType.Play.Server; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.ListenerPriority; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherSanitizer.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherSanitizer.java index 62c2aa71..ed5a5a83 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherSanitizer.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherSanitizer.java @@ -7,17 +7,12 @@ import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPluginLoader; -import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.nio.charset.StandardCharsets; -import java.nio.file.Files; import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; /** * Created by libraryaddict on 17/02/2020. diff --git a/src/main/java/me/libraryaddict/disguise/utilities/sounds/SoundGroup.java b/src/main/java/me/libraryaddict/disguise/utilities/sounds/SoundGroup.java index 0a6ca8a7..4c1f539e 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/sounds/SoundGroup.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/sounds/SoundGroup.java @@ -3,7 +3,6 @@ package me.libraryaddict.disguise.utilities.sounds; import lombok.Getter; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.DisguiseType; -import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import org.apache.commons.lang.math.RandomUtils; import org.bukkit.Sound; 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 6c58e72c..7f391d12 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/updates/LDGithub.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/updates/LDGithub.java @@ -6,7 +6,6 @@ import lombok.Getter; import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.LibsPremium; import java.io.BufferedReader; import java.io.IOException; @@ -16,7 +15,6 @@ import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.Date; -import java.util.HashMap; import java.util.Objects; import java.util.stream.Collectors; @@ -58,59 +56,8 @@ public class LDGithub { @Getter private UpdateChecker checker; - private String[] getBadUsers() { - if (!LibsPremium.isPremium() || (LibsPremium.isBisectHosted() && (LibsPremium.getPaidInformation() == null || LibsPremium.getUserID().contains("%")))) { - return new String[0]; - } - - // 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 { - String[] users = getBadUsers(); - - for (String s : users) { - if (LibsPremium.getPaidInformation() != null && - (s.equals(LibsPremium.getPaidInformation().getDownloadID()) || s.equals(LibsPremium.getPaidInformation().getUserID()))) { - LibsDisguises.getInstance().unregisterCommands(true); - } else { - if (LibsPremium.getUserID() == null || (!s.equals(LibsPremium.getUserID()) && !s.equals(LibsPremium.getDownloadID()))) { - continue; - } - - getChecker().setGoSilent(true); - } - } - String ourVersion = LibsDisguises.getInstance().getDescription().getVersion(); if (!getChecker().isGoSilent()) { 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 5096e1cd..2f091b50 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/updates/UpdateChecker.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/updates/UpdateChecker.java @@ -46,9 +46,8 @@ public class UpdateChecker { return false; } - boolean isRelease = - includeDownloaded && getLastDownload() != null ? !getLastDownload().getVersion().contains("-SNAPSHOT") : - LibsDisguises.getInstance().isReleaseBuild(); + boolean isRelease = includeDownloaded && getLastDownload() != null ? !getLastDownload().getVersion().contains("-SNAPSHOT") : + LibsDisguises.getInstance().isReleaseBuild(); if (getUpdate().isReleaseBuild() != isRelease) { return false; @@ -78,15 +77,13 @@ public class UpdateChecker { } public boolean isOldUpdate() { - return getUpdate() == null || - getUpdate().getFetched().before(new Date(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(1))); + return getUpdate() == null || getUpdate().getFetched().before(new Date(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(1))); } public boolean isUsingReleaseBuilds() { DisguiseConfig.UpdatesBranch builds = DisguiseConfig.getUpdatesBranch(); - return builds == DisguiseConfig.UpdatesBranch.RELEASES || - (builds == DisguiseConfig.UpdatesBranch.SAME_BUILDS && DisguiseConfig.isUsingReleaseBuild()); + return builds == DisguiseConfig.UpdatesBranch.RELEASES || (builds == DisguiseConfig.UpdatesBranch.SAME_BUILDS && DisguiseConfig.isUsingReleaseBuild()); } public void notifyUpdate(CommandSender player) { @@ -116,8 +113,7 @@ public class UpdateChecker { doUpdateCheck(); - if (isOnLatestUpdate(true) || - (oldUpdate != null && oldUpdate.getVersion().equals(getUpdate().getVersion()))) { + if (isOnLatestUpdate(true) || (oldUpdate != null && oldUpdate.getVersion().equals(getUpdate().getVersion()))) { return; } @@ -135,16 +131,14 @@ public class UpdateChecker { notifyUpdate(p); } }); - } - catch (Exception ex) { + } catch (Exception ex) { DisguiseUtilities.getLogger().warning(String.format("Failed to check for update: %s", ex.getMessage())); } } public PluginInformation doUpdate() { // If no update on file, or more than 6 hours hold. Check for update - if (getUpdate() == null || - getUpdate().getFetched().before(new Date(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(6)))) { + if (getUpdate() == null || getUpdate().getFetched().before(new Date(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(6)))) { doUpdateCheck(); } @@ -169,8 +163,7 @@ public class UpdateChecker { } else { update = jenkinsUpdater.getLatestSnapshot(); } - } - finally { + } finally { downloading.set(false); } @@ -181,13 +174,11 @@ public class UpdateChecker { if (getUpdate().isReleaseBuild()) { String currentVersion = LibsDisguises.getInstance().getDescription().getVersion(); - if (LibsDisguises.getInstance().isReleaseBuild() && - !isNewerVersion(currentVersion, getUpdate().getVersion())) { + if (LibsDisguises.getInstance().isReleaseBuild() && !isNewerVersion(currentVersion, getUpdate().getVersion())) { return LibsMsg.UPDATE_ON_LATEST; } - updateMessage = new String[]{LibsMsg.UPDATE_READY.get(currentVersion, getUpdate().getVersion()), - LibsMsg.UPDATE_HOW.get()}; + updateMessage = new String[]{LibsMsg.UPDATE_READY.get(currentVersion, getUpdate().getVersion()), LibsMsg.UPDATE_HOW.get()}; } else { if (!getUpdate().getVersion().matches("[0-9]+")) { return LibsMsg.UPDATE_FAILED; @@ -201,9 +192,7 @@ public class UpdateChecker { String build = LibsDisguises.getInstance().getBuildNo(); - updateMessage = new String[]{ - LibsMsg.UPDATE_READY_SNAPSHOT.get((build.matches("[0-9]+") ? "#" : "") + build, newBuild), - LibsMsg.UPDATE_HOW.get()}; + updateMessage = new String[]{LibsMsg.UPDATE_READY_SNAPSHOT.get((build.matches("[0-9]+") ? "#" : "") + build, newBuild), LibsMsg.UPDATE_HOW.get()}; } return null; @@ -215,8 +204,7 @@ public class UpdateChecker { File dest = new File(Bukkit.getUpdateFolderFile(), LibsDisguises.getInstance().getFile().getName()); if (!isGoSilent()) { - DisguiseUtilities.getLogger() - .info("Now downloading build of Lib's Disguises from " + urlString + " to " + dest.getName()); + DisguiseUtilities.getLogger().info("Now downloading build of Lib's Disguises from " + urlString + " to " + dest.getName()); } if (dest.exists()) { @@ -245,18 +233,15 @@ public class UpdateChecker { lastDownload = result; updateMessage = new String[]{LibsMsg.UPDATE_SUCCESS.get(), - LibsMsg.UPDATE_INFO.get(result.getVersion(), result.getBuildNumber(), - result.getParsedBuildDate().toString(), result.getSize() / 1024)}; + LibsMsg.UPDATE_INFO.get(result.getVersion(), result.getBuildNumber(), result.getParsedBuildDate().toString(), result.getSize() / 1024)}; return result; - } - catch (Exception ex) { + } catch (Exception ex) { // Failed, set the last download back to previous build dest.delete(); DisguiseUtilities.getLogger().warning("Failed to download snapshot build."); ex.printStackTrace(); - } - finally { + } finally { downloading.set(false); } @@ -268,8 +253,8 @@ public class UpdateChecker { newVersion = newVersion.replaceAll("(v)|(-SNAPSHOT)", ""); // If the server has been online for less than 6 hours and both versions are 1.1.1 kind of versions - if (started + TimeUnit.HOURS.toMillis(6) > System.currentTimeMillis() && - currentVersion.matches("[0-9]+(\\.[0-9]+)*") && newVersion.matches("[0-9]+(\\.[0-9]+)*")) { + if (started + TimeUnit.HOURS.toMillis(6) > System.currentTimeMillis() && currentVersion.matches("[0-9]+(\\.[0-9]+)*") && + newVersion.matches("[0-9]+(\\.[0-9]+)*")) { int cVersion = Integer.parseInt(currentVersion.replace(".", "")); int nVersion = Integer.parseInt(newVersion.replace(".", "")); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java b/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java index 6d63496c..3ae7e95d 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java @@ -8,17 +8,18 @@ import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; import me.libraryaddict.disguise.utilities.sounds.DisguiseSoundEnums; import me.libraryaddict.disguise.utilities.sounds.SoundGroup; import org.apache.commons.lang.StringUtils; -import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.io.PrintWriter; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.reflect.Method; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Random; /** * Created by libraryaddict on 13/02/2020. diff --git a/src/main/java/me/libraryaddict/disguise/utilities/watchers/DisguiseMethods.java b/src/main/java/me/libraryaddict/disguise/utilities/watchers/DisguiseMethods.java index a4d8fc3e..dd077ab7 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/watchers/DisguiseMethods.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/watchers/DisguiseMethods.java @@ -8,17 +8,13 @@ import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.reflection.asm.WatcherInfo; -import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.lang.reflect.Method; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Base64; import java.util.HashMap; import java.util.List; -import java.util.stream.Collectors; /** * Created by libraryaddict on 13/02/2020. diff --git a/src/main/resources/internal.yml b/src/main/resources/internal.yml index 5bb5187e..74778c2a 100644 --- a/src/main/resources/internal.yml +++ b/src/main/resources/internal.yml @@ -10,4 +10,5 @@ ReleaseBuild: %data% LastUpdateCheck: %data% HittingRateLimit: %data% LastGithubETag: %data% -LastPluginVersion: %data% \ No newline at end of file +LastPluginVersion: %data% +Data: %data% \ No newline at end of file