package com.skcraft.plume.module;

import com.sk89q.intake.Command;
import com.sk89q.intake.Require;
import com.skcraft.plume.command.Sender;
import com.skcraft.plume.common.util.SharedLocale;
import com.skcraft.plume.common.util.module.Module;
import com.skcraft.plume.util.PlayerData;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;
import lombok.extern.java.Log;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.world.WorldSettings;
import net.minecraftforge.common.DimensionManager;

import java.io.IOException;

@Module(name = "mod-mode")
@Log
public class ModMode {

    @Command(aliases = "mod", desc = "Enable moderator mode")
    @Require("plume.moderator.mod")
    public void enableModMode(@Sender ICommandSender sender) {
        if(sender instanceof EntityPlayerMP) {
            EntityPlayerMP player = (EntityPlayerMP) sender;
            PlayerData backupData = new PlayerData(DimensionManager.getCurrentSaveRootDirectory().getPath() + "/plume/temp/" + player.getGameProfile().getId().toString() + ".dat");
            PlayerData modInv = new PlayerData(DimensionManager.getCurrentSaveRootDirectory().getPath() + "/plume/modinv/" + player.getGameProfile().getId().toString() + ".dat");
            if(!backupData.getFile().exists()) {
                try {
                    backupData.load(player);
                    backupData.save();
                    modInv.load();
                    modInv.putInventory(player);
                    MinecraftServer.getServer().getConfigurationManager().func_152605_a(player.getGameProfile());
                    player.setGameType(WorldSettings.GameType.CREATIVE);
                    player.addChatMessage(new ChatComponentText(SharedLocale.tr("modmode.enter")));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else {
                player.addChatMessage(new ChatComponentText(SharedLocale.tr("modmode.alreadyEnabled")));
            }
        }
    }

    @Command(aliases = "done", desc = "Disable moderator mode")
    @Require("plume.moderator.done")
    public void disableModMode(@Sender ICommandSender sender) {
        if(sender instanceof EntityPlayerMP) {
            EntityPlayerMP player = (EntityPlayerMP) sender;
            PlayerData backupData = new PlayerData(DimensionManager.getCurrentSaveRootDirectory().getPath() + "/plume/temp/" + player.getGameProfile().getId().toString() + ".dat");
            PlayerData modInv = new PlayerData(DimensionManager.getCurrentSaveRootDirectory().getPath() + "/plume/modinv/" + player.getGameProfile().getId().toString() + ".dat");
            if(backupData.getFile().exists()) {
                try {
                    modInv.load(player);
                    modInv.save();
                    backupData.load();
                    backupData.putAll(player);
                    backupData.getFile().delete();
                    MinecraftServer.getServer().getConfigurationManager().func_152610_b(player.getGameProfile());
                    player.fallDistance = 0;
                    player.setGameType(WorldSettings.GameType.SURVIVAL);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else {
                player.addChatMessage(new ChatComponentText(SharedLocale.tr("modmode.alreadyDisabled")));
            }
        }
    }

    @SubscribeEvent
    public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) {
        PlayerData backupData = new PlayerData(DimensionManager.getCurrentSaveRootDirectory().getPath() + "/plume/temp/" + event.player.getGameProfile().getId().toString() + ".dat");
        if(backupData.getFile().exists() && event.player instanceof EntityPlayerMP) {
            try {
                PlayerData modInv = new PlayerData(DimensionManager.getCurrentSaveRootDirectory().getPath() + "/plume/modinv/" + event.player.getGameProfile().getId().toString() + ".dat");
                modInv.load((EntityPlayerMP) event.player);
                modInv.save();
                backupData.load();
                backupData.putAll((EntityPlayerMP) event.player);
                backupData.getFile().delete();
                MinecraftServer.getServer().getConfigurationManager().func_152610_b(event.player.getGameProfile());
                event.player.setGameType(WorldSettings.GameType.SURVIVAL);
            } catch(IOException e) {
                e.printStackTrace();
            }
        }
    }
}

@@ -139,59 +139,8 @@
 er;%0A
-import com.skcraft.plume.common.util.SharedLocale;%0A
 impo
@@ -673,16 +673,110 @@
 ception;
+%0Aimport java.util.logging.Level;%0A%0Aimport static com.skcraft.plume.common.util.SharedLocale.tr;
 %0A%0A@Modul
@@ -988,32 +988,33 @@
 er) %7B%0A        if
+ 
 (sender instance
@@ -1469,16 +1469,17 @@
       if
+ 
 (!backup
@@ -1942,37 +1942,24 @@
 mponentText(
-SharedLocale.
 tr(%22modmode.
@@ -2031,34 +2031,160 @@
         
-e.printStackTrace(
+player.addChatMessage(new ChatComponentText(tr(%22messages.exception%22)));%0A                    log.log(Level.WARNING, %22Failed to enter mod mode%22, e
 );%0A     
@@ -2273,37 +2273,24 @@
 mponentText(
-SharedLocale.
 tr(%22modmode.
@@ -2515,16 +2515,17 @@
       if
+ 
 (sender 
@@ -2980,32 +2980,33 @@
 ;%0A            if
+ 
 (backupData.getF
@@ -3552,34 +3552,160 @@
         
-e.printStackTrace(
+player.addChatMessage(new ChatComponentText(tr(%22messages.exception%22)));%0A                    log.log(Level.WARNING, %22Failed to leave mod mode%22, e
 );%0A     
@@ -3798,29 +3798,16 @@
 entText(
-SharedLocale.
 tr(%22modm
@@ -4146,16 +4146,17 @@
       if
+ 
 (backupD
@@ -4879,16 +4879,17 @@
  %7D catch
+ 
 (IOExcep
@@ -4918,26 +4918,68 @@
     
-e.printStackTrace(
+log.log(Level.WARNING, %22Failed to leave mod mode on join%22, e
 );%0A 

Reformat moderator mode module and log errors.