static void EnvHandler( Player player, Command cmd ) {
if( !ConfigKey.WoMEnableEnvExtensions.Enabled() ) {
player.Message( "Env command is disabled on this server." );
return;
}
string worldName = cmd.Next();
World world;
if( worldName == null ) {
world = player.World;
if( world == null ) {
player.Message( "When used from console, /Env requires a world name." );
return;
}
} else {
world = WorldManager.FindWorldOrPrintMatches( player, worldName );
if( world == null ) return;
}
string variable = cmd.Next();
string valueText = cmd.Next();
if( variable == null ) {
player.Message( "Environment settings for world {0}&S:", world.ClassyName );
player.Message( " Cloud: {0} Fog: {1} Sky: {2}",
world.CloudColor == -1 ? "normal" : '#' + world.CloudColor.ToString( "X6" ),
world.FogColor == -1 ? "normal" : '#' + world.FogColor.ToString( "X6" ),
world.SkyColor == -1 ? "normal" : '#' + world.SkyColor.ToString( "X6" ) );
player.Message( " Edge level: {0} Edge texture: {1}",
world.EdgeLevel == -1 ? "normal" : world.EdgeLevel + " blocks",
world.EdgeBlock );
if( !player.IsUsingWoM ) {
player.Message( " You need WoM client to see the changes." );
}
return;
}
if( variable.Equals( "normal", StringComparison.OrdinalIgnoreCase ) ) {
if( cmd.IsConfirmed ) {
world.FogColor = -1;
world.CloudColor = -1;
world.SkyColor = -1;
world.EdgeLevel = -1;
world.EdgeBlock = Block.Water;
player.Message( "Reset enviroment settings for world {0}", world.ClassyName );
WorldManager.SaveWorldList();
} else {
player.Confirm( cmd, "Reset enviroment settings for world {0}&S?", world.ClassyName );
}
return;
}
if( valueText == null ) {
CdEnv.PrintUsage( player );
return;
}
int value = 0;
if( valueText.Equals( "normal", StringComparison.OrdinalIgnoreCase ) ) {
value = -1;
}
switch( variable.ToLower() ) {
case "fog":
if( value == -1 ) {
player.Message( "Reset fog color for {0}&S to normal", world.ClassyName );
} else {
try {
value = ParseHexColor( valueText );
} catch( FormatException ) {
CdEnv.PrintUsage( player );
return;
}
player.Message( "Set fog color for {0}&S to #{1:X6}", world.ClassyName, value );
}
world.FogColor = value;
break;
case "cloud":
case "clouds":
if( value == -1 ) {
player.Message( "Reset cloud color for {0}&S to normal", world.ClassyName );
} else {
try {
value = ParseHexColor( valueText );
} catch( FormatException ) {
CdEnv.PrintUsage( player );
return;
}
player.Message( "Set cloud color for {0}&S to #{1:X6}", world.ClassyName, value );
}
world.CloudColor = value;
break;
case "sky":
if( value == -1 ) {
player.Message( "Reset sky color for {0}&S to normal", world.ClassyName );
} else {
try {
value = ParseHexColor( valueText );
} catch( FormatException ) {
CdEnv.PrintUsage( player );
return;
}
player.Message( "Set sky color for {0}&S to #{1:X6}", world.ClassyName, value );
}
world.SkyColor = value;
break;
case "level":
if( value == -1 ) {
player.Message( "Reset edge level for {0}&S to normal", world.ClassyName );
} else {
try {
value = UInt16.Parse( valueText );
} catch( OverflowException ) {
CdEnv.PrintUsage( player );
return;
} catch( FormatException ) {
CdEnv.PrintUsage( player );
return;
}
player.Message( "Set edge level for {0}&S to {1}", world.ClassyName, value );
}
world.EdgeLevel = value;
break;
case "edge":
Block block = Map.GetBlockByName( valueText );
if( block == Block.Undefined ) {
CdEnv.PrintUsage( player );
return;
}
if( block == Block.Water || valueText.Equals( "normal", StringComparison.OrdinalIgnoreCase ) ) {
player.Message( "Reset edge block for {0}&S to normal (water)", world.ClassyName );
world.EdgeBlock = Block.Water;
} else {
string textName = Map.GetEdgeTexture( block );
if( textName == null ) {
player.Message( "Cannot use {0} for edge textures.", block );
return;
} else {
world.EdgeBlock = block;
}
}
break;
default:
CdEnv.PrintUsage( player );
return;
}
WorldManager.SaveWorldList();
if( player.World == world ) {
if( player.IsUsingWoM ) {
player.Message( "Rejoin the world to see the changes." );
} else {
player.Message( "You need WoM client to see the changes." );
}
}
}