Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
Update Zyndex to 2024.7.2 and apply new instance schemes
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldieeins committed Jul 3, 2024
1 parent 9a7fd02 commit 4f7a3e1
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 92 deletions.
8 changes: 4 additions & 4 deletions application-main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<groupId>com.zyneonstudios</groupId>
<artifactId>nexus-application</artifactId>
<version>2024.7</version>
<version>2024.7.1</version>
</parent>

<artifactId>application-main</artifactId>
<version>2024.7-beta.11</version>
<version>2024.7.1-beta.1</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand All @@ -21,8 +21,8 @@
<dependencies>
<dependency>
<groupId>com.zyneonstudios</groupId>
<artifactId>nexus-smblib</artifactId>
<version>2024.6</version>
<artifactId>nexus-zyndex</artifactId>
<version>2024.7.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.zyneonstudios.application.main.NexusApplication;
import com.zyneonstudios.application.modules.ApplicationModule;
import com.zyneonstudios.application.modules.search.ModuleSearch;
import com.zyneonstudios.nexus.modules.ReadableModule;
import live.nerotv.shademebaby.file.OnlineConfig;

import java.awt.*;
Expand All @@ -13,12 +14,11 @@
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;

public class FrameConnector {

private final ApplicationFrame frame;
private final ModuleSearch moduleSearch = new ModuleSearch("https://raw.githubusercontent.com/zyneonstudios/nexus-nex/main/zyndex/index.json");
private final ModuleSearch moduleSearch = new ModuleSearch("https://zyneonstudios.github.io/nexus-nex/zyndex/index.json");
private final NexusApplication application;

public FrameConnector(ApplicationFrame frame,NexusApplication application) {
Expand All @@ -35,12 +35,10 @@ public void resolveRequest(String request) {

if(request.startsWith("sync.")) {
sync(request.replace("sync.", ""));
NexusApplication.getLogger().debug("[CONNECTOR] successfully resolved " + request);
} else if(request.startsWith("open.")) {
open(request.replaceFirst("open.",""));
} else if(request.startsWith("init.")) {
init(request.replace("init.", ""));
NexusApplication.getLogger().debug("[CONNECTOR] successfully resolved " + request);
}
for(ApplicationModule module:NexusApplication.getModuleLoader().getApplicationModules()) {
module.getConnector().resolveFrameRequest(request);
Expand Down Expand Up @@ -204,8 +202,12 @@ private void syncDiscover(String request) {
} else {
query = "";
}
ArrayList<HashMap<String,String>> results = null;
if(moduleSearch.getCachedResults()==null||!moduleSearch.getCachedSearchTerm().equals(query)) {
ArrayList<ReadableModule> results = null;
String searchTerm = "";
if(moduleSearch.getCachedSearchTerm()!=null) {
searchTerm = moduleSearch.getCachedSearchTerm();
}
if(moduleSearch.getCachedResults()==null||!searchTerm.equals(query)) {
results = moduleSearch.search(query);
}
if(moduleSearch.getCachedSearchTerm()!=null) {
Expand All @@ -216,17 +218,17 @@ private void syncDiscover(String request) {
if(results == null) {
results = moduleSearch.search(query);
}
for(HashMap<String,String> result : results) {
String tags = "Tags: "+result.get("meta.tags").replace("[\"","").replace("\"]","").replace("\"","").replace(",",", ");
String meta = result.get("meta.id")+" | v"+result.get("info.version")+" | Hidden: "+result.get("meta.isHidden")+"<br>"+tags;
String location = URLEncoder.encode(result.get("meta.location"),StandardCharsets.UTF_8);
for(ReadableModule module : results) {
String tags = "Tags: "+module.getTagString();
String meta = module.getId()+" | v"+module.getVersion()+" | Hidden: "+module.isHidden()+"<br>"+tags;
String location = module.getLocation();
String actions = "<a onclick=\\\"connector('sync.discover.details.module."+location+"');\\\"><i class='bx bx-spreadsheet'></i> More</a> ";
if(NexusApplication.getModuleLoader().getModuleIds().contains(result.get("meta.id"))) {
actions = "v"+NexusApplication.getModuleLoader().getModules().get(result.get("meta.id")).getVersion()+" <a onclick=\\\"connector('sync.discover.details.module."+location+"');\\\"><i class='bx bx-spreadsheet'></i> More</a> <a style=\\\"background: #473e5c !important; color: white!important; cursor: not-allowed !important; box-shadow: 0 0 0.2rem var(--shadow3) !important;\\\"><i class='bx bx-check'></i> Installed</a>";
if(NexusApplication.getModuleLoader().getModuleIds().contains(module.getId())) {
actions = "v"+NexusApplication.getModuleLoader().getModules().get(module.getId()).getVersion()+" <a onclick=\\\"connector('sync.discover.details.module."+location+"');\\\"><i class='bx bx-spreadsheet'></i> More</a> <a style=\\\"background: #473e5c !important; color: white!important; cursor: not-allowed !important; box-shadow: 0 0 0.2rem var(--shadow3) !important;\\\"><i class='bx bx-check'></i> Installed</a>";
} else {
actions = actions+"<a style=\\\"background: #5632a8; color: white;\\\" onclick=\\\"connector('sync.discover.install.module.nexus-minecraft-module');\\\"><i class='bx bx-download'></i> Install</a>";
}
String command = "addResult(\""+result.get("meta.id")+"\",\""+result.get("resources.thumbnail")+"\",\""+result.get("info.name")+"\",\""+result.get("info.authors")+"\",\""+formatForDetails(result.get("info.summary"))+"\",\""+meta+"\",\""+actions+"\",\""+location+"\");";
String command = "addResult(\""+module.getId()+"\",\""+module.getThumbnailUrl()+"\",\""+module.getName()+"\",\""+module.getAuthor()+"\",\""+formatForDetails(module.getSummary())+"\",\""+meta+"\",\""+actions+"\",\""+location+"\");";
frame.executeJavaScript(command);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,108 +1,67 @@
package com.zyneonstudios.application.modules.search;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import live.nerotv.shademebaby.utils.GsonUtil;
import com.zyneonstudios.nexus.index.ReadableZyndex;
import com.zyneonstudios.nexus.modules.ReadableModule;

import java.util.ArrayList;
import java.util.HashMap;

public class ModuleSearch {

private final JsonArray array;
private ArrayList<HashMap<String,String>> cachedResults = null;
private final ArrayList<ReadableModule> modules;
private ArrayList<ReadableModule> cachedResults = null;
private String cachedSearchTerm = null;
private final boolean officialSource;

public ModuleSearch(String zyndexUrl) {
array = GsonUtil.getObject(zyndexUrl).getAsJsonArray("modules");
officialSource = zyndexUrl.equals("https://raw.githubusercontent.com/zyneonstudios/nexus-nex/main/zyndex/index.json");
modules = new ReadableZyndex(zyndexUrl).getModules();
officialSource = isOfficial(zyndexUrl);
}

private boolean isOfficial(String url) {
ArrayList<String> officialUrls = new ArrayList<>();
officialUrls.add("https://raw.githubusercontent.com/zyneonstudios/nexus-nex/main/zyndex/index.json");
officialUrls.add("https://zyneonstudios.github.io/nexus-nex/main/zyndex/index.json");
officialUrls.add("https://raw.githubusercontent.com/zyneonstudios/nexus-nex/main/zyndex/index");
officialUrls.add("https://zyneonstudios.github.io/nexus-nex/main/zyndex/index");
officialUrls.add("https://raw.githubusercontent.com/zyneonstudios/nexus-nex/main/zyndex/");
officialUrls.add("https://zyneonstudios.github.io/nexus-nex/main/zyndex/");
officialUrls.add("https://raw.githubusercontent.com/zyneonstudios/nexus-nex/main/zyndex");
officialUrls.add("https://zyneonstudios.github.io/nexus-nex/main/zyndex");
return officialUrls.contains(url.toLowerCase());
}

@SuppressWarnings("all")
public ArrayList<HashMap<String, String>> search(String searchTerm) {
public ArrayList<ReadableModule> search(String searchTerm) {
if(!searchTerm.replace(" ","").isEmpty()) {
cachedSearchTerm = searchTerm;
}

ArrayList<HashMap<String, String>> results = new ArrayList<>();
ArrayList<ReadableModule> results = new ArrayList<>();
String[] searchTerms = searchTerm.toLowerCase().replace(" ",",").replace(",,",",").split(",");

if(!array.isEmpty()) {
for(JsonElement element:array) {
JsonObject result = GsonUtil.getObject(element.getAsString()).getAsJsonObject("module");

JsonObject info = result.getAsJsonObject("info");
String name = info.get("name").getAsString();

JsonObject meta = result.getAsJsonObject("meta");
String id = meta.get("id").getAsString();

if(!modules.isEmpty()) {
for(ReadableModule module : modules) {
boolean idMatching = false;
for(String s:searchTerms) {
if (id.equalsIgnoreCase(s)) {
if (module.getId().equalsIgnoreCase(s)) {
idMatching = true;
break;
}
}

if(name.toLowerCase().contains(searchTerm)||idMatching) {
JsonObject resources = result.getAsJsonObject("resources");
HashMap<String,String> module = new HashMap<>();

module.put("info.authors",info.get("authors").getAsString().replace("\"","''"));
module.put("info.summary",info.get("summary").getAsString().replace("\\n","<br>").replace("\n","<br>").replace("\"","''"));
module.put("info.name",info.get("name").getAsString().replace("\"","''"));
module.put("info.version",info.get("version").getAsString().replace("\"","''"));

module.put("meta.download",meta.get("download").getAsString());
if(meta.get("description")!=null) {
module.put("meta.description", meta.get("description").getAsString().replace("\"","''"));
} else {
module.put("meta.description", info.get("summary").getAsString().replace("\\n","<br>").replace("\n","<br>").replace("\"","''"));
}
module.put("meta.id",id);
module.put("meta.isHidden",meta.get("isHidden").getAsString());
module.put("meta.isOfficial",officialSource+"");
module.put("meta.location",meta.get("location").getAsString());
module.put("meta.origin",meta.get("origin").getAsString());
module.put("meta.tags",meta.get("tags").toString());

if(resources.get("thumbnail")!=null) {
module.put("resources.thumbnail",resources.get("thumbnail").getAsString());
} else {
module.put("resources.thumbnail","");
}

if(resources.get("logo")!=null) {
module.put("resources.logo",resources.get("logo").getAsString());
} else {
module.put("resources.logo","");
}

if(resources.get("icon")!=null) {
module.put("resources.icon",resources.get("icon").getAsString());
} else {
module.put("resources.icon","");
}

if(resources.get("background")!=null) {
module.put("resources.background",resources.get("background").getAsString());
} else {
module.put("resources.background","");
if(module.getName().toLowerCase().contains(searchTerm.toLowerCase())||idMatching) {
if(!module.isHidden()||idMatching) {
results.add(module);
}

results.add(module);
}
}
};
}

cachedResults = results;
return cachedResults;
}

public ArrayList<HashMap<String, String>> getCachedResults() {
public ArrayList<ReadableModule> getCachedResults() {
return cachedResults;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ function initDiscover() {
if(urlParams.get("moduleId")!==null||localStorage.getItem("settings.lastSearchModule")!==null) {
if(urlParams.get("moduleId")!==null) {
moduleId = urlParams.get('moduleId');
if(moduleId==="modules") {
moduleId = "-1";
}
localStorage.setItem("settings.lastSearchModule",moduleId);
} else {
moduleId = localStorage.getItem("settings.lastSearchModule");
Expand Down Expand Up @@ -144,9 +147,7 @@ addEventListener("DOMContentLoaded", () => {
document.getElementById("search-bar").addEventListener('keydown', function(event) {
if (event.keyCode === 13) {
const value = document.getElementById("search-bar").value;
if(value) {
location.href = "discover.html?moduleId="+moduleId+"&l=search&s="+encodeURIComponent(value);
}
location.href = "discover.html?moduleId="+moduleId+"&l=search&s="+encodeURIComponent(value);
}
});
});
2 changes: 1 addition & 1 deletion bootstrapper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.zyneonstudios</groupId>
<artifactId>nexus-application</artifactId>
<version>2024.7</version>
<version>2024.7.1</version>
</parent>

<artifactId>bootstrapper</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.zyneonstudios</groupId>
<artifactId>nexus-application</artifactId>
<version>2024.7</version>
<version>2024.7.1</version>
<packaging>pom</packaging>

<repositories>
Expand Down

0 comments on commit 4f7a3e1

Please sign in to comment.