Some stuff
This commit is contained in:
parent
4eb367b61b
commit
3e96e765e9
@ -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<TargetedDisguise> 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;
|
||||
}
|
||||
|
@ -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<String, Command> 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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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]+");
|
||||
}
|
||||
}
|
||||
|
@ -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<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 &&
|
||||
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");
|
||||
|
@ -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());
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (!isGoSilent()) {
|
||||
DisguiseUtilities.getLogger().info("Download success!");
|
||||
}
|
||||
|
||||
PluginInformation result = LibsPremium.getInformation(dest);
|
||||
lastDownload = result;
|
||||
|
Loading…
Reference in New Issue
Block a user