Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-26 00:00:28 +01:00
Add new /viaversion dontbugme, change method if the version looks like it's custom / debug (not compiled by maven)
Dieser Commit ist enthalten in:
Ursprung
eccc5091b5
Commit
30c4fea044
@ -6,7 +6,6 @@ import io.netty.channel.ChannelHandler;
|
|||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
@ -16,7 +15,6 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.ViaVersion;
|
import us.myles.ViaVersion.api.ViaVersion;
|
||||||
import us.myles.ViaVersion.api.ViaVersionAPI;
|
import us.myles.ViaVersion.api.ViaVersionAPI;
|
||||||
import us.myles.ViaVersion.armor.ArmorListener;
|
import us.myles.ViaVersion.armor.ArmorListener;
|
||||||
@ -62,18 +60,18 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.config = getFileConfiguration();
|
this.config = getFileConfiguration();
|
||||||
if(!config.contains("checkforupdates")) {
|
if (!config.contains("checkforupdates")) {
|
||||||
config.set("checkforupdates", true);
|
config.set("checkforupdates", true);
|
||||||
try {
|
try {
|
||||||
config.save(configFile);
|
config.save(configFile);
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
this.getLogger().info("Unabled to write config.yml!");
|
this.getLogger().info("Unabled to write config.yml!");
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(config.getBoolean("checkforupdates")) {
|
if (config.getBoolean("checkforupdates")) {
|
||||||
Bukkit.getPluginManager().registerEvents(new UpdateListener(this), this);
|
Bukkit.getPluginManager().registerEvents(new UpdateListener(this), this);
|
||||||
UpdateUtil.sendUpdateMessage(this);
|
UpdateUtil.sendUpdateMessage(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getPluginManager().registerEvents(new Listener() {
|
Bukkit.getPluginManager().registerEvents(new Listener() {
|
||||||
@ -153,17 +151,17 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private FileConfiguration getFileConfiguration() {
|
private FileConfiguration getFileConfiguration() {
|
||||||
if(!this.getDataFolder().exists())
|
if (!this.getDataFolder().exists())
|
||||||
this.getDataFolder().mkdirs();
|
this.getDataFolder().mkdirs();
|
||||||
this.configFile = new File(this.getDataFolder(), "config.yml");
|
this.configFile = new File(this.getDataFolder(), "config.yml");
|
||||||
if(!this.configFile.exists())
|
if (!this.configFile.exists())
|
||||||
try {
|
try {
|
||||||
this.configFile.createNewFile();
|
this.configFile.createNewFile();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
this.getLogger().info("Unable to create config.yml!");
|
this.getLogger().info("Unable to create config.yml!");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return YamlConfiguration.loadConfiguration(this.configFile);
|
return YamlConfiguration.loadConfiguration(this.configFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack getHandItem(final ConnectionInfo info) {
|
public static ItemStack getHandItem(final ConnectionInfo info) {
|
||||||
|
@ -28,6 +28,7 @@ public class ViaVersionCommand implements CommandExecutor {
|
|||||||
sender.sendMessage(color("&aViaVersion &c" + ViaVersion.getInstance().getVersion()));
|
sender.sendMessage(color("&aViaVersion &c" + ViaVersion.getInstance().getVersion()));
|
||||||
sender.sendMessage(color("&6Commands:"));
|
sender.sendMessage(color("&6Commands:"));
|
||||||
sender.sendMessage(color("&2/viaversion list &7- &6Shows lists of all 1.9 clients and 1.8 clients."));
|
sender.sendMessage(color("&2/viaversion list &7- &6Shows lists of all 1.9 clients and 1.8 clients."));
|
||||||
|
sender.sendMessage(color("&2/viaversion dontbugme &7- &6Toggle checking for updates."));
|
||||||
} else if (args.length == 1) {
|
} else if (args.length == 1) {
|
||||||
if (args[0].equalsIgnoreCase("list")) {
|
if (args[0].equalsIgnoreCase("list")) {
|
||||||
List<String> portedPlayers = new ArrayList<String>();
|
List<String> portedPlayers = new ArrayList<String>();
|
||||||
@ -47,6 +48,12 @@ public class ViaVersionCommand implements CommandExecutor {
|
|||||||
plugin.setDebug(!plugin.isDebug());
|
plugin.setDebug(!plugin.isDebug());
|
||||||
sender.sendMessage(color("&6Debug mode is now " + (plugin.isDebug() ? "&aenabled" : "&cdisabled")));
|
sender.sendMessage(color("&6Debug mode is now " + (plugin.isDebug() ? "&aenabled" : "&cdisabled")));
|
||||||
}
|
}
|
||||||
|
if (args[0].equalsIgnoreCase("dontbugme")) {
|
||||||
|
boolean newValue = !plugin.getConfig().getBoolean("checkforupdates", true);
|
||||||
|
plugin.getConfig().set("checkforupdates", newValue);
|
||||||
|
plugin.saveConfig();
|
||||||
|
sender.sendMessage(color("&6We will " + (newValue ? "&anotify you about updates." : "&cnot tell you about updates.")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,10 @@ public class UpdateListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onJoin(PlayerJoinEvent e) {
|
public void onJoin(PlayerJoinEvent e) {
|
||||||
if(e.getPlayer().hasPermission("viaversion.update"))
|
if(e.getPlayer().hasPermission("viaversion.update")
|
||||||
|
&& plugin.getConfig().getBoolean("checkforupdates", true)) {
|
||||||
UpdateUtil.sendUpdateMessage(e.getPlayer().getUniqueId(), plugin);
|
UpdateUtil.sendUpdateMessage(e.getPlayer().getUniqueId(), plugin);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package us.myles.ViaVersion.update;
|
package us.myles.ViaVersion.update;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import us.myles.ViaVersion.api.ViaVersion;
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -17,79 +17,81 @@ import java.net.MalformedURLException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.ViaVersion;
|
|
||||||
|
|
||||||
public class UpdateUtil {
|
public class UpdateUtil {
|
||||||
|
|
||||||
private final static String URL = "https://api.spiget.org/v1/resources/";
|
private final static String URL = "https://api.spiget.org/v1/resources/";
|
||||||
private final static int PLUGIN = 19254;
|
private final static int PLUGIN = 19254;
|
||||||
|
|
||||||
public final static String PREFIX = ChatColor.GREEN + "" + ChatColor.BOLD + "[ViaVersion] " + ChatColor.GREEN;
|
public final static String PREFIX = ChatColor.GREEN + "" + ChatColor.BOLD + "[ViaVersion] " + ChatColor.GREEN;
|
||||||
|
|
||||||
public static void sendUpdateMessage(final UUID uuid, final Plugin plugin) {
|
public static void sendUpdateMessage(final UUID uuid, final Plugin plugin) {
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final String message = getUpdateMessage(false);
|
final String message = getUpdateMessage(false);
|
||||||
if(message != null) {
|
if (message != null) {
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Player p = Bukkit.getPlayer(uuid);
|
Player p = Bukkit.getPlayer(uuid);
|
||||||
if(p != null)
|
if (p != null) {
|
||||||
p.sendMessage(PREFIX + message);
|
p.sendMessage(PREFIX + message);
|
||||||
}
|
}
|
||||||
}.runTask(plugin);
|
}
|
||||||
}
|
}.runTask(plugin);
|
||||||
}
|
}
|
||||||
}.runTaskAsynchronously(plugin);
|
}
|
||||||
}
|
}.runTaskAsynchronously(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
public static void sendUpdateMessage(final Plugin plugin) {
|
public static void sendUpdateMessage(final Plugin plugin) {
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final String message = getUpdateMessage(true);
|
final String message = getUpdateMessage(true);
|
||||||
if(message != null) {
|
if (message != null) {
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Bukkit.getLogger().info(PREFIX + message);
|
Bukkit.getLogger().info(PREFIX + message);
|
||||||
}
|
}
|
||||||
}.runTask(plugin);
|
}.runTask(plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.runTaskAsynchronously(plugin);
|
}.runTaskAsynchronously(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getUpdateMessage(boolean console) {
|
private static String getUpdateMessage(boolean console) {
|
||||||
Version current = new Version(ViaVersion.getInstance().getVersion());
|
if (ViaVersion.getInstance().getVersion().equals("${project.version}")) {
|
||||||
Version newest = new Version(getNewestVersion());
|
return "You are using a debug/custom version, consider updating.";
|
||||||
if(current.compareTo(newest) < 0)
|
}
|
||||||
return "There is a newer version available: " + newest.toString();
|
|
||||||
else if(console) {
|
|
||||||
if(current.compareTo(newest) == 0)
|
|
||||||
return "You are running the newest version: " + current;
|
|
||||||
else
|
|
||||||
return "You are running a newer version than is released!";
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getNewestVersion()
|
Version current = new Version(ViaVersion.getInstance().getVersion());
|
||||||
{
|
Version newest = new Version(getNewestVersion());
|
||||||
String result = "";
|
if (current.compareTo(newest) < 0)
|
||||||
try {
|
return "There is a newer version available: " + newest.toString();
|
||||||
URL url = new URL(URL + PLUGIN);
|
else if (console) {
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
if (current.compareTo(newest) == 0)
|
||||||
connection.setUseCaches(true);
|
return "You are running the newest version: " + current;
|
||||||
connection.addRequestProperty("User-Agent", "Mozilla/4.76");
|
else
|
||||||
connection.setDoOutput(true);
|
return "You are running a newer version than is released!";
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getNewestVersion() {
|
||||||
|
String result = "";
|
||||||
|
try {
|
||||||
|
URL url = new URL(URL + PLUGIN);
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setUseCaches(true);
|
||||||
|
connection.addRequestProperty("User-Agent", "Mozilla/4.76");
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
String input;
|
String input;
|
||||||
String content = "";
|
String content = "";
|
||||||
while ((input = br.readLine()) != null) {
|
while ((input = br.readLine()) != null) {
|
||||||
@ -97,13 +99,13 @@ public class UpdateUtil {
|
|||||||
}
|
}
|
||||||
br.close();
|
br.close();
|
||||||
JsonParser parser = new JsonParser();
|
JsonParser parser = new JsonParser();
|
||||||
JsonObject statistics = (JsonObject)parser.parse(content);
|
JsonObject statistics = (JsonObject) parser.parse(content);
|
||||||
result = statistics.get("version").getAsString();
|
result = statistics.get("version").getAsString();
|
||||||
} catch(MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
package us.myles.ViaVersion.update;
|
package us.myles.ViaVersion.update;
|
||||||
|
|
||||||
public class Version implements Comparable<Version>
|
import org.apache.commons.lang.StringUtils;
|
||||||
{
|
|
||||||
|
public class Version implements Comparable<Version> {
|
||||||
private int[] parts;
|
private int[] parts;
|
||||||
|
|
||||||
public Version(String value)
|
public Version(String value) {
|
||||||
{
|
if (value == null)
|
||||||
if(value == null)
|
|
||||||
throw new IllegalArgumentException("Version can not be null");
|
throw new IllegalArgumentException("Version can not be null");
|
||||||
|
|
||||||
if(value.matches("^[0-9]+(\\.[0-9]+)*$") == false)
|
if (value.matches("^[0-9]+(\\.[0-9]+)*$") == false)
|
||||||
throw new IllegalArgumentException("Invalid version format");
|
throw new IllegalArgumentException("Invalid version format");
|
||||||
|
|
||||||
String[] split = value.split("\\.");
|
String[] split = value.split("\\.");
|
||||||
@ -20,26 +20,23 @@ public class Version implements Comparable<Version>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
String[] split = new String[parts.length];
|
String[] split = new String[parts.length];
|
||||||
|
|
||||||
for (int i = 0; i < parts.length; i += 1)
|
for (int i = 0; i < parts.length; i += 1)
|
||||||
split[i] = String.valueOf(parts[i]);
|
split[i] = String.valueOf(parts[i]);
|
||||||
|
|
||||||
return String.join(".", split);
|
return StringUtils.join(split, ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int compare(Version verA, Version verB)
|
public static int compare(Version verA, Version verB) {
|
||||||
{
|
|
||||||
if (verA == verB) return 0;
|
if (verA == verB) return 0;
|
||||||
if (verA == null) return -1;
|
if (verA == null) return -1;
|
||||||
if (verB == null) return 1;
|
if (verB == null) return 1;
|
||||||
|
|
||||||
int max = Math.max(verA.parts.length, verB.parts.length);
|
int max = Math.max(verA.parts.length, verB.parts.length);
|
||||||
|
|
||||||
for (int i = 0; i < max; i += 1)
|
for (int i = 0; i < max; i += 1) {
|
||||||
{
|
|
||||||
int partA = i < verA.parts.length ? verA.parts[i] : 0;
|
int partA = i < verA.parts.length ? verA.parts[i] : 0;
|
||||||
int partB = i < verB.parts.length ? verB.parts[i] : 0;
|
int partB = i < verB.parts.length ? verB.parts[i] : 0;
|
||||||
if (partA < partB) return -1;
|
if (partA < partB) return -1;
|
||||||
@ -50,13 +47,11 @@ public class Version implements Comparable<Version>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Version that)
|
public int compareTo(Version that) {
|
||||||
{
|
|
||||||
return compare(this, that);
|
return compare(this, that);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean equals(Version verA, Version verB)
|
public static boolean equals(Version verA, Version verB) {
|
||||||
{
|
|
||||||
if (verA == verB) return true;
|
if (verA == verB) return true;
|
||||||
if (verA == null) return false;
|
if (verA == null) return false;
|
||||||
if (verB == null) return false;
|
if (verB == null) return false;
|
||||||
@ -64,8 +59,7 @@ public class Version implements Comparable<Version>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object that)
|
public boolean equals(Object that) {
|
||||||
{
|
return that instanceof Version && equals(this, (Version) that);
|
||||||
return that instanceof Version && equals(this, (Version)that);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren