mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-12 14:49:56 +01:00
UrlParser
This commit is contained in:
parent
c4a55c6f8c
commit
db2577e304
@ -8,6 +8,7 @@ import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.systems.cache.DataCache;
|
||||
import main.java.com.djrapitops.plan.systems.cache.SessionCache;
|
||||
import main.java.com.djrapitops.plan.systems.info.parsing.UrlParser;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -24,19 +25,20 @@ public class InformationManager {
|
||||
private final DataCache dataCache;
|
||||
private final SessionCache sessionCache;
|
||||
|
||||
private String bungeeWebAddress;
|
||||
private boolean usingBungeeWebServer;
|
||||
private String webServerAddress;
|
||||
|
||||
public InformationManager(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
db = plugin.getDB();
|
||||
|
||||
plugin.getServerInfoManager().getBungeeConnectionAddress()
|
||||
.ifPresent(address -> bungeeWebAddress = address);
|
||||
.ifPresent(address -> webServerAddress = address);
|
||||
|
||||
dataCache = new DataCache(plugin);
|
||||
sessionCache = new SessionCache(plugin);
|
||||
|
||||
if (bungeeWebAddress != null) {
|
||||
if (webServerAddress != null) {
|
||||
attemptBungeeConnection();
|
||||
}
|
||||
}
|
||||
@ -50,4 +52,23 @@ public class InformationManager {
|
||||
// TODO Player page plugin tab request
|
||||
}
|
||||
|
||||
public UrlParser getLinkTo(String target) {
|
||||
if (webServerAddress != null) {
|
||||
return new UrlParser(webServerAddress).target(target);
|
||||
} else {
|
||||
return new UrlParser("");
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshAnalysis() {
|
||||
plugin.addToProcessQueue(); // TODO Analysis, PluginData
|
||||
}
|
||||
|
||||
public DataCache getDataCache() {
|
||||
return dataCache;
|
||||
}
|
||||
|
||||
public SessionCache getSessionCache() {
|
||||
return sessionCache;
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.systems.info.parsing;
|
||||
|
||||
/**
|
||||
* Used for parsing URL strings.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class UrlParser {
|
||||
|
||||
private final String webServerAddress;
|
||||
private StringBuilder url;
|
||||
|
||||
public UrlParser(String address) {
|
||||
webServerAddress = address;
|
||||
url = new StringBuilder();
|
||||
}
|
||||
|
||||
public UrlParser relativeProtocol() {
|
||||
url.append("//");
|
||||
return this;
|
||||
}
|
||||
|
||||
public UrlParser httpProtocol() {
|
||||
if (url.length() == 0) {
|
||||
url.append("http://");
|
||||
} else {
|
||||
String current = url.toString();
|
||||
url = new StringBuilder("./");
|
||||
url.append(current.substring(current.indexOf("/")));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public UrlParser httpsProtocol() {
|
||||
if (url.length() == 0) {
|
||||
url.append("https://");
|
||||
} else {
|
||||
String current = url.toString();
|
||||
url = new StringBuilder("./");
|
||||
url.append(current.substring(current.indexOf("/")));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public UrlParser relative() {
|
||||
if (url.length() == 0) {
|
||||
url.append("./");
|
||||
} else {
|
||||
String current = url.toString();
|
||||
url = new StringBuilder("./");
|
||||
url.append(current.substring(current.indexOf("/")));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public UrlParser webAddress() {
|
||||
url.append(webServerAddress);
|
||||
return this;
|
||||
}
|
||||
|
||||
public UrlParser target(String target) {
|
||||
if (!target.startsWith("/") && url.charAt(url.length() - 1) != '/') {
|
||||
url.append("/");
|
||||
}
|
||||
url.append(target);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return url.toString();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user