Small Code Changes
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
package net.t2code.alias.Spigot.system;
|
||||
|
||||
import net.t2code.alias.Spigot.Main;
|
||||
import net.t2code.alias.Util;
|
||||
import net.t2code.lib.Spigot.Lib.messages.send;
|
||||
import net.t2code.lib.Spigot.Lib.update.UpdateAPI;
|
||||
import net.t2code.lib.Spigot.system.config.SelectLibConfig;
|
||||
@@ -24,7 +25,7 @@ public class JoinEvent implements Listener {
|
||||
if (player.hasPermission("alias.updatemsg") || player.isOp()) {
|
||||
if (!Main.version.equals(publicVersion)) {
|
||||
if (SelectLibConfig.UpdateCheckOnJoin) {
|
||||
UpdateAPI.sendUpdateMsg(Main.prefix, Main.spigot, Main.discord, Main.version, publicVersion, player);
|
||||
UpdateAPI.sendUpdateMsg(Util.getPrefix(), Util.getSpigot(), Util.getDiscord(), Main.version, publicVersion, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@ import net.t2code.alias.Spigot.config.config.SelectAlias;
|
||||
import net.t2code.alias.Spigot.config.config.SelectConfig;
|
||||
import net.t2code.alias.Spigot.config.languages.LanguagesCreate;
|
||||
import net.t2code.alias.Spigot.config.languages.SelectMessages;
|
||||
import net.t2code.alias.Util;
|
||||
import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate;
|
||||
import net.t2code.lib.Spigot.Lib.update.UpdateAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -43,7 +44,7 @@ public class Load {
|
||||
CreateConfig.configCreate();
|
||||
LanguagesCreate.langCreate();
|
||||
SelectConfig.onSelect();
|
||||
SelectMessages.onSelect(Main.prefix);
|
||||
SelectMessages.onSelect(Util.getPrefix());
|
||||
SelectAlias.onSelect();
|
||||
|
||||
if (SelectConfig.Bungee) {
|
||||
@@ -51,8 +52,5 @@ public class Load {
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(Main.plugin, "t2codealias:bungee");
|
||||
}
|
||||
Alias_RegisterPermissions.onPermRegister();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,116 +0,0 @@
|
||||
// This claas was created by JaTiTV
|
||||
|
||||
package net.t2code.alias.Spigot.system;
|
||||
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.t2code.alias.Spigot.Main;
|
||||
import net.t2code.lib.Spigot.Lib.messages.TextBuilder;
|
||||
import net.t2code.lib.Spigot.Lib.messages.send;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Scanner;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class UpdateChecker {
|
||||
|
||||
public static void sendUpdateMsg(String Prefix, String foundVersion, String update_version) {
|
||||
send.console("§4=========== " + Prefix + " §4===========");
|
||||
send.console("§6A new version was found!");
|
||||
send.console("§6Your version: §c" + foundVersion + " §7- §6Current version: §a" + update_version);
|
||||
send.console("§6You can download it here: §e" + Main.spigot);
|
||||
send.console("§6You can find more information on Discord: §e" + Main.discord);
|
||||
send.console("§4=========== " + Prefix + " §4===========");
|
||||
}
|
||||
|
||||
public static void sendUpdateMsg(String Prefix, String foundVersion, String update_version, Player player) {
|
||||
TextComponent comp = new TextBuilder(Prefix + " §6A new version was found!")
|
||||
.addHover("§6You can download it here: §e" + Main.spigot).addClickEvent(ClickEvent.Action.OPEN_URL, Main.spigot).build();
|
||||
player.spigot().sendMessage(comp);
|
||||
TextComponent comp1 = new TextBuilder(Prefix + " §c" + foundVersion + " §7-> §a" + update_version)
|
||||
.addHover("§6You can download it here: §e" + Main.spigot).addClickEvent(ClickEvent.Action.OPEN_URL, Main.spigot).build();
|
||||
player.spigot().sendMessage(comp1);
|
||||
TextComponent comp2 = new TextBuilder(Prefix + " §6You can find more information on Discord.")
|
||||
.addHover("§e" + Main.discord).addClickEvent(ClickEvent.Action.OPEN_URL, Main.discord).build();
|
||||
player.spigot().sendMessage(comp2);
|
||||
}
|
||||
|
||||
private static Boolean noUpdate = true;
|
||||
public static void onUpdateCheck() {
|
||||
int taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.plugin, new Runnable() {
|
||||
public void run() {
|
||||
(new UpdateChecker(Main.plugin, Main.spigotID)).getVersion((update_version) -> {
|
||||
String foundVersion = Main.plugin.getDescription().getVersion();
|
||||
// Main.update_version = update_version;
|
||||
if (!foundVersion.equalsIgnoreCase(update_version)) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sendUpdateMsg(Main.prefix, foundVersion, update_version);
|
||||
}
|
||||
}.runTaskLater(Main.plugin, 600L);
|
||||
}else {
|
||||
if (noUpdate) {
|
||||
send.console(Main.prefix + " §2No update found.");
|
||||
noUpdate = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 0L, 20 * 60 * 60L);
|
||||
}
|
||||
|
||||
private JavaPlugin plugin;
|
||||
private int resourceId;
|
||||
|
||||
public UpdateChecker(JavaPlugin plugin, int resourceId) {
|
||||
this.plugin = plugin;
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
||||
public void getVersion(Consumer<String> consumer) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
try {
|
||||
InputStream inputStream = (new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId)).openStream();
|
||||
try {
|
||||
Scanner scanner = new Scanner(inputStream);
|
||||
|
||||
try {
|
||||
if (scanner.hasNext()) {
|
||||
consumer.accept(scanner.next());
|
||||
}
|
||||
} catch (Throwable var8) {
|
||||
try {
|
||||
scanner.close();
|
||||
} catch (Throwable var7) {
|
||||
var8.addSuppressed(var7);
|
||||
}
|
||||
throw var8;
|
||||
}
|
||||
scanner.close();
|
||||
} catch (Throwable var9) {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (Throwable var6) {
|
||||
var9.addSuppressed(var6);
|
||||
}
|
||||
}
|
||||
throw var9;
|
||||
}
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
}
|
||||
} catch (IOException var10) {
|
||||
// Main.update_version = " §4No public version found!";
|
||||
this.plugin.getLogger().severe(Main.prefix + "§4 Cannot look for updates: " + var10.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user