1.0.6 #1

Merged
JaTiTV merged 4 commits from 1.0.6 into main 2022-01-29 18:44:30 +00:00
15 changed files with 83 additions and 181 deletions
Showing only changes of commit 3d6c911d8a - Show all commits

View File

@ -69,7 +69,7 @@
<dependency> <dependency>
<groupId>net.t2code</groupId> <groupId>net.t2code</groupId>
<artifactId>T2CodeLib</artifactId> <artifactId>T2CodeLib</artifactId>
<version>10.8</version> <version>11.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.t2code</groupId> <groupId>net.t2code</groupId>

View File

@ -15,13 +15,6 @@ public final class BMain extends Plugin {
public static String version; public static String version;
public static String autor; public static String autor;
public static String prefix = Util.Prefix;
public static Integer spigotID = Util.SpigotID;
public static Integer bstatsID = Util.BstatsID;
public static String spigot = Util.Spigot;
public static String discord = Util.Discord;
@Override @Override
public void onEnable() { public void onEnable() {
// Plugin startup logic // Plugin startup logic
@ -30,18 +23,18 @@ public final class BMain extends Plugin {
autor = plugin.getDescription().getAuthor(); autor = plugin.getDescription().getAuthor();
if (ProxyServer.getInstance().getPluginManager().getPlugin("T2CodeLib") == null) { if (ProxyServer.getInstance().getPluginManager().getPlugin("T2CodeLib") == null) {
plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!"); plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!");
ProxyServer.getInstance().getConsole().sendMessage(prefix + " §eT2CodeLib §4could not be found. Please download it here: " + ProxyServer.getInstance().getConsole().sendMessage(Util.getPrefix() + " §eT2CodeLib §4could not be found. Please download it here: " +
"§6https://www.spigotmc.org/resources/t2codelib.96388/ §4to be able to use this plugin."); "§6https://www.spigotmc.org/resources/t2codelib.96388/ §4to be able to use this plugin.");
getProxy().getPluginManager().getPlugin(plugin.getDescription().getName()).onDisable(); getProxy().getPluginManager().getPlugin(plugin.getDescription().getName()).onDisable();
return; return;
} }
BLoad.onLoad(plugin, prefix, autor, version, spigot, discord, spigotID, bstatsID); BLoad.onLoad(plugin, Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord(), Util.getSpigotID(), Util.getBstatsID());
} }
@Override @Override
public void onDisable() { public void onDisable() {
// Plugin shutdown logic // Plugin shutdown logic
if (ProxyServer.getInstance().getPluginManager().getPlugin("T2CodeLib") == null) return; if (ProxyServer.getInstance().getPluginManager().getPlugin("T2CodeLib") == null) return;
BT2CodeTemplate.onDisable(prefix, autor, version, spigot, discord); BT2CodeTemplate.onDisable(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
} }
} }

View File

