package monoxide.forgebackup;

import java.util.Iterator;
import java.util.logging.Level;

import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.ServerCommandManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntityCommandBlock;
import cpw.mods.fml.common.registry.LanguageRegistry;

public abstract class CommandBackupBase extends CommandBase {
	protected final MinecraftServer server;
	
	public CommandBackupBase(MinecraftServer server) {
		this.server = MinecraftServer.getServer();
		((ServerCommandManager) this.server.getCommandManager()).registerCommand(this);
	}
	
	@Override
	public int getRequiredPermissionLevel() {
		return !ForgeBackup.instance().config().onlyOperatorsCanManuallyBackup() ? 0 : 
		       (ForgeBackup.instance().config().canCommandBlocksUseCommands() ? 3 : 2);
	}
	
	public void notifyBackupAdmins(ICommandSender sender, String translationKey, Object... parameters) {
		notifyBackupAdmins(sender, Level.INFO, translationKey, parameters);
	}
	
	public void notifyBackupAdmins(ICommandSender sender, Level level, String translationKey, Object... parameters) {
		boolean var5 = true;
		String message = String.format(LanguageRegistry.instance().getStringLocalization(translationKey), parameters);
		
		if (sender instanceof TileEntityCommandBlock && !server.worldServers[0].getGameRules().getGameRuleBooleanValue("commandBlockOutput"))
		{
			var5 = false;
		}
		
		if (var5)
		{
			Iterator var6 = server.getConfigurationManager().playerEntityList.iterator();
			
			while (var6.hasNext())
			{
				EntityPlayerMP var7 = (EntityPlayerMP)var6.next();
				
				if (server.getConfigurationManager().areCommandsAllowed(var7.username) && 
				    (ForgeBackup.instance().config().verboseLogging() || level != Level.FINE))
				{
					var7.sendChatToPlayer("\u00a77\u00a7o[" + sender.getCommandSenderName() + ": " + message + "]");
				}
			}
		}
		
		if (sender != server)
		{
			if (ForgeBackup.instance().config().verboseLogging() && level == Level.FINE) {
				BackupLog.log(Level.INFO, message);
			} else {
				BackupLog.log(level, message);
			}
		}
		if (sender instanceof EntityPlayer && !server.isDedicatedServer()) {
			if (ForgeBackup.instance().config().verboseLogging() || level != Level.FINE) {
				((EntityPlayer)sender).sendChatToPlayer("\u00a77\u00a7o[" + sender.getCommandSenderName() + ": " + message + "]");
			}
		}
	}
}

@@ -2044,45 +2044,14 @@
 a7o%5B
-%22 + sender.getCommandSenderName() + %22
+Backup
 : %22 
@@ -2254,24 +2254,24 @@
 %09%09%7D else %7B%0D%0A
+
 %09%09%09%09BackupLo
@@ -2309,294 +2309,8 @@
 %09%7D%0D%0A
-%09%09if (sender instanceof EntityPlayer && !server.isDedicatedServer()) %7B%0D%0A%09%09%09if (ForgeBackup.instance().config().verboseLogging() %7C%7C level != Level.FINE) %7B%0D%0A%09%09%09%09((EntityPlayer)sender).sendChatToPlayer(%22%5Cu00a77%5Cu00a7o%5B%22 + sender.getCommandSenderName() + %22: %22 + message + %22%5D%22);%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A
 %09%7D%0D%0A

Fix up some issues with chat notifications in SSP.