Move UriScheme to extras module
This commit is contained in:
@@ -3,17 +3,14 @@ package com.replaymod.core;
|
||||
import com.google.common.util.concurrent.ListenableFutureTask;
|
||||
import com.replaymod.replay.ReplaySender;
|
||||
import eu.crushedpixel.replaymod.api.ApiClient;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.FileInfo;
|
||||
import eu.crushedpixel.replaymod.chat.ChatMessageHandler;
|
||||
import eu.crushedpixel.replaymod.events.handlers.CrosshairRenderHandler;
|
||||
import eu.crushedpixel.replaymod.events.handlers.GuiEventHandler;
|
||||
import eu.crushedpixel.replaymod.events.handlers.MouseInputHandler;
|
||||
import eu.crushedpixel.replaymod.events.handlers.TickAndRenderListener;
|
||||
import eu.crushedpixel.replaymod.events.handlers.keyboard.KeyInputHandler;
|
||||
import eu.crushedpixel.replaymod.gui.online.GuiReplayDownloading;
|
||||
import eu.crushedpixel.replaymod.localization.LocalizedResourcePack;
|
||||
import eu.crushedpixel.replaymod.online.authentication.ConfigurationAuthData;
|
||||
import eu.crushedpixel.replaymod.online.urischeme.UriScheme;
|
||||
import eu.crushedpixel.replaymod.registry.*;
|
||||
import eu.crushedpixel.replaymod.renderer.CustomObjectRenderer;
|
||||
import eu.crushedpixel.replaymod.renderer.InvisibilityRender;
|
||||
@@ -47,13 +44,9 @@ import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
@@ -156,17 +149,6 @@ public class ReplayMod {
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
try {
|
||||
UriScheme uriScheme = UriScheme.create();
|
||||
if (uriScheme == null) {
|
||||
throw new UnsupportedOperationException("OS not supported.");
|
||||
}
|
||||
uriScheme.install();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Failed to install UriScheme handler:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Initialize the static OpenGL info field from the minecraft main thread
|
||||
// Unfortunately lwjgl uses static methods so we have to make use of magic init calls as well
|
||||
OpenGLUtils.init();
|
||||
@@ -398,67 +380,13 @@ public class ReplayMod {
|
||||
|
||||
testIfMoeshAndExitMinecraft();
|
||||
}
|
||||
}
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ServerSocket serverSocket = null;
|
||||
try {
|
||||
serverSocket = new ServerSocket(UriScheme.PROCESS_PORT);
|
||||
while (!Thread.interrupted()) {
|
||||
Socket clientSocket = serverSocket.accept();
|
||||
try {
|
||||
InputStream inputStream = clientSocket.getInputStream();
|
||||
String replayId = IOUtils.toString(inputStream);
|
||||
final int id = Integer.parseInt(replayId);
|
||||
mc.addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
loadOnlineReplay(id);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(clientSocket);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(serverSocket);
|
||||
}
|
||||
}
|
||||
}, "UriSchemeHandler").start();
|
||||
|
||||
String replayId = System.getenv("replaymod.uri.replayid");
|
||||
if (replayId != null) {
|
||||
final int id = Integer.parseInt(replayId);
|
||||
public void runLater(Runnable runnable) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Queue<ListenableFutureTask> tasks = mc.scheduledTasks;
|
||||
synchronized (mc.scheduledTasks) {
|
||||
tasks.add(ListenableFutureTask.create(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
loadOnlineReplay(id);
|
||||
}
|
||||
}, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadOnlineReplay(int id) {
|
||||
File file = ReplayMod.downloadedFileHandler.getFileForID(id);
|
||||
if (file == null) {
|
||||
FileInfo info = new FileInfo(id, null, null, null, 0, 0, 0, String.valueOf(id), false, 0);
|
||||
new GuiReplayDownloading(info).display();
|
||||
} else {
|
||||
try {
|
||||
// TODO
|
||||
// ReplayHandler.startReplay(file);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
tasks.add(ListenableFutureTask.create(runnable, null));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.replaymod.extras;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.extras.playeroverview.PlayerOverview;
|
||||
import com.replaymod.extras.urischeme.UriSchemeExtra;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
@@ -22,6 +23,7 @@ public class ReplayModExtras {
|
||||
|
||||
private static final List<Class<? extends Extra>> builtin = Arrays.asList(
|
||||
PlayerOverview.class,
|
||||
UriSchemeExtra.class,
|
||||
FullBrightness.class,
|
||||
HotkeyButtons.class
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package eu.crushedpixel.replaymod.online.urischeme;
|
||||
package com.replaymod.extras.urischeme;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
@@ -1,4 +1,4 @@
|
||||
package eu.crushedpixel.replaymod.online.urischeme;
|
||||
package com.replaymod.extras.urischeme;
|
||||
|
||||
public class OSXUriScheme extends UriScheme {
|
||||
@Override
|
||||
@@ -1,4 +1,4 @@
|
||||
package eu.crushedpixel.replaymod.online.urischeme;
|
||||
package com.replaymod.extras.urischeme;
|
||||
|
||||
import net.minecraft.util.Util;
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.replaymod.extras.urischeme;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.extras.Extra;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
|
||||
public class UriSchemeExtra implements Extra {
|
||||
private ReplayMod mod;
|
||||
|
||||
@Override
|
||||
public void register(final ReplayMod mod) throws Exception {
|
||||
this.mod = mod;
|
||||
|
||||
UriScheme uriScheme = UriScheme.create();
|
||||
if (uriScheme == null) {
|
||||
throw new UnsupportedOperationException("OS not supported.");
|
||||
}
|
||||
uriScheme.install();
|
||||
|
||||
mod.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Start listening for future requests
|
||||
startListener();
|
||||
|
||||
// Handle initial request
|
||||
String replayId = System.getenv("replaymod.uri.replayid");
|
||||
if (replayId != null) {
|
||||
loadReplay(Integer.parseInt(replayId));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void startListener() {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ServerSocket serverSocket = null;
|
||||
try {
|
||||
serverSocket = new ServerSocket(UriScheme.PROCESS_PORT);
|
||||
while (!Thread.interrupted()) {
|
||||
Socket clientSocket = serverSocket.accept();
|
||||
try {
|
||||
InputStream inputStream = clientSocket.getInputStream();
|
||||
String replayId = IOUtils.toString(inputStream);
|
||||
final int id = Integer.parseInt(replayId);
|
||||
mod.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
loadReplay(id);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(clientSocket);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(serverSocket);
|
||||
}
|
||||
}
|
||||
}, "UriSchemeHandler").start();
|
||||
}
|
||||
|
||||
private void loadReplay(int id) {
|
||||
// TODO
|
||||
// File file = ReplayMod.downloadedFileHandler.getFileForID(id);
|
||||
// if (file == null) {
|
||||
// FileInfo info = new FileInfo(id, null, null, null, 0, 0, 0, String.valueOf(id), false, 0);
|
||||
// new GuiReplayDownloading(info).display();
|
||||
// } else {
|
||||
// try {
|
||||
// ReplayHandler.startReplay(file);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package eu.crushedpixel.replaymod.online.urischeme;
|
||||
package com.replaymod.extras.urischeme;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
Reference in New Issue
Block a user