@ -11,6 +11,7 @@ import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.logging.Level; import java.util.logging.Level;
public final class Main extends JavaPlugin { public final class Main extends JavaPlugin {
@ -18,13 +19,6 @@ public final class Main extends JavaPlugin {
return plugin.getDataFolder(); return plugin.getDataFolder();
} }
public static String prefix = Util.Prefix;
public static Integer spigotID = Util.SpigotID;
public static Integer bstatsID = Util.BstatsID;
public static String spigot = Util.Spigot;
public static String discord = Util.Discord;
public static String version; public static String version;
public static List<String> autor; public static List<String> autor;
@ -39,8 +33,8 @@ public final class Main extends JavaPlugin {
plugin = this; plugin = this;
autor = plugin.getDescription().getAuthors(); autor = plugin.getDescription().getAuthors();
version = plugin.getDescription().getVersion(); version = plugin.getDescription().getVersion();
isPlugin("T2CodeLib",96388); if (pluginNotFound("T2CodeLib", 96388, Util.getRequiredT2CodeLibVersion())) return;
Load.onLoad(prefix, autor, version, spigot, spigotID, discord, bstatsID); Load.onLoad(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getSpigotID(), Util.getDiscord(), Util.getBstatsID());
} }
@Override @Override
@ -49,16 +43,24 @@ public final class Main extends JavaPlugin {
aliasHashMap.clear(); aliasHashMap.clear();
allAliases.clear(); allAliases.clear();
if (Bukkit.getPluginManager().getPlugin("T2CodeLib") == null) return; if (Bukkit.getPluginManager().getPlugin("T2CodeLib") == null) return;
T2CodeTemplate.onDisable(prefix, autor, version, spigot, discord); T2CodeTemplate.onDisable(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
} }
public static void isPlugin(String pl, Integer spigotID) { public static Boolean pluginNotFound(String pl, Integer spigotID, double ver) {
if (Bukkit.getPluginManager().getPlugin(pl) == null) { if (Bukkit.getPluginManager().getPlugin(pl) == null) {
plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!"); plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!");
Bukkit.getConsoleSender().sendMessage(prefix + " §e" + pl + " §4could not be found. Please download it here: " + Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §e" + pl + " §4could not be found. Please download it here: " +
"§6https://spigotmc.org/resources/" + pl + "." + spigotID + " §4to be able to use this plugin."); "§6https://spigotmc.org/resources/" + pl + "." + spigotID + " §4to be able to use this plugin.");
Main.plugin.getPluginLoader().disablePlugin(Main.plugin); Main.plugin.getPluginLoader().disablePlugin(Main.plugin);
return; return true;
} else {
if (Double.parseDouble(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin(pl)).getDescription().getVersion()) < ver) {
plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!");
Bukkit.getConsoleSender().sendMessage(Util.getPrefix() + " §e" + pl + " §4is out of date! This plugin requires at least version §2" + ver + " §4of §6" + pl + " §4Please update it here: §6https://spigotmc.org/resources/" + pl + "." + spigotID + " §4to use this version of " + plugin.getDescription().getName() + ".");
Main.plugin.getPluginLoader().disablePlugin(Main.plugin);
return true;
}
return false;
} }
} }
} }

View File

