Files
ReplayModCinematic/src/main/java/com/replaymod/online/ReplayModOnline.java
Jonas Herzig 6c8c779983 Merge branch '1.8.9' into 1.9.4
ed56673 Merge branch '1.8' into 1.8.9
91573d9 Update jGui, ReplayStudio and Translations
d71358b Add confirmation dialog before overwriting path presets (fixes #65)
1a55983 Move addCallback method from integration test Utils to main Utils
18c5bcd Be more cooperative with other mods on the ingame menu (fixes #42)
c054fe8 Register keys for simplepathing only once (fixes #63)
f13297c Fix default interpolator handling in keyframe gui and after loading (fixes #64)
391f304 Show error popup if entity tracker fails to load
0e0eaaa Fix entity tracker being set even if it failed loading (fixes #50)
a34bbbc Fix NPE when spectating a player without a camera entity
60879fb Change local class to be an inner class because Srg2Source breaks with it
dfafbec Load translations from github repo, only reload language not all resource packs
8a6ec51 Add missing tooltips to player overview and various missing chat messages
5677fc5 Re-add warning to replay editor
748a91e Fix missing tooltips on fav/like/dislike buttons in replay center
ee24866 Fix upload replay button not being updated when name/tags change
dba085c Move translations into separate repo
3f0e3e7 Fix NPE when receiving Replay|Restrict messages (fixes #16 GH)
40e1d85 Fix crash when saving the last keyframe in the edit gui (fixes #61)
03aada1 Update Mixin to 0.6.8 (fixes #9 GH)
0c1dc65 Fix interpolator being lost when moving keyframe to the end (fixes #62)
fcbbbc9 Add integration test. Run with ./gradlew runIntegrationTest
fe6ded0 Fix movement of keyframe via GuiEditKeyframe not updating selected keyframe
f58fa8f Fix Login GUI not respecting other GUIs opened on startup
4fc3a31 Fix OpenEye being installed into working dir instead of mcDataDir
2017-05-31 20:49:04 +02:00

144 lines
4.9 KiB
Java

package com.replaymod.online;
import com.replaymod.core.ReplayMod;
import com.replaymod.online.api.ApiClient;
import com.replaymod.online.gui.GuiLoginPrompt;
import com.replaymod.online.gui.GuiReplayDownloading;
import com.replaymod.online.gui.GuiSaveModifiedReplay;
import com.replaymod.online.handler.GuiHandler;
import com.replaymod.replay.ReplayModReplay;
import com.replaymod.replay.events.ReplayCloseEvent;
import com.replaymod.replaystudio.replay.ReplayFile;
import com.replaymod.replaystudio.replay.ZipReplayFile;
import com.replaymod.replaystudio.studio.ReplayStudio;
import de.johni0702.minecraft.gui.container.GuiScreen;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.apache.logging.log4j.Logger;
import java.io.File;
import java.io.IOException;
import static net.minecraft.client.Minecraft.getMinecraft;
@Mod(modid = ReplayModOnline.MOD_ID,
version = "@MOD_VERSION@",
acceptedMinecraftVersions = "@MC_VERSION@",
useMetadata = true)
public class ReplayModOnline {
public static final String MOD_ID = "replaymod-online";
@Mod.Instance(MOD_ID)
public static ReplayModOnline instance;
private ReplayMod core;
private ReplayModReplay replayModule;
private Logger logger;
private ApiClient apiClient;
/**
* In case the currently opened replay gets modified, the resulting replay file is saved to this location.
* Usually a file within the normal replays folder with a unique name.
* When the replay is closed, the user is asked whether they want to give it a proper name.
*/
private File currentReplayOutputFile;
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
logger = event.getModLog();
core = ReplayMod.instance;
replayModule = ReplayModReplay.instance;
core.getSettingsRegistry().register(Setting.class);
Configuration config = new Configuration(event.getSuggestedConfigurationFile());
ConfigurationAuthData authData = new ConfigurationAuthData(config);
apiClient = new ApiClient(authData);
authData.load(apiClient);
}
@Mod.EventHandler
public void init(FMLInitializationEvent event) {
if (!getDownloadsFolder().exists()){
if (!getDownloadsFolder().mkdirs()) {
logger.warn("Failed to create downloads folder: " + getDownloadsFolder());
}
}
new GuiHandler(this).register();
MinecraftForge.EVENT_BUS.register(this);
}
@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event) {
// Initial login prompt
if (!core.getSettingsRegistry().get(Setting.SKIP_LOGIN_PROMPT)) {
if (!isLoggedIn()) {
core.runLater(() -> new GuiLoginPrompt(apiClient, GuiScreen.wrap(getMinecraft().currentScreen), null, false).display());
}
}
}
public ReplayMod getCore() {
return core;
}
public ReplayModReplay getReplayModule() {
return replayModule;
}
public Logger getLogger() {
return logger;
}
public ApiClient getApiClient() {
return apiClient;
}
public boolean isLoggedIn() {
return apiClient.isLoggedIn();
}
public File getDownloadsFolder() {
String path = core.getSettingsRegistry().get(Setting.DOWNLOAD_PATH);
return new File(path.startsWith("./") ? getMinecraft().mcDataDir : null, path);
}
public File getDownloadedFile(int id) {
return new File(getDownloadsFolder(), id + ".mcpr");
}
public boolean hasDownloaded(int id) {
return getDownloadedFile(id).exists();
}
public void startReplay(int id, String name, GuiScreen onDownloadCancelled) throws IOException {
File file = getDownloadedFile(id);
if (file.exists()) {
currentReplayOutputFile = new File(core.getReplayFolder(), System.currentTimeMillis() + ".mcpr");
ReplayFile replayFile = new ZipReplayFile(new ReplayStudio(), file, currentReplayOutputFile);
replayModule.startReplay(replayFile);
} else {
new GuiReplayDownloading(onDownloadCancelled, this, id, name).display();
}
}
@SubscribeEvent
public void onReplayClosed(ReplayCloseEvent.Post event) {
if (currentReplayOutputFile != null) {
if (currentReplayOutputFile.exists()) { // Replay was modified, ask user for new name
new GuiSaveModifiedReplay(currentReplayOutputFile).display();
}
currentReplayOutputFile = null;
}
}
}