Optimize imports, contact github less
This commit is contained in:
		| @@ -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); | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -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.*; | ||||
|   | ||||
| @@ -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. | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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<String, Disguise> 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<String, Object> 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) { | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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; | ||||
|  | ||||
|   | ||||
| @@ -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<String, LibsEntityInteract> interactions = new HashMap<>(); | ||||
|     private HashMap<String, BukkitRunnable> 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; | ||||
|         } | ||||
|  | ||||
|         if (event.isCancelled()) { | ||||
|             event.setCancelled(false); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         if (event.getCause() == EntityDamageEvent.DamageCause.FALL) { | ||||
|             event.setDamage(event.getDamage() * 3); | ||||
|   | ||||
| @@ -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. | ||||
|   | ||||
| @@ -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; | ||||
|         } | ||||
|   | ||||
| @@ -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. | ||||
|  */ | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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. | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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<String, Object> 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()) { | ||||
|   | ||||
| @@ -46,8 +46,7 @@ public class UpdateChecker { | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         boolean isRelease = | ||||
|                 includeDownloaded && getLastDownload() != null ? !getLastDownload().getVersion().contains("-SNAPSHOT") : | ||||
|         boolean isRelease = includeDownloaded && getLastDownload() != null ? !getLastDownload().getVersion().contains("-SNAPSHOT") : | ||||
|                 LibsDisguises.getInstance().isReleaseBuild(); | ||||
|  | ||||
|         if (getUpdate().isReleaseBuild() != isRelease) { | ||||
| @@ -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(".", "")); | ||||
|   | ||||
| @@ -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. | ||||
|   | ||||
| @@ -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. | ||||
|   | ||||
| @@ -11,3 +11,4 @@ LastUpdateCheck: %data% | ||||
| HittingRateLimit: %data% | ||||
| LastGithubETag: %data% | ||||
| LastPluginVersion: %data% | ||||
| Data: %data% | ||||
		Reference in New Issue
	
	Block a user