@ -19,7 +19,6 @@ public class Alias_CmdExecuter implements CommandExecutor, TabCompleter {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Prefix = Main.prefix;
if (args.length == 0) { if (args.length == 0) {
// Command // Command

View File

@ -3,6 +3,7 @@ package net.t2code.alias.Spigot.cmdManagement;
import net.t2code.alias.Spigot.Main; import net.t2code.alias.Spigot.Main;
import net.t2code.alias.Spigot.config.languages.SelectMessages; import net.t2code.alias.Spigot.config.languages.SelectMessages;
import net.t2code.alias.Spigot.system.Load; import net.t2code.alias.Spigot.system.Load;
import net.t2code.alias.Util;
import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate; import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate;
import net.t2code.lib.Spigot.Lib.messages.send; import net.t2code.lib.Spigot.Lib.messages.send;
import net.t2code.lib.Spigot.Lib.update.UpdateAPI; import net.t2code.lib.Spigot.Lib.update.UpdateAPI;
@ -13,26 +14,19 @@ import org.bukkit.plugin.Plugin;
import java.util.List; import java.util.List;
public class Commands { public class Commands {
private static Plugin plugin = Main.plugin;
private static String prefix = Main.prefix;
private static List autor = Main.autor;
private static String version = Main.version;
private static String spigot = Main.spigot;
private static String discord = Main.discord;
public static void info(CommandSender sender) { public static void info(CommandSender sender) {
T2CodeTemplate.sendInfo(sender,prefix,spigot,discord,autor,version, UpdateAPI.PluginVersionen.get(plugin.getName()).publicVersion); T2CodeTemplate.sendInfo(sender, Util.getPrefix(),Util.getSpigot(),Util.getDiscord(),Main.autor,Main.version, UpdateAPI.PluginVersionen.get(Main.plugin.getName()).publicVersion);
} }
public static void reload(CommandSender sender) { public static void reload(CommandSender sender) {
if (sender instanceof Player) sender.sendMessage(SelectMessages.ReloadStart); if (sender instanceof Player) sender.sendMessage(SelectMessages.ReloadStart);
send.console(prefix + "§8-------------------------------"); send.console(Util.getPrefix() + "§8-------------------------------");
send.console(prefix + " §6Plugin reload..."); send.console(Util.getPrefix() + " §6Plugin reload...");
send.console(prefix + "§8-------------------------------"); send.console(Util.getPrefix() + "§8-------------------------------");
Load.loadReload(); Load.loadReload();
if (sender instanceof Player) sender.sendMessage(SelectMessages.ReloadEnd); if (sender instanceof Player) sender.sendMessage(SelectMessages.ReloadEnd);
send.console(prefix + "§8-------------------------------"); send.console(Util.getPrefix() + "§8-------------------------------");
send.console(prefix + " §2Plugin successfully reloaded."); send.console(Util.getPrefix() + " §2Plugin successfully reloaded.");
send.console(prefix + "§8-------------------------------"); send.console(Util.getPrefix() + "§8-------------------------------");
} }
} }

View File

@ -6,6 +6,7 @@ import net.t2code.alias.Spigot.config.config.SelectConfig;
import net.t2code.alias.Spigot.config.languages.SelectMessages; import net.t2code.alias.Spigot.config.languages.SelectMessages;
import net.t2code.alias.Spigot.objects.Alias_Objekt; import net.t2code.alias.Spigot.objects.Alias_Objekt;
import net.t2code.alias.Spigot.system.*; import net.t2code.alias.Spigot.system.*;
import net.t2code.alias.Util;
import net.t2code.lib.Spigot.Lib.commands.Cmd; import net.t2code.lib.Spigot.Lib.commands.Cmd;
import net.t2code.lib.Spigot.Lib.messages.TextBuilder; import net.t2code.lib.Spigot.Lib.messages.TextBuilder;
import net.t2code.lib.Spigot.Lib.messages.send; import net.t2code.lib.Spigot.Lib.messages.send;
@ -17,7 +18,7 @@ import org.bukkit.entity.Player;
public class RegisterCommands extends Command { public class RegisterCommands extends Command {
private String alias; private String alias;
private String prefix = Main.prefix; private String prefix = Util.getPrefix();
public RegisterCommands(String alias) { public RegisterCommands(String alias) {
super(alias); super(alias);
@ -46,8 +47,8 @@ public class RegisterCommands extends Command {
} else BCommand_Sender_Reciver.sendToBungee(player, cmd.replace("[player]", player.getName()), false); } else BCommand_Sender_Reciver.sendToBungee(player, cmd.replace("[player]", player.getName()), false);
} else { } else {
send.console(Main.prefix + " §4To use bungee commands, enable the Bungee option in the config."); send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
send.player(player, Main.prefix + " §4To use bungee commands, enable the Bungee option in the config."); send.player(player, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
} }
} else { } else {
if (Alias.AdminCommandAsConsole) { if (Alias.AdminCommandAsConsole) {
@ -101,8 +102,8 @@ public class RegisterCommands extends Command {
} else BCommand_Sender_Reciver.sendToBungee(player, cmd.replace("[player]", player.getName()), false); } else BCommand_Sender_Reciver.sendToBungee(player, cmd.replace("[player]", player.getName()), false);
} else { } else {
send.console(Main.prefix + " §4To use bungee commands, enable the Bungee option in the config."); send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
send.player(player, Main.prefix + " §4To use bungee commands, enable the Bungee option in the config."); send.player(player, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
} }
} else { } else {
if (Alias.CommandAsConsole) { if (Alias.CommandAsConsole) {
@ -144,8 +145,8 @@ public class RegisterCommands extends Command {
if (SelectConfig.Bungee) { if (SelectConfig.Bungee) {
BCommand_Sender_Reciver.sendToBungee(sender, cmd.replace("[player]", sender.getName()), true); BCommand_Sender_Reciver.sendToBungee(sender, cmd.replace("[player]", sender.getName()), true);
} else { } else {
send.console(Main.prefix + " §4To use bungee commands, enable the Bungee option in the config."); send.console(Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
send.sender(sender, Main.prefix + " §4To use bungee commands, enable the Bungee option in the config."); send.sender(sender, Util.getPrefix() + " §4To use bungee commands, enable the Bungee option in the config.");
} }
} else { } else {
Cmd.console(cmd.replace("[player]", sender.getName())); Cmd.console(cmd.replace("[player]", sender.getName()));

View File

@ -1,6 +1,7 @@
package net.t2code.alias.Spigot.config.config; package net.t2code.alias.Spigot.config.config;
import net.t2code.alias.Spigot.Main; 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.messages.send;
import net.t2code.lib.Spigot.Lib.yamlConfiguration.Config; import net.t2code.lib.Spigot.Lib.yamlConfiguration.Config;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -19,8 +20,8 @@ public class CreateConfig {
public static void configCreate() { public static void configCreate() {
Long long_ = Long.valueOf(System.currentTimeMillis()); Long long_ = Long.valueOf(System.currentTimeMillis());
if (new File(Main.getPath(), "config.yml").exists()) { if (new File(Main.getPath(), "config.yml").exists()) {
if (Main.plugin.getConfig().getBoolean("Plugin.Debug")) send.console(Main.prefix + " §5DEBUG: §6" + " §4config.yml are created / updated..."); if (Main.plugin.getConfig().getBoolean("Plugin.Debug")) send.console(Util.getPrefix() + " §5DEBUG: §6" + " §4config.yml are created / updated...");
} else send.console(Main.prefix + " §4config.yml are created..."); } else send.console(Util.getPrefix() + " §4config.yml are created...");
File config = new File(Main.getPath(), "config.yml"); File config = new File(Main.getPath(), "config.yml");
@ -40,6 +41,6 @@ public class CreateConfig {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
send.console(Main.prefix + " §2config.yml were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms"); send.console(Util.getPrefix() + " §2config.yml were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms");
} }
} }

View File

@ -1,6 +1,7 @@
package net.t2code.alias.Spigot.config.config; package net.t2code.alias.Spigot.config.config;
import net.t2code.alias.Spigot.Main; 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.messages.send;
import net.t2code.lib.Spigot.Lib.yamlConfiguration.Config; import net.t2code.lib.Spigot.Lib.yamlConfiguration.Config;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -54,8 +55,8 @@ public class CreateExampleAliasConfig {
public static void configCreate() { public static void configCreate() {
Long long_ = Long.valueOf(System.currentTimeMillis()); Long long_ = Long.valueOf(System.currentTimeMillis());
if (new File(Main.getPath(), "config.yml").exists()) { if (new File(Main.getPath(), "config.yml").exists()) {
if (Main.plugin.getConfig().getBoolean("Plugin.Debug")) send.console(Main.prefix + " §5DEBUG: §6" + " §4config.yml are created / updated..."); if (Main.plugin.getConfig().getBoolean("Plugin.Debug")) send.console(Util.getPrefix() + " §5DEBUG: §6" + " §4config.yml are created / updated...");
} else send.console(Main.prefix + " §4config.yml are created..."); } else send.console(Util.getPrefix() + " §4config.yml are created...");
File config = new File(Main.getPath(), "Alias/aliasexample.yml"); File config = new File(Main.getPath(), "Alias/aliasexample.yml");
@ -106,6 +107,6 @@ public class CreateExampleAliasConfig {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
send.console(Main.prefix + " §2config.yml were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms"); send.console(Util.getPrefix() + " §2config.yml were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms");
} }
} }

View File

@ -3,12 +3,13 @@ package net.t2code.alias.Spigot.config.config;
import net.t2code.alias.Spigot.Main; import net.t2code.alias.Spigot.Main;
import net.t2code.alias.Spigot.system.AliasRegister; import net.t2code.alias.Spigot.system.AliasRegister;
import net.t2code.alias.Spigot.objects.Alias_Objekt; import net.t2code.alias.Spigot.objects.Alias_Objekt;
import net.t2code.alias.Util;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
public class SelectAlias { public class SelectAlias {
private static String Prefix = Main.prefix; private static String Prefix = Util.getPrefix();
public static void onSelect() { public static void onSelect() {
Main.aliasHashMap.clear(); Main.aliasHashMap.clear();

View File

@ -1,6 +1,7 @@
package net.t2code.alias.Spigot.config.languages; package net.t2code.alias.Spigot.config.languages;
import net.t2code.alias.Spigot.Main; 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.messages.send;
import net.t2code.lib.Spigot.Lib.yamlConfiguration.Config; import net.t2code.lib.Spigot.Lib.yamlConfiguration.Config;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -86,7 +87,7 @@ public class LanguagesCreate {
} }
send.console(Main.prefix + " §2Language files were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms"); send.console(Util.getPrefix() + " §2Language files were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms");
} }
} }

View File

@ -2,6 +2,7 @@ package net.t2code.alias.Spigot.config.languages;
import net.t2code.alias.Spigot.Main; import net.t2code.alias.Spigot.Main;
import net.t2code.alias.Spigot.config.config.SelectConfig; import net.t2code.alias.Spigot.config.config.SelectConfig;
import net.t2code.alias.Util;
import net.t2code.lib.Spigot.Lib.messages.send; import net.t2code.lib.Spigot.Lib.messages.send;
import net.t2code.lib.Spigot.Lib.yamlConfiguration.Config; import net.t2code.lib.Spigot.Lib.yamlConfiguration.Config;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -9,7 +10,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
public class SelectMessages { public class SelectMessages {
private static String prefix = Main.prefix; private static String prefix = Util.getPrefix();
public static String selectMSG; public static String selectMSG;

View File

@ -3,6 +3,7 @@
package net.t2code.alias.Spigot.system; package net.t2code.alias.Spigot.system;
import net.t2code.alias.Spigot.Main; 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.messages.send;
import net.t2code.lib.Spigot.Lib.update.UpdateAPI; import net.t2code.lib.Spigot.Lib.update.UpdateAPI;
import net.t2code.lib.Spigot.system.config.SelectLibConfig; 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 (player.hasPermission("alias.updatemsg") || player.isOp()) {
if (!Main.version.equals(publicVersion)) { if (!Main.version.equals(publicVersion)) {
if (SelectLibConfig.UpdateCheckOnJoin) { 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);
} }
} }
} }

View File

@ -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.config.SelectConfig;
import net.t2code.alias.Spigot.config.languages.LanguagesCreate; import net.t2code.alias.Spigot.config.languages.LanguagesCreate;
import net.t2code.alias.Spigot.config.languages.SelectMessages; 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.messages.T2CodeTemplate;
import net.t2code.lib.Spigot.Lib.update.UpdateAPI; import net.t2code.lib.Spigot.Lib.update.UpdateAPI;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -43,7 +44,7 @@ public class Load {
CreateConfig.configCreate(); CreateConfig.configCreate();
LanguagesCreate.langCreate(); LanguagesCreate.langCreate();
SelectConfig.onSelect(); SelectConfig.onSelect();
SelectMessages.onSelect(Main.prefix); SelectMessages.onSelect(Util.getPrefix());
SelectAlias.onSelect(); SelectAlias.onSelect();
if (SelectConfig.Bungee) { if (SelectConfig.Bungee) {
@ -51,8 +52,5 @@ public class Load {
Bukkit.getMessenger().registerOutgoingPluginChannel(Main.plugin, "t2codealias:bungee"); Bukkit.getMessenger().registerOutgoingPluginChannel(Main.plugin, "t2codealias:bungee");
} }
Alias_RegisterPermissions.onPermRegister(); Alias_RegisterPermissions.onPermRegister();
} }
} }

View File

@ -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());
}
});
}
}

View File

@ -1,9 +1,34 @@
package net.t2code.alias; package net.t2code.alias;
public class Util { public class Util {
public static String Prefix = "§8[§4T2Code§7-§aAlias§8]"; private static double requiredT2CodeLibVersion = 11.0;
public static Integer SpigotID = 96389; private static String Prefix = "§8[§4T2Code§7-§aAlias§8]";
public static Integer BstatsID = 12517; private static Integer SpigotID = 96389;
public static String Spigot = "https://www.spigotmc.org/resources/" + SpigotID; private static Integer BstatsID = 12517;
public static String Discord = "http://dc.t2code.net"; private static String Spigot = "https://www.spigotmc.org/resources/" + SpigotID;
private static String Discord = "http://dc.t2code.net";
public static double getRequiredT2CodeLibVersion() {
return requiredT2CodeLibVersion;
}
public static String getPrefix() {
return Prefix;
}
public static Integer getSpigotID() {
return SpigotID;
}
public static Integer getBstatsID() {
return BstatsID;
}
public static String getSpigot() {
return Spigot;
}
public static String getDiscord() {
return Discord;
}
} }