This commit is contained in:
parent
536cb90868
commit
1ff00557bb
3 changed files with 26 additions and 3 deletions
2
pom.xml
2
pom.xml
|
@ -108,7 +108,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.21.5-R0.1-SNAPSHOT</version>
|
<version>1.21.4-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -14,7 +14,6 @@ import tech.sbdevelopment.themeparkaudio.managers.PinManager;
|
||||||
import tech.sbdevelopment.themeparkaudio.managers.WGManager;
|
import tech.sbdevelopment.themeparkaudio.managers.WGManager;
|
||||||
import tech.sbdevelopment.themeparkaudio.socket.messages.AudioMessage;
|
import tech.sbdevelopment.themeparkaudio.socket.messages.AudioMessage;
|
||||||
import tech.sbdevelopment.themeparkaudio.socket.messages.LightMessage;
|
import tech.sbdevelopment.themeparkaudio.socket.messages.LightMessage;
|
||||||
import tech.sbdevelopment.themeparkaudio.socket.messages.StopAudioMessage;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
package tech.sbdevelopment.themeparkaudio.socket.messages;
|
package tech.sbdevelopment.themeparkaudio.socket.messages;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import tech.sbdevelopment.themeparkaudio.ThemeParkAudio;
|
||||||
import tech.sbdevelopment.themeparkaudio.api.AudioType;
|
import tech.sbdevelopment.themeparkaudio.api.AudioType;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class AudioMessage extends AbstractMessage {
|
public class AudioMessage extends AbstractMessage {
|
||||||
private final String path;
|
private final String path;
|
||||||
|
@ -12,7 +19,7 @@ public class AudioMessage extends AbstractMessage {
|
||||||
|
|
||||||
protected AudioMessage(AudioType type, String path, Boolean play, Integer at) {
|
protected AudioMessage(AudioType type, String path, Boolean play, Integer at) {
|
||||||
super(type.toMessageTask());
|
super(type.toMessageTask());
|
||||||
this.path = path;
|
this.path = parsePath(path);
|
||||||
this.play = play;
|
this.play = play;
|
||||||
this.at = at;
|
this.at = at;
|
||||||
}
|
}
|
||||||
|
@ -29,6 +36,23 @@ public class AudioMessage extends AbstractMessage {
|
||||||
return new AudioMessage(type, path, play, at);
|
return new AudioMessage(type, path, play, at);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String parsePath(String path) {
|
||||||
|
if (path.startsWith("https://mcau.nl")) {
|
||||||
|
try {
|
||||||
|
HttpsURLConnection connection = (HttpsURLConnection) new URI(path).toURL().openConnection();
|
||||||
|
connection.setInstanceFollowRedirects(false);
|
||||||
|
connection.connect();
|
||||||
|
if (connection.getResponseCode() == HttpURLConnection.HTTP_MOVED_PERM ||
|
||||||
|
connection.getResponseCode() == HttpURLConnection.HTTP_MOVED_TEMP) {
|
||||||
|
path = connection.getHeaderField("Location");
|
||||||
|
}
|
||||||
|
} catch (URISyntaxException | IOException e) {
|
||||||
|
ThemeParkAudio.getInstance().getLogger().warning("Failed to resolve URL: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JSONObject extendJson() {
|
protected JSONObject extendJson() {
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
|
|
Loading…
Add table
Reference in a new issue