Refactored and reformatted code to use less static variables

This commit is contained in:
CrushedPixel
2015-04-23 14:09:54 +02:00
parent f22416be2c
commit 0003f040ed
109 changed files with 9037 additions and 10229 deletions

View File

@@ -1,17 +1,18 @@
package eu.crushedpixel.replaymod;
import java.io.File;
import java.io.IOException;
import javax.swing.JOptionPane;
import eu.crushedpixel.replaymod.api.client.ApiClient;
import eu.crushedpixel.replaymod.chat.ChatMessageHandler;
import eu.crushedpixel.replaymod.events.*;
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
import eu.crushedpixel.replaymod.registry.FileCopyHandler;
import org.apache.commons.io.FilenameUtils;
import eu.crushedpixel.replaymod.registry.KeybindRegistry;
import eu.crushedpixel.replaymod.renderer.SafeEntityRenderer;
import eu.crushedpixel.replaymod.replay.ReplaySender;
import eu.crushedpixel.replaymod.settings.ReplaySettings;
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
import net.minecraft.client.Minecraft;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
@@ -19,114 +20,95 @@ import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import eu.crushedpixel.replaymod.api.client.ApiClient;
import eu.crushedpixel.replaymod.api.client.ApiException;
import eu.crushedpixel.replaymod.events.GuiEventHandler;
import eu.crushedpixel.replaymod.events.GuiReplayOverlay;
import eu.crushedpixel.replaymod.events.KeyInputHandler;
import eu.crushedpixel.replaymod.events.RecordingHandler;
import eu.crushedpixel.replaymod.events.TickAndRenderListener;
import eu.crushedpixel.replaymod.gui.GuiReplaySaving;
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
import eu.crushedpixel.replaymod.registry.KeybindRegistry;
import eu.crushedpixel.replaymod.registry.LightingHandler;
import eu.crushedpixel.replaymod.renderer.SafeEntityRenderer;
import eu.crushedpixel.replaymod.settings.ReplaySettings;
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
import org.apache.commons.io.FilenameUtils;
import java.io.File;
@Mod(modid = ReplayMod.MODID, version = ReplayMod.VERSION)
public class ReplayMod
{
public class ReplayMod {
//TODO: Set ReplayHandler replaying to false when replay is exited
//TODO: Hide Titles upon hurrying
//TODO: Override Enchantment Rendering for items when replaying (to adjust speed of animation)
//TODO: Set ReplayHandler replaying to false when replay is exited
//TODO: Hide Titles upon hurrying
//TODO: Override Enchantment Rendering for items when replaying (to adjust speed of animation)
//TODO: Show the player whether he has already uploaded a replay
//TODO: Show the player whether he has already uploaded a replay
//TODO: Hinting to the b/v key feature
//TODO: Hinting to the b/v key feature
//XXX
//Known Bugs
//
//Keyframes have problems with Linear Paths
//Rain isn't working
//Incompatible with Shaders Mod
//
//
//XXX
//Known Bugs
//
//Keyframes have problems with Linear Paths
//Rain isn't working
//Incompatible with Shaders Mod
//
//
public static final String MODID = "replaymod";
public static final String VERSION = "0.0.1";
public static final String MODID = "replaymod";
public static final String VERSION = "0.0.1";
public static final ApiClient apiClient = new ApiClient();
private static final Minecraft mc = Minecraft.getMinecraft();
public static GuiReplayOverlay overlay = new GuiReplayOverlay();
public static ReplaySettings replaySettings;
public static Configuration config;
public static boolean firstMainMenu = true;
public static RecordingHandler recordingHandler;
public static ChatMessageHandler chatMessageHandler = new ChatMessageHandler();
public static ReplaySender replaySender;
public static int TP_DISTANCE_LIMIT = 128;
public static FileCopyHandler fileCopyHandler;
private static final Minecraft mc = Minecraft.getMinecraft();
// The instance of your mod that Forge uses.
@Instance(value = "ReplayModID")
public static ReplayMod instance;
public static GuiReplayOverlay overlay = new GuiReplayOverlay();
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
config = new Configuration(event.getSuggestedConfigurationFile());
config.load();
public static ReplaySettings replaySettings;
public static Configuration config;
replaySettings = new ReplaySettings();
replaySettings.readValues();
public static boolean firstMainMenu = true;
fileCopyHandler = new FileCopyHandler();
fileCopyHandler.start();
}
public static RecordingHandler recordingHandler;
@EventHandler
public void init(FMLInitializationEvent event) {
FMLCommonHandler.instance().bus().register(new ConnectionEventHandler());
MinecraftForge.EVENT_BUS.register(new GuiEventHandler());
public static int TP_DISTANCE_LIMIT = 128;
FMLCommonHandler.instance().bus().register(new KeyInputHandler());
public static final ApiClient apiClient = new ApiClient();
recordingHandler = new RecordingHandler();
FMLCommonHandler.instance().bus().register(recordingHandler);
MinecraftForge.EVENT_BUS.register(recordingHandler);
}
public static FileCopyHandler fileCopyHandler;
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
overlay = new GuiReplayOverlay();
FMLCommonHandler.instance().bus().register(overlay);
MinecraftForge.EVENT_BUS.register(overlay);
// The instance of your mod that Forge uses.
@Instance(value = "ReplayModID")
public static ReplayMod instance;
TickAndRenderListener tarl = new TickAndRenderListener();
FMLCommonHandler.instance().bus().register(tarl);
MinecraftForge.EVENT_BUS.register(tarl);
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
config = new Configuration(event.getSuggestedConfigurationFile());
config.load();
KeybindRegistry.initialize();
replaySettings = new ReplaySettings();
replaySettings.readValues();
try {
mc.entityRenderer = new SafeEntityRenderer(mc, mc.entityRenderer);
} catch(Exception e) {
e.printStackTrace();
}
fileCopyHandler = new FileCopyHandler();
fileCopyHandler.start();
}
//clean up replay_recordings folder
removeTmcprFiles();
@EventHandler
public void init(FMLInitializationEvent event) {
FMLCommonHandler.instance().bus().register(new ConnectionEventHandler());
MinecraftForge.EVENT_BUS.register(new GuiEventHandler());
FMLCommonHandler.instance().bus().register(new KeyInputHandler());
recordingHandler = new RecordingHandler();
FMLCommonHandler.instance().bus().register(recordingHandler);
MinecraftForge.EVENT_BUS.register(recordingHandler);
}
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
overlay = new GuiReplayOverlay();
FMLCommonHandler.instance().bus().register(overlay);
MinecraftForge.EVENT_BUS.register(overlay);
TickAndRenderListener tarl = new TickAndRenderListener();
FMLCommonHandler.instance().bus().register(tarl);
MinecraftForge.EVENT_BUS.register(tarl);
KeybindRegistry.initialize();
try {
mc.entityRenderer = new SafeEntityRenderer(mc, mc.entityRenderer);
} catch(Exception e) {
e.printStackTrace();
}
//clean up replay_recordings folder
removeTmcprFiles();
boolean auth = false;
/*
boolean auth = false;
try {
auth = AuthenticationHandler.hasDonated(Minecraft.getMinecraft().getSession().getPlayerID());
} catch(Exception e) {
@@ -138,16 +120,16 @@ public class ReplayMod
JOptionPane.showMessageDialog(null, "It seems like you didn't donate, so you can't use the Replay Mod yet.");
FMLCommonHandler.instance().exitJava(0, false);
}
*/
}
}
private void removeTmcprFiles() {
File folder = ReplayFileIO.getReplayFolder();
private void removeTmcprFiles() {
File folder = ReplayFileIO.getReplayFolder();
for(File f : folder.listFiles()) {
if(("."+FilenameUtils.getExtension(f.getAbsolutePath())).equals(ConnectionEventHandler.TEMP_FILE_EXTENSION)) {
f.delete();
}
}
}
for(File f : folder.listFiles()) {
if(("." + FilenameUtils.getExtension(f.getAbsolutePath())).equals(ConnectionEventHandler.TEMP_FILE_EXTENSION)) {
f.delete();
}
}
}
}