fix!: remove dependance on update.songoda.com which is not available

This also gets rid of auto-download of different locale files
as the services providing them finally stopped working.
This commit is contained in:
Christian Koop 2024-07-19 17:35:36 +02:00
parent 27115b20e8
commit 54494c8ad9
No known key found for this signature in database
GPG Key ID: 6A4A09E8ED946113
3 changed files with 4 additions and 200 deletions

View File

@ -2,14 +2,11 @@ package com.craftaro.core;
import com.craftaro.core.commands.CommandManager;
import com.craftaro.core.compatibility.ClientVersion;
import com.craftaro.core.core.LocaleModule;
import com.craftaro.core.core.PluginInfo;
import com.craftaro.core.core.PluginInfoModule;
import com.craftaro.core.core.SongodaCoreCommand;
import com.craftaro.core.core.SongodaCoreDiagCommand;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
@ -20,24 +17,14 @@ import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
public class SongodaCore {
@ -230,55 +217,11 @@ public class SongodaCore {
getLogger().info(getPrefix() + "Hooked " + plugin.getName() + ".");
PluginInfo info = new PluginInfo(plugin, pluginID, icon, libraryVersion);
// don't forget to check for language pack updates ;)
info.addModule(new LocaleModule());
registeredPlugins.add(info);
this.tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> update(info), 60L));
}
/**
* @deprecated Seems useless and will probably be replaced in the near future
*/
@Deprecated
private void update(PluginInfo plugin) {
try {
URL url = new URL("https://update.songoda.com/index.php?plugin=" + plugin.getSongodaId()
+ "&version=" + plugin.getJavaPlugin().getDescription().getVersion()
+ "&updaterVersion=" + updaterVersion);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
urlConnection.setRequestProperty("Accept", "*/*");
urlConnection.setConnectTimeout(5000);
InputStream is = urlConnection.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
int numCharsRead;
char[] charArray = new char[1024];
StringBuilder sb = new StringBuilder();
while ((numCharsRead = isr.read(charArray)) > 0) {
sb.append(charArray, 0, numCharsRead);
}
urlConnection.disconnect();
String jsonString = sb.toString();
JSONObject json = (JSONObject) new JSONParser().parse(jsonString);
plugin.setLatestVersion((String) json.get("latestVersion"));
plugin.setMarketplaceLink((String) json.get("link"));
plugin.setNotification((String) json.get("notification"));
plugin.setChangeLog((String) json.get("changeLog"));
plugin.setJson(json);
for (PluginInfoModule module : plugin.getModules()) {
module.run(plugin);
}
} catch (IOException ex) {
final String er = ex.getMessage();
getLogger().log(Level.FINE, "Connection with Songoda servers failed: " + (er.contains("URL") ? er.substring(0, er.indexOf("URL") + 3) : er));
} catch (ParseException ex) {
getLogger().log(Level.FINE, "Failed to parse json for " + plugin.getJavaPlugin().getName() + " update check");
if (plugin.getDescription().getWebsite() != null && plugin.getDescription().getWebsite().contains("songoda.com/")) {
info.setMarketplaceLink(plugin.getDescription().getWebsite());
}
registeredPlugins.add(info);
}
public static List<PluginInfo> getPlugins() {
@ -391,33 +334,6 @@ public class SongodaCore {
}
private class EventListener implements Listener {
final HashMap<UUID, Long> lastCheck = new HashMap<>();
@EventHandler
void onLogin(PlayerLoginEvent event) {
final Player player = event.getPlayer();
// don't spam players with update checks
long now = System.currentTimeMillis();
Long last = this.lastCheck.get(player.getUniqueId());
if (last != null && now - 10000 < last) {
return;
}
this.lastCheck.put(player.getUniqueId(), now);
// is this player good to revieve update notices?
if (!event.getPlayer().isOp() && !player.hasPermission("songoda.updatecheck")) return;
// check for updates! ;)
for (PluginInfo plugin : getPlugins()) {
if (plugin.getNotification() != null && plugin.getJavaPlugin().isEnabled())
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin.getJavaPlugin(), () ->
player.sendMessage("[" + plugin.getJavaPlugin().getName() + "] " + plugin.getNotification()), 10L);
}
}
@EventHandler
void onDisable(PluginDisableEvent event) {
// don't track disabled plugins

View File

@ -1,64 +0,0 @@
package com.craftaro.core.core;
import com.craftaro.core.locale.Locale;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
public class LocaleModule implements PluginInfoModule {
@Override
public void run(PluginInfo plugin) {
if (plugin.getJavaPlugin() == null || plugin.getSongodaId() <= 0) {
return;
}
try {
JSONObject json = plugin.getJson();
JSONArray files = (JSONArray) json.get("neededFiles");
for (Object o : files) {
JSONObject file = (JSONObject) o;
if (file.get("type").equals("locale")) {
downloadLocale(plugin, (String) file.get("link"), (String) file.get("name"));
}
}
} catch (IOException ex) {
Logger.getLogger(LocaleModule.class.getName()).log(Level.INFO, "Failed to check for locale files: " + ex.getMessage());
}
}
void downloadLocale(PluginInfo plugin, String link, String fileName) throws IOException {
URL url = new URL(link);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
urlConnection.setRequestProperty("Accept", "*/*");
urlConnection.setInstanceFollowRedirects(true);
urlConnection.setConnectTimeout(5000);
// do we need to follow a redirect?
int status = urlConnection.getResponseCode();
if (status == HttpURLConnection.HTTP_MOVED_TEMP || status == HttpURLConnection.HTTP_MOVED_PERM || status == HttpURLConnection.HTTP_SEE_OTHER) {
// get redirect url from "location" header field
String newUrl = urlConnection.getHeaderField("Location");
// get the cookie if needed
String cookies = urlConnection.getHeaderField("Set-Cookie");
// open the new connnection again
urlConnection = (HttpURLConnection) new URL(newUrl).openConnection();
urlConnection.setRequestProperty("Cookie", cookies);
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
urlConnection.setRequestProperty("Accept", "*/*");
urlConnection.setConnectTimeout(5000);
}
Locale.saveLocale(plugin.getJavaPlugin(), urlConnection.getInputStream(), fileName);
urlConnection.disconnect();
}
}

View File

@ -4,7 +4,6 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.dependency.DependencyLoader;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.plugin.java.JavaPlugin;
import org.json.simple.JSONObject;
import java.util.ArrayList;
import java.util.Collections;
@ -18,12 +17,7 @@ public final class PluginInfo {
private final String coreLibraryVersion;
private final List<PluginInfoModule> modules = new ArrayList<>();
private boolean hasUpdate = false;
private String latestVersion;
private String notification;
private String changeLog;
private String marketplaceLink;
private JSONObject json;
public PluginInfo(JavaPlugin javaPlugin, int songodaId, String icon, String coreLibraryVersion) {
this.javaPlugin = javaPlugin;
@ -33,40 +27,6 @@ public final class PluginInfo {
this.coreLibraryVersion = coreLibraryVersion;
}
public String getLatestVersion() {
return this.latestVersion;
}
public void setLatestVersion(String latestVersion) {
this.latestVersion = latestVersion;
this.hasUpdate = latestVersion != null && !latestVersion.isEmpty() && !this.javaPlugin.getDescription().getVersion().equalsIgnoreCase(latestVersion);
}
public String getNotification() {
return this.notification;
}
public void setNotification(String notification) {
this.notification = notification;
}
public boolean hasUpdate() {
return this.hasUpdate;
}
public void setHasUpdate(boolean hasUpdate) {
this.hasUpdate = hasUpdate;
}
public String getChangeLog() {
return this.changeLog;
}
public void setChangeLog(String changeLog) {
this.changeLog = changeLog;
}
public String getMarketplaceLink() {
return this.marketplaceLink;
}
@ -75,14 +35,6 @@ public final class PluginInfo {
this.marketplaceLink = marketplaceLink;
}
public JSONObject getJson() {
return this.json;
}
public void setJson(JSONObject json) {
this.json = json;
}
public PluginInfoModule addModule(PluginInfoModule module) {
this.modules.add(module);